Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Add hex input to shape Fill and Stroke popovers

EuanTopd7828bda6f25
diff --git a/crates/ui-egui/src/vector_paint_tests.rs b/crates/ui-egui/src/vector_paint_tests.rs
index c62277fb1..f5c7f23cd 100644
--- a/crates/ui-egui/src/vector_paint_tests.rs
+++ b/crates/ui-egui/src/vector_paint_tests.rs
@@ -94,6 +94,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);
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index 01bb3c133..572a3f3db 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -1431,6 +1431,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]]);
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 6edff953d..3e111a4ec 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (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) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-16 · **Change:** minor (shape Fill/Stroke popovers accept hex RGB values, #6176; 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) · **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,
@@ -126,6 +126,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| Path operations in the options bar (combine, subtract, intersect, exclude) | partial | `layer.combineShapes.*`; Pen options #1397 |
| On-canvas corner-radius handles on live shapes | done: every selected live rectangle shows a widget at each arc centre with Path Selection, the Rectangle tool and Move with Show Transform Controls; a drag rounds every corner of every selected rectangle to the same radius, ⌥ that corner on each, 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) |
@@ -227,6 +228,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-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 |
| 2026-10-13 | minor | Stale "missing tool" rows corrected against main: Color Replacement (`paint.colorReplacement`), Red Eye (`paint.redEye`) and Add/Delete Anchor Point (the P flyout cycle) are live toolbar tools, so only Art History Brush is missing; no percentage or estimate changed |