Skip to content

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

Integration: keep a strokeless shape strokeless on a 0 px width step (#6472)

David Mann962539607d42
diff --git a/crates/ui-egui/src/vector_paint_tests.rs b/crates/ui-egui/src/vector_paint_tests.rs
index 321a106cb..f050b9fac 100644
--- a/crates/ui-egui/src/vector_paint_tests.rs
+++ b/crates/ui-egui/src/vector_paint_tests.rs
@@ -411,3 +411,25 @@ fn options_bar_fill_swatch_recolours_the_shape_just_drawn() {
h.state_mut().run("edit.undo", json!({})).unwrap();
assert_eq!(shape(h.state()).fill, original.fill);
}
+
+/// An arrow-key step at 0 px on a strokeless shape must not add an invisible stroke.
+#[test]
+fn arrow_down_at_zero_width_keeps_a_strokeless_shape_strokeless() {
+ for properties in [true, false] {
+ let mut app = app("rgb", 8);
+ app.run("shape.create", json!({"rect": [20, 20, 80, 60], "fill": "#336699", "stroke": null})).unwrap();
+ assert!(shape(&app).stroke.is_none());
+ let history = app.session.active().unwrap().history.past_len();
+ let mut h = harness(app, properties);
+ h.get_all_by_role(egui::accesskit::Role::SpinButton).next().expect("the stroke width").click();
+ h.run();
+ h.key_press(Key::ArrowDown);
+ h.run_steps(3);
+ assert!(shape(h.state()).stroke.is_none(), "Properties={properties}: Down at 0 px added a stroke");
+ assert_eq!(h.state().session.active().unwrap().history.past_len(), history, "Properties={properties}: no history step");
+ // The field has the keys: Up still enables a 1 px stroke.
+ h.key_press(Key::ArrowUp);
+ h.run_steps(3);
+ assert_eq!(shape(h.state()).stroke.as_ref().map(|s| s.width), Some(1.0), "Properties={properties}");
+ }
+}
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index 1375f63b1..3aee5cf8f 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -1199,11 +1199,14 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
let stroke_color = swatch(ui, stroke.as_ref().map(|s| &s.paint), bg, tl!("Stroke color"));
if crate::widgets::value_field(ui, &mut width, 0.0..=288.0, "px", 58.0).changed() {
o.stroke_width = width;
- let mut p = json!({"width": width});
- if stroke.is_none() {
- p["color"] = json!(bg);
+ // A 0 px "change" (an arrow step clamped at the minimum) must not add a stroke.
+ if stroke.is_some() || width > 0.0 {
+ let mut p = json!({"width": width});
+ if stroke.is_none() {
+ p["color"] = json!(bg);
+ }
+ edit = Some(json!({"stroke": p, "coalesce": key("stroke-w")}));
}
- edit = Some(json!({"stroke": p, "coalesce": key("stroke-w")}));
}
let preview = target.as_ref().filter(|s| s.stroke.is_some()).map(|s| (s.doc, s.layer));
if let Some(change) =
@@ -1529,7 +1532,7 @@ pub fn shape_properties(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: photocra
edit = Some(json!({"stroke": stroke, "coalesce": coalesce("stroke")}));
}
let mut w = sh.stroke.as_ref().map_or(0.0, |s| s.width);
- if crate::widgets::value_field(ui, &mut w, 0.0..=288.0, "px", 60.0).changed() {
+ if crate::widgets::value_field(ui, &mut w, 0.0..=288.0, "px", 60.0).changed() && (sh.stroke.is_some() || w > 0.0) {
edit = Some(json!({"stroke": {"width": w}, "coalesce": coalesce("stroke-w")}));
}
});