From 9dab50358fccfd798fdf145e66b9984019c4832f Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Fri, 13 Nov 2026 12:03:46 +0530 Subject: [PATCH 1/5] Object Selection: gear menu with Object Subtract and Object Finder Mode, and a Refresh button (#12857) The options bar loses the Object Finder checkbox and the rectangle hint and gains a Refresh button and a gear menu: Object Finder, Object Subtract (stored only) and Object Finder Mode (Auto Refresh, the default, or Manual Refresh). Reset Tool restores all three. With Manual Refresh the finder keeps the pixels it analysed: selection-only changes and the pointer leaving keep the highlight, and after a pixel edit it starts no lookup until Refresh is clicked. Auto Refresh is unchanged. --- crates/ui-egui/src/state.rs | 2 +- crates/ui-egui/src/state/tool_options.rs | 16 +++ crates/ui-egui/src/tools.rs | 2 + crates/ui-egui/src/tools/object_finder.rs | 76 ++++++++++- .../src/tools/object_selection_gear_tests.rs | 118 ++++++++++++++++++ crates/ui-egui/src/tools/retouch_ui.rs | 7 +- crates/ui-egui/src/tools/tool_reset.rs | 2 +- 7 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 crates/ui-egui/src/tools/object_selection_gear_tests.rs diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 138d9954691..ebe12297538 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -18,7 +18,7 @@ pub use panel_state::{ PointCurveDrag, PointCurveState, }; pub use tool::Tool; -pub use tool_options::{SampleAllLayers, ToolOptions}; +pub use tool_options::{ObjectFinderMode, SampleAllLayers, ToolOptions}; use tool_options::{default_brush_tool, default_layer_filter_mode, layer_filter_mode_or_normal, yes}; pub use transform::{ BoxResize, CamTransform, ContentAwareOptions, Extras, MadeLayer, TextEdit, TransformMode, TransformSession, TypeInsertionStyle, TypeTransform, diff --git a/crates/ui-egui/src/state/tool_options.rs b/crates/ui-egui/src/state/tool_options.rs index ea741e4b97c..77d0ca31d7f 100644 --- a/crates/ui-egui/src/state/tool_options.rs +++ b/crates/ui-egui/src/state/tool_options.rs @@ -1,6 +1,16 @@ use super::tool::Tool; use super::{Deserialize, Serialize}; +/// Object Selection › gear › Object Finder Mode (#12857). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +pub enum ObjectFinderMode { + /// Auto Refresh: the finder re-analyses the document after every edit. + #[default] + Auto, + /// Manual Refresh: the finder re-analyses only when Refresh is clicked. + Manual, +} + /// Options-bar state for tools (Photoshop keeps these per tool). #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(default)] @@ -13,6 +23,10 @@ pub struct ToolOptions { pub sample_all: SampleAllLayers, /// Object Selection › Object Finder: hovering highlights the object a click selects (#4087). pub object_finder: bool, + /// Object Selection › gear › Object Subtract; stored only, today's subtract behaviour is unchanged (#12857). + pub object_subtract: bool, + /// Object Selection › gear › Object Finder Mode: when the finder re-analyses (#12857). + pub object_finder_mode: ObjectFinderMode, /// Remove tool: the fill goes to a new layer above the target (Photoshop's Create a new layer). pub remove_new_layer: bool, /// Remove tool: each stroke is filled when released (Photoshop's default). Off, the strokes @@ -464,6 +478,8 @@ impl Default for ToolOptions { anti_alias: true, sample_all: SampleAllLayers::default(), object_finder: true, + object_subtract: true, + object_finder_mode: ObjectFinderMode::Auto, remove_new_layer: false, remove_after_each_stroke: true, feather: 0.0, diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index 721057faacd..27d2054ed0b 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -63,6 +63,8 @@ pub mod zoom_tool; #[cfg(test)] mod gradient_mode_greyed_tests; +#[cfg(test)] +mod object_selection_gear_tests; #[cfg(test)] mod object_selection_mode_tests; diff --git a/crates/ui-egui/src/tools/object_finder.rs b/crates/ui-egui/src/tools/object_finder.rs index 267c3267750..ec780193979 100644 --- a/crates/ui-egui/src/tools/object_finder.rs +++ b/crates/ui-egui/src/tools/object_finder.rs @@ -10,6 +10,12 @@ //! so an edit drops it. The preview itself is keyed by document revision, sampled layer and //! Sample All Layers, and clears when the pointer leaves the canvas, the tool changes, a button //! goes down or the option is off. Quality of the object found is out of scope here (#2788). +//! +//! The options bar has a Refresh button and a gear menu (#12857): Object Finder on/off, Object +//! Subtract (stored only) and Object Finder Mode. Auto Refresh re-analyses after every edit, as +//! above. Manual Refresh keeps the analysed pixels (`Finder::basis`) across the pointer leaving, +//! a tool switch and selection-only changes, and after a pixel edit highlights nothing until +//! Refresh is clicked ([`refresh`]). use std::sync::Arc; @@ -20,7 +26,7 @@ use photocraft_engine::smartselect_cmds::{empty_sampled_area, find_object, sampl use crate::PhotocraftApp; use crate::canvas::ViewXform; -use crate::state::Tool; +use crate::state::{ObjectFinderMode, Tool, ToolOptions}; /// Seconds the pointer must rest before an object is looked up. pub const DEBOUNCE: f64 = 0.12; @@ -48,6 +54,8 @@ pub(crate) struct Finder { misses: Vec<[i32; 2]>, shown: Option>, texture: Option<(usize, egui::TextureHandle)>, + /// The document whose pixels were last analysed (Manual Refresh compares against it). + basis: Arc, } /// What [`update`] decided. @@ -81,7 +89,7 @@ fn active(app: &PhotocraftApp, pressed: bool) -> bool { pub(crate) fn update(app: &mut PhotocraftApp, at: Option<[f64; 2]>, pressed: bool, now: f64) -> Update { let at = at.filter(|p| p[0].is_finite() && p[1].is_finite()); let (Some(at), true) = (at, active(app, pressed)) else { - app.object_finder = None; + idle(app); return Update::default(); }; let Some(st) = app.session.active() else { return Update::default() }; @@ -90,10 +98,35 @@ pub(crate) fn update(app: &mut PhotocraftApp, at: Option<[f64; 2]>, pressed: boo let (doc, revision, layer) = (st.doc.id, st.revision, st.active_layer); let px = [at[0].floor() as i32, at[1].floor() as i32]; let fresh = app.object_finder.as_ref().is_some_and(|f| f.doc == doc && f.revision == revision && f.target == target && f.all_layers == all_layers); - if !fresh { - app.object_finder = Some(Finder { doc, revision, target, all_layers, at: px, since: now, job: None, misses: Vec::new(), shown: None, texture: None }); - } let doc_arc = Arc::clone(&st.doc); + if !fresh { + let manual = app.ui.tool_options.object_finder_mode == ObjectFinderMode::Manual; + match app.object_finder.as_mut() { + // Manual Refresh: a selection-only change keeps the analysis, a pixel edit makes it stale. + Some(f) if manual && f.doc == doc => { + if f.target == target && f.all_layers == all_layers && photocraft_engine::layer_multi_cmds::same_pixels(&f.basis, &doc_arc) { + f.revision = revision; + } else { + return Update::default(); + } + } + _ => { + app.object_finder = Some(Finder { + doc, + revision, + target, + all_layers, + at: px, + since: now, + job: None, + misses: Vec::new(), + shown: None, + texture: None, + basis: Arc::clone(&doc_arc), + }); + } + } + } // The click reports an empty sampled layer; the hover says so too instead of showing nothing. let here = photocraft_geom::Rect::from_xywh(px[0], px[1], 1, 1); if doc_arc.bounds().contains(px[0], px[1]) && empty_sampled_area(&doc_arc, layer, all_layers, here).is_some() { @@ -156,11 +189,44 @@ fn spawn(doc: Arc, layer: Option, all_layers: bool, px: [i32; Job { at: px, doc, rx } } +/// Drops the preview. Auto Refresh forgets the finder; Manual Refresh keeps the analysed +/// pixels so the pointer leaving or a tool switch doesn't lose them. +fn idle(app: &mut PhotocraftApp) { + if app.ui.tool_options.object_finder_mode == ObjectFinderMode::Manual + && let Some(f) = app.object_finder.as_mut() + { + f.shown = None; + f.job = None; + f.texture = None; + f.misses.clear(); + } else { + app.object_finder = None; + } +} + /// Clears the preview (a tool switch or an edit made elsewhere is caught by [`update`] too). pub(crate) fn clear(app: &mut PhotocraftApp) { + idle(app); +} + +/// The options bar's Refresh button: the next [`update`] analyses the current pixels. +pub(crate) fn refresh(app: &mut PhotocraftApp) { app.object_finder = None; } +/// The options bar's gear button and its menu (#12857). +pub(crate) fn gear(o: &mut ToolOptions, ui: &mut egui::Ui) { + let r = crate::icons::button(ui, "settings", 24.0, false, tl!("Set additional options")); + egui::Popup::menu(&r).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + crate::widgets::checkbox(ui, &mut o.object_finder, tl!("Object Finder")); + crate::widgets::checkbox(ui, &mut o.object_subtract, tl!("Object Subtract")); + ui.separator(); + ui.label(tl!("Object Finder Mode")); + ui.radio_value(&mut o.object_finder_mode, ObjectFinderMode::Auto, tl!("Auto Refresh")); + ui.radio_value(&mut o.object_finder_mode, ObjectFinderMode::Manual, tl!("Manual Refresh")); + }); +} + /// The overlay colour: the theme accent, translucent (Photoshop tints the object it finds). fn overlay(accent: Color32, cov: f32, edge: bool) -> Color32 { let a = if edge { 0.95 } else { 0.42 * cov.clamp(0.0, 1.0) }; diff --git a/crates/ui-egui/src/tools/object_selection_gear_tests.rs b/crates/ui-egui/src/tools/object_selection_gear_tests.rs new file mode 100644 index 00000000000..0e67af2cc24 --- /dev/null +++ b/crates/ui-egui/src/tools/object_selection_gear_tests.rs @@ -0,0 +1,118 @@ +//! Object Selection's Refresh button and gear menu (#12857): Object Finder, Object Subtract and +//! Object Finder Mode are options that Reset Tool restores; Manual Refresh keeps the analysed +//! pixels until Refresh is clicked, Auto Refresh re-analyses after every edit. + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::object_finder::{Update, refresh, update}; +use crate::state::{ObjectFinderMode, Tool, ToolOptions}; + +const DISC: [f64; 2] = [100.0, 80.0]; + +/// A 200 x 160 document: a red disc (centre 100,80, radius 45) on blue, nothing selected. +fn app(mode: ObjectFinderMode) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 160})).unwrap(); + app.sync_views(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("select.rect", json!({"x": 0, "y": 0, "width": 200, "height": 160})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": "#3366cc"})).unwrap(); + app.run("select.rect", json!({"x": 55, "y": 35, "width": 90, "height": 90, "ellipse": true})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": "#e63319"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + app.ui.tool = Tool::ObjectSelection; + app.ui.tool_options.object_finder = true; + app.ui.tool_options.object_finder_mode = mode; + app +} + +/// Hovers at `at` until the lookup settles (time advances past the debounce). +fn hover(app: &mut PhotocraftApp, at: [f64; 2]) -> Update { + let mut t = 100.0; + loop { + let u = update(app, Some(at), false, t); + if !u.busy || t > 130.0 { + return u; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + t += 0.05; + } +} + +/// A pixel edit away from the disc. +fn edit_pixels(app: &mut PhotocraftApp) { + app.run("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": "#000000"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); +} + +#[test] +fn defaults_and_old_settings() { + let d = ToolOptions::default(); + assert!(d.object_finder && d.object_subtract); + assert_eq!(d.object_finder_mode, ObjectFinderMode::Auto); + let o: ToolOptions = serde_json::from_value(json!({})).unwrap(); + assert!(o.object_finder && o.object_subtract); + assert_eq!(o.object_finder_mode, ObjectFinderMode::Auto); + let mut v = serde_json::to_value(&d).unwrap(); + let m = v.as_object_mut().unwrap(); + m.remove("object_subtract"); + m.remove("object_finder_mode"); + let o: ToolOptions = serde_json::from_value(v).unwrap(); + assert_eq!(o, d); +} + +#[test] +fn options_round_trip() { + let mut o = ToolOptions::default(); + o.object_subtract = false; + o.object_finder_mode = ObjectFinderMode::Manual; + let back: ToolOptions = serde_json::from_value(serde_json::to_value(&o).unwrap()).unwrap(); + assert!(!back.object_subtract); + assert_eq!(back.object_finder_mode, ObjectFinderMode::Manual); +} + +#[test] +fn reset_tool_restores_them() { + let mut o = ToolOptions::default(); + o.object_finder = false; + o.object_subtract = false; + o.object_finder_mode = ObjectFinderMode::Manual; + crate::tools::tool_reset::reset_options(&mut o, Tool::Lasso); + assert!(!o.object_finder && !o.object_subtract && o.object_finder_mode == ObjectFinderMode::Manual); + crate::tools::tool_reset::reset_options(&mut o, Tool::ObjectSelection); + assert_eq!(o, ToolOptions::default()); +} + +#[test] +fn manual_refresh_waits_for_refresh_after_a_pixel_edit() { + let mut app = app(ObjectFinderMode::Manual); + assert!(hover(&mut app, DISC).shown.is_some()); + edit_pixels(&mut app); + let u = hover(&mut app, DISC); + assert!(u.shown.is_none() && !u.busy); + // Still nothing after the debounce: no lookup was started. + let u = update(&mut app, Some(DISC), false, 500.0); + assert!(u.shown.is_none() && !u.busy); + refresh(&mut app); + assert!(hover(&mut app, DISC).shown.is_some()); +} + +#[test] +fn manual_refresh_survives_selection_changes_and_leaving() { + let mut app = app(ObjectFinderMode::Manual); + assert!(hover(&mut app, DISC).shown.is_some()); + assert!(update(&mut app, None, false, 200.0).shown.is_none()); + app.run("select.all", json!({})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + assert!(hover(&mut app, DISC).shown.is_some()); +} + +#[test] +fn auto_refresh_reanalyses_after_a_pixel_edit() { + let mut app = app(ObjectFinderMode::Auto); + assert!(hover(&mut app, DISC).shown.is_some()); + edit_pixels(&mut app); + assert!(hover(&mut app, DISC).shown.is_some()); +} diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 233db18f850..266fb8edb3f 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -1145,10 +1145,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo Tool::ObjectSelection => { crate::panels::selection_mode_buttons(&mut app.ui.selection_mode, ui); crate::widgets::vline(ui, 22.0); - crate::widgets::checkbox(ui, &mut o.object_finder, tl!("Object Finder")); crate::widgets::checkbox(ui, &mut o.sample_all.object_selection, tl!("Sample All Layers")); - opt(ui, tl!("Drag a rectangle around the object")); + let refresh = crate::icons::button(ui, "rotate-cw", 24.0, false, tl!("Click to refresh object finder.")).clicked(); + crate::object_finder::gear(o, ui); crate::widgets::vline(ui, 22.0); + if refresh { + crate::object_finder::refresh(app); + } if crate::widgets::secondary_button(ui, tl!("Select Subject"), 0.0).clicked() { let r = app.run("select.subject", json!({})); report_smart_result(app, r, tl!("No subject found — try a rectangle around the object")); diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index 4caae361a19..e04ad6f45c2 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -211,7 +211,7 @@ pub fn option_keys(tool: Tool) -> &'static [&'static str] { Tool::MagneticLasso => reset!(feather, anti_alias, magnetic_width, magnetic_contrast, magnetic_frequency, magnetic_pressure), Tool::MagicWand => reset!(tolerance, anti_alias, contiguous), Tool::QuickSelection => reset!(enhance_edge), - Tool::ObjectSelection => reset!(enhance_edge, object_finder), + Tool::ObjectSelection => reset!(enhance_edge, object_finder, object_subtract, object_finder_mode), Tool::Crop => reset!( crop_ratio, crop_delete, From 0783289bb89b351fef9e596e70a640ea548a2a59 Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Fri, 13 Nov 2026 13:12:04 +0530 Subject: [PATCH 2/5] Object Selection gear tests: build options with struct update syntax (clippy) --- crates/ui-egui/src/tools/object_selection_gear_tests.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/tools/object_selection_gear_tests.rs b/crates/ui-egui/src/tools/object_selection_gear_tests.rs index 0e67af2cc24..6ce77c645f9 100644 --- a/crates/ui-egui/src/tools/object_selection_gear_tests.rs +++ b/crates/ui-egui/src/tools/object_selection_gear_tests.rs @@ -65,9 +65,7 @@ fn defaults_and_old_settings() { #[test] fn options_round_trip() { - let mut o = ToolOptions::default(); - o.object_subtract = false; - o.object_finder_mode = ObjectFinderMode::Manual; + let o = ToolOptions { object_subtract: false, object_finder_mode: ObjectFinderMode::Manual, ..ToolOptions::default() }; let back: ToolOptions = serde_json::from_value(serde_json::to_value(&o).unwrap()).unwrap(); assert!(!back.object_subtract); assert_eq!(back.object_finder_mode, ObjectFinderMode::Manual); @@ -75,10 +73,7 @@ fn options_round_trip() { #[test] fn reset_tool_restores_them() { - let mut o = ToolOptions::default(); - o.object_finder = false; - o.object_subtract = false; - o.object_finder_mode = ObjectFinderMode::Manual; + let mut o = ToolOptions { object_finder: false, object_subtract: false, object_finder_mode: ObjectFinderMode::Manual, ..ToolOptions::default() }; crate::tools::tool_reset::reset_options(&mut o, Tool::Lasso); assert!(!o.object_finder && !o.object_subtract && o.object_finder_mode == ObjectFinderMode::Manual); crate::tools::tool_reset::reset_options(&mut o, Tool::ObjectSelection); From 66a2916dfb175f9ef7ac19c2bed13f77fbeaf94f Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Fri, 13 Nov 2026 19:30:37 +0530 Subject: [PATCH 3/5] Object Selection: Manual Refresh analyses nothing until Refresh is clicked The first hover, or a hover on another document, no longer starts an analysis under Manual Refresh; Refresh creates the finder for the current pixels. --- crates/ui-egui/src/tools/object_finder.rs | 48 +++++++++++-------- .../src/tools/object_selection_gear_tests.rs | 40 ++++++++++++++-- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/crates/ui-egui/src/tools/object_finder.rs b/crates/ui-egui/src/tools/object_finder.rs index ec780193979..3764578a6e4 100644 --- a/crates/ui-egui/src/tools/object_finder.rs +++ b/crates/ui-egui/src/tools/object_finder.rs @@ -14,8 +14,8 @@ //! The options bar has a Refresh button and a gear menu (#12857): Object Finder on/off, Object //! Subtract (stored only) and Object Finder Mode. Auto Refresh re-analyses after every edit, as //! above. Manual Refresh keeps the analysed pixels (`Finder::basis`) across the pointer leaving, -//! a tool switch and selection-only changes, and after a pixel edit highlights nothing until -//! Refresh is clicked ([`refresh`]). +//! a tool switch and selection-only changes; it analyses nothing until Refresh is clicked +//! ([`refresh`]): not on the first hover, on another document, or after a pixel edit. use std::sync::Arc; @@ -110,21 +110,10 @@ pub(crate) fn update(app: &mut PhotocraftApp, at: Option<[f64; 2]>, pressed: boo return Update::default(); } } - _ => { - app.object_finder = Some(Finder { - doc, - revision, - target, - all_layers, - at: px, - since: now, - job: None, - misses: Vec::new(), - shown: None, - texture: None, - basis: Arc::clone(&doc_arc), - }); - } + // Manual Refresh analyses nothing until Refresh is clicked: no finder yet, or one kept + // for another document, waits for [`refresh`] (#12857). + _ if manual => return Update::default(), + _ => app.object_finder = start(app), } } // The click reports an empty sampled layer; the hover says so too instead of showing nothing. @@ -209,9 +198,30 @@ pub(crate) fn clear(app: &mut PhotocraftApp) { idle(app); } -/// The options bar's Refresh button: the next [`update`] analyses the current pixels. +/// The options bar's Refresh button: the next [`update`] analyses the current pixels. Under +/// Manual Refresh this is the only way a finder starts. pub(crate) fn refresh(app: &mut PhotocraftApp) { - app.object_finder = None; + app.object_finder = start(app); +} + +/// A new finder for the active document's current pixels, sampled layer and Sample All Layers. +/// Its pointer position is unset, so the first hover starts the debounce. +fn start(app: &PhotocraftApp) -> Option { + let st = app.session.active()?; + let all_layers = app.ui.tool_options.sample_all.object_selection; + Some(Finder { + doc: st.doc.id, + revision: st.revision, + target: sampled_target(&st.doc, st.active_layer, all_layers), + all_layers, + at: [i32::MIN, i32::MIN], + since: 0.0, + job: None, + misses: Vec::new(), + shown: None, + texture: None, + basis: Arc::clone(&st.doc), + }) } /// The options bar's gear button and its menu (#12857). diff --git a/crates/ui-egui/src/tools/object_selection_gear_tests.rs b/crates/ui-egui/src/tools/object_selection_gear_tests.rs index 6ce77c645f9..47f511da2b0 100644 --- a/crates/ui-egui/src/tools/object_selection_gear_tests.rs +++ b/crates/ui-egui/src/tools/object_selection_gear_tests.rs @@ -80,16 +80,45 @@ fn reset_tool_restores_them() { assert_eq!(o, ToolOptions::default()); } +/// Hovers long past the debounce and checks nothing was shown or started. +fn assert_idle(app: &mut PhotocraftApp) { + let u = hover(app, DISC); + assert!(u.shown.is_none() && !u.busy); + let u = update(app, Some(DISC), false, 500.0); + assert!(u.shown.is_none() && !u.busy); +} + +#[test] +fn manual_refresh_analyses_nothing_before_refresh() { + let mut app = app(ObjectFinderMode::Manual); + assert_idle(&mut app); + refresh(&mut app); + assert!(hover(&mut app, DISC).shown.is_some()); +} + +#[test] +fn manual_refresh_needs_refresh_on_another_document() { + let mut app = app(ObjectFinderMode::Manual); + refresh(&mut app); + assert!(hover(&mut app, DISC).shown.is_some()); + app.run("file.new", json!({"width": 200, "height": 160})).unwrap(); + app.sync_views(); + app.run("layer.new.layer", json!({})).unwrap(); + app.run("select.rect", json!({"x": 55, "y": 35, "width": 90, "height": 90, "ellipse": true})).unwrap(); + app.run("edit.fill", json!({"contents": "color", "color": "#e63319"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + assert_idle(&mut app); + refresh(&mut app); + assert!(hover(&mut app, DISC).shown.is_some()); +} + #[test] fn manual_refresh_waits_for_refresh_after_a_pixel_edit() { let mut app = app(ObjectFinderMode::Manual); + refresh(&mut app); assert!(hover(&mut app, DISC).shown.is_some()); edit_pixels(&mut app); - let u = hover(&mut app, DISC); - assert!(u.shown.is_none() && !u.busy); - // Still nothing after the debounce: no lookup was started. - let u = update(&mut app, Some(DISC), false, 500.0); - assert!(u.shown.is_none() && !u.busy); + assert_idle(&mut app); refresh(&mut app); assert!(hover(&mut app, DISC).shown.is_some()); } @@ -97,6 +126,7 @@ fn manual_refresh_waits_for_refresh_after_a_pixel_edit() { #[test] fn manual_refresh_survives_selection_changes_and_leaving() { let mut app = app(ObjectFinderMode::Manual); + refresh(&mut app); assert!(hover(&mut app, DISC).shown.is_some()); assert!(update(&mut app, None, false, 200.0).shown.is_none()); app.run("select.all", json!({})).unwrap(); From 91149ac8e21df5e7dcfebb0a47033b7d85655b80 Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Sun, 15 Nov 2026 21:39:30 +0530 Subject: [PATCH 4/5] Object Selection: Refresh and gear buttons in one helper, keeping options_bar under the complexity limit --- crates/ui-egui/src/tools/object_finder.rs | 11 ++++++++++- crates/ui-egui/src/tools/retouch_ui.rs | 6 +----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/tools/object_finder.rs b/crates/ui-egui/src/tools/object_finder.rs index 3764578a6e4..8adf645ce64 100644 --- a/crates/ui-egui/src/tools/object_finder.rs +++ b/crates/ui-egui/src/tools/object_finder.rs @@ -224,8 +224,17 @@ fn start(app: &PhotocraftApp) -> Option { }) } +/// The options bar's Refresh and gear buttons (#12857). +pub(crate) fn bar_buttons(app: &mut PhotocraftApp, ui: &mut egui::Ui) { + let clicked = crate::icons::button(ui, "rotate-cw", 24.0, false, tl!("Click to refresh object finder.")).clicked(); + gear(&mut app.ui.tool_options, ui); + if clicked { + refresh(app); + } +} + /// The options bar's gear button and its menu (#12857). -pub(crate) fn gear(o: &mut ToolOptions, ui: &mut egui::Ui) { +fn gear(o: &mut ToolOptions, ui: &mut egui::Ui) { let r = crate::icons::button(ui, "settings", 24.0, false, tl!("Set additional options")); egui::Popup::menu(&r).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { crate::widgets::checkbox(ui, &mut o.object_finder, tl!("Object Finder")); diff --git a/crates/ui-egui/src/tools/retouch_ui.rs b/crates/ui-egui/src/tools/retouch_ui.rs index 5bc5df8e058..7473c7b229d 100644 --- a/crates/ui-egui/src/tools/retouch_ui.rs +++ b/crates/ui-egui/src/tools/retouch_ui.rs @@ -1227,12 +1227,8 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo crate::widgets::vline(ui, 22.0); crate::widgets::checkbox(ui, &mut o.sample_all.object_selection, tl!("Sample All Layers")); crate::widgets::checkbox(ui, &mut o.object_hard_edge, tl!("Hard Edge")); - let refresh = crate::icons::button(ui, "rotate-cw", 24.0, false, tl!("Click to refresh object finder.")).clicked(); - crate::object_finder::gear(o, ui); + crate::object_finder::bar_buttons(app, ui); crate::widgets::vline(ui, 22.0); - if refresh { - crate::object_finder::refresh(app); - } if crate::widgets::secondary_button(ui, tl!("Select Subject"), 0.0).clicked() { let r = app.run("select.subject", json!({})); report_smart_result(app, r, tl!("No subject found — try a rectangle around the object")); From bdacd76af0d25c2bfd4827bd73f4c8e529fce749 Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Fri, 20 Nov 2026 12:29:57 +0530 Subject: [PATCH 5/5] Object Selection gear tests: the boxed app and the borrows of the new update signature --- crates/ui-egui/src/tools/object_selection_gear_tests.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/tools/object_selection_gear_tests.rs b/crates/ui-egui/src/tools/object_selection_gear_tests.rs index bf3d0906987..72cf230ecf7 100644 --- a/crates/ui-egui/src/tools/object_selection_gear_tests.rs +++ b/crates/ui-egui/src/tools/object_selection_gear_tests.rs @@ -11,7 +11,7 @@ use crate::state::{ObjectFinderMode, Tool, ToolOptions}; const DISC: [f64; 2] = [100.0, 80.0]; /// A 200 x 160 document: a red disc (centre 100,80, radius 45) on blue, nothing selected. -fn app(mode: ObjectFinderMode) -> PhotocraftApp { +fn app(mode: ObjectFinderMode) -> Box { let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); app.run("file.new", json!({"width": 200, "height": 160})).unwrap(); app.sync_views(); @@ -85,7 +85,8 @@ fn reset_tool_restores_them() { fn assert_idle(app: &mut PhotocraftApp) { let u = hover(app, DISC); assert!(u.shown.is_none() && !u.busy); - let u = update(app, Some(DISC), false, 500.0, &app.ctx().clone()); + let ctx = app.ctx().clone(); + let u = update(app, Some(DISC), false, 500.0, &ctx); assert!(u.shown.is_none() && !u.busy); } @@ -129,7 +130,8 @@ fn manual_refresh_survives_selection_changes_and_leaving() { let mut app = app(ObjectFinderMode::Manual); refresh(&mut app); assert!(hover(&mut app, DISC).shown.is_some()); - assert!(update(&mut app, None, false, 200.0, &app.ctx().clone()).shown.is_none()); + let ctx = app.ctx().clone(); + assert!(update(&mut app, None, false, 200.0, &ctx).shown.is_none()); app.run("select.all", json!({})).unwrap(); app.run("select.deselect", json!({})).unwrap(); assert!(hover(&mut app, DISC).shown.is_some());