Merge PR #6201: Add hex color input to shape Fill and Stroke popovers

docs/ui-parity.md: header keeps main's date and gains the PR's change entry; change-log rows for both, newest first.
This commit is contained in:
aiongg committed 2026-10-22 15:37:29 +00:00
commit c9173cc9f2
3 files changed
+112 -1

No files matched your search

+78
View File
@@ -189,6 +189,84 @@ fn fill_and_stroke_swatches_open_with_pointer_and_keyboard_without_changing_pain
}
}
#[test]
fn shape_paint_hex_input_keeps_partial_text_and_preserves_alpha() {
for label in ["Fill color", "Stroke color"] {
let mut app = app("rgb", 32);
let original = [0.123456, 0.345678, 0.567891, 0.372819];
app.run("tools.setColors", json!({"foreground": original, "background": original})).unwrap();
let mut h = harness(app, false);
h.get_by_label(label).click();
h.run_steps(3);
h.get_by_label("#").click();
h.run_steps(1);
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
h.run_steps(1);
for ch in "12AB".chars() {
h.event(Event::Text(ch.to_string()));
h.run_steps(1);
}
assert_eq!(h.get_by_label("#").value().as_deref(), Some("12AB"));
assert_eq!(h.state().session.tools.foreground, original);
assert_eq!(h.state().session.tools.background, original);
for ch in "EF".chars() {
h.event(Event::Text(ch.to_string()));
h.run_steps(1);
}
let want = [18.0 / 255.0, 171.0 / 255.0, 239.0 / 255.0, original[3]];
let tools = &h.state().session.tools;
assert_eq!(if label == "Fill color" { tools.foreground } else { tools.background }, want);
assert_eq!(if label == "Fill color" { tools.background } else { tools.foreground }, original);
// An invalid/multi-byte value leaves the selected paint untouched.
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
h.run_steps(1);
h.event(Event::Text("颜色".into()));
h.run_steps(2);
let tools = &h.state().session.tools;
assert_eq!(if label == "Fill color" { tools.foreground } else { tools.background }, want);
h.key_press(Key::Escape);
h.run_steps(2);
finish_shape(h.state_mut(), Tool::Rectangle, [20.0, 20.0], [100.0, 80.0], Modifiers::NONE);
let drawn = shape(h.state());
let paint = if label == "Fill color" { drawn.fill.as_ref().and_then(color_of) } else { drawn.stroke.as_ref().and_then(|s| color_of(&s.paint)) };
assert_eq!(paint, Some(want), "the next shape takes the typed colour");
}
}
#[test]
fn a_pasted_hex_colour_updates_the_selected_shape_and_undoes_once() {
for label in ["Fill color", "Stroke color"] {
let mut app = app("rgb", 32);
app.run("tools.setColors", json!({"foreground": [0.2, 0.3, 0.4, 0.6], "background": [0.5, 0.6, 0.7, 0.8]})).unwrap();
app.ui.tool_options.stroke_width = 3.0;
finish_shape(&mut app, Tool::Rectangle, [20.0, 20.0], [100.0, 80.0], Modifiers::NONE);
let original = shape(&app).clone();
let history = app.session.active().unwrap().history.past_len();
let mut h = harness(app, false);
h.get_by_label(label).click();
h.run_steps(3);
h.get_by_label("#").click();
h.run_steps(1);
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
h.run_steps(1);
h.event(Event::Paste("#12ABEF".into()));
h.run_steps(2);
let edited = shape(h.state());
let (paint, untouched) = if label == "Fill color" {
(edited.fill.as_ref().and_then(color_of), edited.stroke == original.stroke)
} else {
(edited.stroke.as_ref().and_then(|s| color_of(&s.paint)), edited.fill == original.fill)
};
let alpha = if label == "Fill color" { 0.6 } else { 0.8 };
let want = [18.0 / 255.0, 171.0 / 255.0, 239.0 / 255.0, alpha];
assert_eq!(paint, Some(want));
assert!(untouched, "the other paint stays unchanged");
assert_eq!(h.state().session.active().unwrap().history.past_len(), history + 1);
h.state_mut().run("edit.undo", json!({})).unwrap();
assert_eq!(shape(h.state()), &original);
}
}
#[test]
fn picking_tool_colours_enables_paint_and_reaches_the_next_shape() {
let mut app = app("rgb", 32);
+31
View File
@@ -1626,6 +1626,37 @@ fn swatch(ui: &mut egui::Ui, fill: Option<&photocraft_doc::Fill>, fallback: [f32
out = Some(PaintChange::Color(color));
}
}
ui.horizontal(|ui| {
let label = ui.label(egui::RichText::new("#").color(t.text_dim));
let id = resp.id.with("shape-paint-hex");
let selected = match out {
Some(PaintChange::Color(color)) => color,
_ => original,
};
// Keep incomplete typing across frames; deriving the field from the colour each
// frame would discard every keystroke until all six digits were present.
let mut text = ui
.data(|d| d.get_temp::<([f32; 4], String)>(id))
.filter(|(previous, _)| *previous == selected)
.map_or_else(|| hex(selected).trim_start_matches('#').to_ascii_uppercase(), |(_, text)| text);
let response = crate::widgets::text_field(ui, id, &mut text, "RRGGBB", 90.0, true).labelled_by(label.id);
if response.changed()
&& let Some(rgb) = crate::color_picker_ui::parse_hex(&text)
{
let color = [rgb[0], rgb[1], rgb[2], selected[3]];
out = Some(PaintChange::Color(color));
hsva = picker_color(color);
}
if response.has_focus() {
let color = match out {
Some(PaintChange::Color(color)) => color,
_ => selected,
};
ui.data_mut(|d| d.insert_temp(id, (color, text)));
} else {
ui.data_mut(|d| d.remove::<([f32; 4], String)>(id));
}
});
if let Some(rgb) = crate::screen_picker::button(ui, screen_id) {
out = Some(sampled(rgb));
hsva = picker_color([rgb[0], rgb[1], rgb[2], original[3]]);
+3 -1
View File
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (rounded triangle, polygon and star corners; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -128,6 +128,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| Shape Density and Feather (Properties › Masks: a shape's path is its vector mask) | done: Density and Feather sliders for a selected shape layer, one undo step per drag, through `layer.vectorMask.edit`; the fill shows beyond the path at 100 − density %, a feather is the vector mask's Gaussian (Photoshop's 10 px ramp within 1 level); fill and stroke stay editable, the stroke stays crisp; PSD mask parameters and .pcraft round trip (#5846) | TOOL-214-12 |
| On-canvas corner-radius handles on live shapes | done: every selected live rectangle, triangle, polygon and star shows a widget at each arc centre with Path Selection, the Rectangle, Triangle and Polygon tools and Move with Show Transform Controls; a drag rounds every corner of every selected shape to the same radius, ⌥ one corner of a rectangle (a triangle or polygon has one radius), with the corner radius cursor and an `R:` readout, previewed and committed as one history step (`corner_radius.rs`, `corner_radius_tests.rs`) | TOOL-214-12 |
| Shape stroke controls (dash, caps, joins, align) | done | TOOL-1053-1, [`shape-strokes.md`](shape-strokes.md) |
| Shape options-bar Fill/Stroke hex input | done | #6176; `vector_ui.rs`, `vector_paint_tests.rs`: typed and pasted hex, partial/invalid input, alpha retention, next-shape defaults and selected-shape Undo |
| Rotated shape selection hints correct | partial | #2512 |
| Curved shape bounds exact | partial | one pixel too wide (#2537) |
@@ -229,6 +230,7 @@ Paragraph; the rest open as in-app floating windows.
| Date | Change | Summary |
|---|---|---|
| 2026-10-16 | minor | Shape Fill/Stroke compact pickers accept six-digit hex RGB, including pasted values with `#`, retaining alpha and high-depth paint until an edit; typed/pasted colour and history regressions (#6176). Scores unchanged. |
| 2026-10-15 | minor | Shape Density and Feather row added as done (TOOL-214-12, #5846) |
| 2026-10-13 | minor | Menu bar from the keyboard: Alt / F10 focus, Alt+letter, underlined mnemonics (#4988) |
| 2026-10-13 | minor | Layers panel filter row: Kind is a real dropdown with Kind, Name and Mode filters, drivable by `ui.set {layerFilter}` (#5048); row added as partial |