Skip to content

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

fix(ui): keep brush settings section lock icons permanently visible (#4278) (#4300)

Korg1ch1874214f79e5
diff --git a/crates/ui-egui/src/brush_panel.rs b/crates/ui-egui/src/brush_panel.rs
index dbf73f46c..4cadb6b21 100644
--- a/crates/ui-egui/src/brush_panel.rs
+++ b/crates/ui-egui/src/brush_panel.rs
@@ -327,11 +327,9 @@ fn section_list(app: &mut PhotocraftApp, ui: &mut egui::Ui, b: &mut BrushSetting
if let Some(lock) = section_lock(b, i) {
let lr = egui::Rect::from_center_size(egui::pos2(r.right() - 11.0, r.center().y), vec2(18.0, 18.0));
let lresp = ui.interact(lr, ui.id().with(("brush-sec-lock", i)), Sense::click());
- // Like Photoshop: the lock shows only when set or hovered.
- if *lock || resp.hovered() || lresp.hovered() {
- let tint = if *lock { t.text } else { t.text_faint };
- icons::paint(ui, lr, if *lock { "lock" } else { "lock-open" }, 12.0, tint);
- }
+ // Like Photoshop: lock icons stay visible on every lockable section row.
+ let tint = if *lock { t.text } else { t.text_faint };
+ icons::paint(ui, lr, if *lock { "lock" } else { "lock-open" }, 12.0, tint);
let tip =
if *lock { tl!("Unlock: picking a preset replaces these settings") } else { tl!("Lock: keep these settings when picking another preset") };
if lresp.on_hover_text(tip).clicked() {
diff --git a/crates/ui-egui/src/brush_panel_tests.rs b/crates/ui-egui/src/brush_panel_tests.rs
index 731b13e1a..6a2338295 100644
--- a/crates/ui-egui/src/brush_panel_tests.rs
+++ b/crates/ui-egui/src/brush_panel_tests.rs
@@ -220,6 +220,61 @@ fn section_locks_round_trip_and_survive_preset_picks() {
assert_eq!(b.tip, chalk.tip);
}
+#[test]
+fn section_locks_are_always_visible_and_toggle_on_click() {
+ use egui_kittest::kittest::Queryable;
+
+ fn collect_icon_rects(shape: &egui::Shape, out: &mut Vec<egui::Rect>) {
+ match shape {
+ egui::Shape::Rect(r) if (r.rect.size() - vec2(12.0, 12.0)).length() < 0.5 => out.push(r.rect),
+ egui::Shape::Mesh(mesh) => out.push(mesh.calc_bounds()),
+ egui::Shape::Vec(shapes) => {
+ for s in shapes {
+ collect_icon_rects(s, out);
+ }
+ }
+ _ => {}
+ }
+ }
+
+ let mut h = harness(0, 0);
+ let mut icons = Vec::new();
+ for clipped in &h.output().shapes {
+ collect_icon_rects(&clipped.shape, &mut icons);
+ }
+
+ // Every lockable section (1..SECTIONS.len()) paints its lock icon even when unlocked and unhovered.
+ for (name, _) in SECTIONS.iter().skip(1) {
+ let row = h.get_by_label(name).rect();
+ let lock_center = egui::pos2(row.right() - 11.0, row.center().y);
+ assert!(icons.iter().any(|r| r.contains(lock_center)), "expected lock icon at {lock_center:?} for {name}");
+ }
+
+ // Clicking the lock toggles it on and off without changing the selected section.
+ let row = h.get_by_label("Scattering").rect();
+ let lock_pos = egui::pos2(row.right() - 11.0, row.center().y);
+ assert!(!h.state().session.tools.brush.locks.scattering);
+ assert_eq!(h.state().ui.brush_section, 0);
+
+ h.hover_at(lock_pos);
+ h.run_steps(1);
+ h.drag_at(lock_pos);
+ h.run_steps(1);
+ h.drop_at(lock_pos);
+ h.run_steps(2);
+ assert!(h.state().session.tools.brush.locks.scattering);
+ assert_eq!(h.state().ui.brush_section, 0);
+
+ h.hover_at(lock_pos);
+ h.run_steps(1);
+ h.drag_at(lock_pos);
+ h.run_steps(1);
+ h.drop_at(lock_pos);
+ h.run_steps(2);
+ assert!(!h.state().session.tools.brush.locks.scattering);
+ assert_eq!(h.state().ui.brush_section, 0);
+}
+
/// A harness that shows the options bar with `tool` in the Studio (non-pro) theme.
fn options_bar_harness(tool: crate::state::Tool) -> Harness<'static, PhotocraftApp> {
let mut app = app();