diff --git a/crates/ui-egui/src/panels/brush_panel.rs b/crates/ui-egui/src/panels/brush_panel.rs index 8d45e78de3..615610fa15 100644 --- a/crates/ui-egui/src/panels/brush_panel.rs +++ b/crates/ui-egui/src/panels/brush_panel.rs @@ -1,7 +1,7 @@ //! Window › Brush Settings (F5) and Window › Brushes: Photoshop's floating brush panel. //! -//! Brush Settings: the section list with enable boxes on the left (selecting a controls section -//! shows its options without enabling it; the last five rows only toggle), the selected section's controls on the right (see [`crate::brush_sections`]), +//! Brush Settings: the section list with enable boxes on the left (clicking a controls section +//! shows and enables it; the last five rows only toggle), the selected section's controls on the right (see [`crate::brush_sections`]), //! and a live stroke preview strip below, rendered with the real brush engine and cached on the //! settings (it re-renders only when they change). Brushes: the presets in collapsible groups with //! tip thumbnails and stroke previews, a size slider and a search field. @@ -242,7 +242,7 @@ pub(crate) fn full_uv() -> egui::Rect { egui::Rect::from_min_max(egui::Pos2::ZERO, egui::pos2(1.0, 1.0)) } -/// Selecting a controls section shows its settings without enabling it; the final five rows toggle, keeping +/// Clicking a controls section shows and enables it; the final five rows only toggle, keeping /// the current controls open. The lock on the right is a separate hit target. fn section_list(app: &mut PhotocraftApp, ui: &mut egui::Ui, b: &mut BrushSettings) { let t = Tokens::get(ui.ctx()); @@ -284,7 +284,6 @@ fn section_list(app: &mut PhotocraftApp, ui: &mut egui::Ui, b: &mut BrushSetting ui.painter().rect_filled(r, t.radius_sm, t.hover); } let mut x = r.left() + 6.0; - let mut box_clicked = false; if *has_box && let Some(flag) = section_flag(b, i) { let br = egui::Rect::from_center_size(egui::pos2(x + 6.0, r.center().y), vec2(13.0, 13.0)); // A checkbox-only row is one accessible checkbox across its whole width. A @@ -297,14 +296,15 @@ fn section_list(app: &mut PhotocraftApp, ui: &mut egui::Ui, b: &mut BrushSetting resp }); let on_lock = resp.interact_pointer_pos().is_some_and(|p| p.x > r.right() - 22.0); - // For controls sections, only the checkbox toggles the setting; a row - // click selects the settings without enabling them (#5136). - let pressed = box_resp.as_ref().is_some_and(|b| b.is_pointer_button_down_on()) || (toggle_only && resp.is_pointer_button_down_on() && !on_lock); + // A press on the row (but not its lock) presses the box too: a release there + // turns the section on, or toggles a checkbox-only row (#4476). + let pressed = box_resp.as_ref().is_some_and(|b| b.is_pointer_button_down_on()) || (resp.is_pointer_button_down_on() && !on_lock); let hovered = box_resp.as_ref().is_some_and(|b| b.hovered()) || (toggle_only && resp.hovered()); widgets::check_box(ui.painter(), br, *flag, hovered, pressed, &t); - box_clicked = box_resp.as_ref().is_some_and(|resp| resp.clicked()); - if box_clicked || (toggle_only && resp.clicked() && !on_lock) { + if box_resp.is_some_and(|resp| resp.clicked()) || (toggle_only && resp.clicked() && !on_lock) { *flag = !*flag; + } else if !toggle_only && resp.clicked() && !on_lock { + *flag = true; } x += 20.0; } else { @@ -338,7 +338,7 @@ fn section_list(app: &mut PhotocraftApp, ui: &mut egui::Ui, b: &mut BrushSetting lock_clicked = true; } } - if !toggle_only && resp.clicked() && !lock_clicked && !box_clicked { + if !toggle_only && resp.clicked() && !lock_clicked { app.ui.brush_section = i; } if i == 0 { diff --git a/crates/ui-egui/src/panels/brush_panel/tests.rs b/crates/ui-egui/src/panels/brush_panel/tests.rs index 7099ee2b1f..e0e15cb4f5 100644 --- a/crates/ui-egui/src/panels/brush_panel/tests.rs +++ b/crates/ui-egui/src/panels/brush_panel/tests.rs @@ -31,48 +31,6 @@ fn sections_with_boxes_have_flags() { assert!(b.texture.enabled); } -#[test] -fn selecting_a_controls_section_keeps_its_enabled_flag_and_brush_history() { - use egui_kittest::kittest::Queryable; - - for (section, name) in [(1, "Shape Dynamics"), (2, "Scattering"), (3, "Texture")] { - let mut h = harness(0, 0); - let before = h.state().session.tools.brush.clone(); - let journal = h.state().session.journal.len(); - - h.get_by_label(name).click(); - h.run_steps(3); - - assert_eq!(h.state().ui.brush_section, section, "{name} settings are visible"); - assert_eq!(h.state().session.tools.brush, before, "{name} remains disabled"); - assert_eq!(h.state().session.journal.len(), journal, "selecting {name} is not a brush edit"); - } -} - -#[test] -fn controls_section_checkbox_toggles_without_selecting_its_settings() { - use egui_kittest::kittest::Queryable; - - let mut h = harness(0, 0); - let row = h.get_by_label("Scattering").rect(); - let checkbox = egui::pos2(row.left() + 12.0, row.center().y); - let journal = h.state().session.journal.len(); - - for enabled in [true, false] { - h.hover_at(checkbox); - h.run_steps(1); - h.drag_at(checkbox); - h.run_steps(1); - h.drop_at(checkbox); - h.run_steps(3); - - assert_eq!(h.state().session.tools.brush.scattering.enabled, enabled); - assert_eq!(h.state().ui.brush_section, 0, "the checkbox does not select Scattering"); - assert_eq!(last_journal(h.state()).unwrap().1["brush"], json!({"scattering": {"enabled": enabled}})); - } - assert_eq!(h.state().session.journal.len(), journal + 2); -} - /// What each section's controls edit, set to non-default values. fn edit_section(i: usize, b: &mut BrushSettings) { let dynamic = |jitter: f32, control: Control, minimum: f32| paint::Dynamic { jitter, control, fade_steps: 40, minimum, ..Default::default() }; @@ -1466,20 +1424,22 @@ fn f5_edits_the_default_brush_with_every_section() { for (name, _) in SECTIONS { assert!(h.query_all_by_label(name).next().is_some(), "{name} listed"); } - // Clicking a section's name shows its settings without changing its enable flag. + // Clicking a section's name shows it and turns it on: one tools.setBrush. let n = h.state().session.journal.len(); - let shape_enabled = h.state().session.tools.brush.shape_dynamics.enabled; h.get_by_label("Shape Dynamics").click(); h.run_steps(3); assert_eq!(h.state().ui.brush_section, 1); - assert_eq!(h.state().session.tools.brush.shape_dynamics.enabled, shape_enabled); - assert_eq!(h.state().session.journal.len(), n); + assert!(h.state().session.tools.brush.shape_dynamics.enabled); + assert_eq!(h.state().session.journal.len(), n + 1); + let (id, p) = last_journal(h.state()).unwrap(); + assert_eq!(id, "tools.setBrush"); + assert_eq!(p["brush"]["shapeDynamics"]["enabled"], json!(true)); // A section's box toggles it without showing it. h.get_by_label("Enable Transfer").click(); h.run_steps(3); assert!(h.state().session.tools.brush.transfer.enabled); assert_eq!(h.state().ui.brush_section, 1); - assert_eq!(h.state().session.journal.len(), n + 1); + assert_eq!(h.state().session.journal.len(), n + 2); // The rest of the brush is untouched. let b = &h.state().session.tools.brush; assert_eq!((b.size, b.hardness, &b.tip), (fresh.size, fresh.hardness, &fresh.tip)); @@ -1847,20 +1807,12 @@ fn section_boxes_show_a_pressed_state() { let row = h.get_by_label("Shape Dynamics").rect(); assert!(!h.state().session.tools.brush.shape_dynamics.enabled); assert_eq!(box_fill(&h, boxr), Some(widgets::check_box_fill(false, false, &t))); - // Selecting the controls row leaves its checkbox untouched, including while held. + // Held on the row's name: the unchecked box darkens; the release turns the section on. let at = egui::pos2(row.center().x, row.center().y); h.drag_at(at); h.run_steps(2); - assert_eq!(box_fill(&h, boxr), Some(widgets::check_box_fill(false, false, &t)), "row press leaves checkbox untouched"); - h.drop_at(at); - h.run_steps(3); - assert!(!h.state().session.tools.brush.shape_dynamics.enabled); - assert_eq!(box_fill(&h, boxr), Some(widgets::check_box_fill(false, false, &t))); - // The checkbox itself still shows its pressed state and toggles the section. - h.drag_at(boxr.center()); - h.run_steps(2); assert_eq!(box_fill(&h, boxr), Some(widgets::check_box_fill(false, true, &t)), "pressed, unchecked"); - h.drop_at(boxr.center()); + h.drop_at(at); h.run_steps(3); assert!(h.state().session.tools.brush.shape_dynamics.enabled); assert_eq!(box_fill(&h, boxr), Some(widgets::check_box_fill(true, false, &t)));