From bd89c1147cbf9593102c28ae3c1713d91c5c53df Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 00:20:25 +0000 Subject: [PATCH 01/21] Options bar keyed by the view fields its tool shows; status bar keyed by zoom alone (FW-365 F6) --- crates/ui-egui/src/canvas/document_display.rs | 5 ++ crates/ui-egui/src/chrome_settle_trials.rs | 52 +++++++++++++++++++ crates/ui-egui/src/panels/region_versions.rs | 19 +++++-- crates/ui-egui/src/panels/status_bar.rs | 31 ++++++----- 4 files changed, 89 insertions(+), 18 deletions(-) diff --git a/crates/ui-egui/src/canvas/document_display.rs b/crates/ui-egui/src/canvas/document_display.rs index 81ee1515c3..79d88d17a7 100644 --- a/crates/ui-egui/src/canvas/document_display.rs +++ b/crates/ui-egui/src/canvas/document_display.rs @@ -35,6 +35,11 @@ impl View { .aspect(f64::from(aspect)) } + /// Takes `zoom` points per document unit, shown at `ppp` device pixels per point, and leaves the centre and rotation. + pub(crate) fn set_zoom(&mut self, zoom: f64, ppp: f32) { + self.zoom = (zoom * f64::from(ppp)) as f32; + } + /// Takes the zoom, centre and rotation of `view`, shown at `ppp` device pixels per point. pub(crate) fn set_from(&mut self, view: &CanvasView, ppp: f32) { self.zoom = (view.zoom * f64::from(ppp)) as f32; diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 83b4a8dd81..96a5f0e015 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -201,3 +201,55 @@ fn the_menu_keys_open_a_menu_after_a_dialog_closes_with_escape() { h.run_steps(4); assert!(items(&h) > titles, "Alt+F opens the File menu: {} menu items, {titles} titles", items(&h)); } + +/// The options bar and status bar views that ran over the next `steps` frames, summed. +fn ran_over(h: &mut H, steps: usize, name: &str) -> usize { + (0..steps) + .map(|_| { + h.run_steps(1); + views_ran(h, name) + }) + .sum() +} + +/// A pan with a tool whose bar shows no view field runs neither the options bar nor the status bar (it shows the zoom +/// only); a zoom runs the status bar, and the options bar only while the Zoom tool's bar shows the zoom. +#[test] +fn a_pan_runs_neither_bar_and_a_zoom_runs_the_status_bar() { + let mut h = harness(); + h.state_mut().ui.tool = crate::state::Tool::Move; + h.run_steps(4); + h.state_mut().ui.views[0].center[0] += 40.0; + assert_eq!(ran_over(&mut h, 3, "OptionsSlot<"), 0, "a pan runs no options bar"); + h.state_mut().ui.views[0].center[0] += 40.0; + assert_eq!(ran_over(&mut h, 3, "status_bar::StatusProps<"), 0, "a pan runs no status bar"); + + h.state_mut().ui.views[0].zoom *= 2.0; + let status = ran_over(&mut h, 3, "status_bar::StatusProps<"); + assert!(status > 0, "a zoom runs the status bar: {status}"); +} + +/// The Zoom tool's bar shows the zoom, so a zoom runs it. +#[test] +fn a_zoom_runs_the_zoom_tools_options_bar() { + let mut h = harness(); + h.state_mut().ui.tool = crate::state::Tool::Zoom; + h.run_steps(4); + h.state_mut().ui.views[0].zoom *= 2.0; + assert!(ran_over(&mut h, 3, "OptionsSlot<") > 0, "a zoom runs the Zoom tool's bar"); +} + +/// A tool option changed outside the bar runs the bar, and the frames after it replay it. +#[test] +fn a_tool_option_runs_the_options_bar_once() { + let mut h = harness(); + h.state_mut().ui.tool = crate::state::Tool::Move; + h.run_steps(4); + assert_eq!(ran_over(&mut h, 2, "OptionsSlot<"), 0, "settled"); + let on = h.state().ui.tool_options.move_auto_select; + h.state_mut().ui.tool_options.move_auto_select = !on; + assert!(ran_over(&mut h, 1, "OptionsSlot<") > 0, "a changed option runs the bar"); + // The frame after the run settles (a run's second pass replays what the first ran); then two idle frames run nothing. + h.run_steps(1); + assert_eq!(ran_over(&mut h, 2, "OptionsSlot<"), 0, "the bar's own run leaves the version as it was"); +} diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 31abdea38b..9a62545fad 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -14,6 +14,7 @@ use craft::ui::contract::{MemoProps, MemoView}; use super::PhotocraftApp; use crate::color_picker_ui::PickWindow; +use crate::state::Tool; /// The props of a shell slot's view: the app the slot reads, which its version stands for. One type per slot, so a /// trial and the frame's memo log tell the views apart. @@ -65,7 +66,7 @@ pub(crate) fn show_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: &str) { /// The version of the options bar: every tool option (`app.ui.tool_options`, all of which the bar shows; keys, the /// canvas menu, the canvas and its task bars, panels and presets write them without a command), the commit and cancel /// cells and hints of an edit the canvas opens or ends ([`options_bar::edit_key`](super::options_bar::edit_key)), the -/// Zoom tool's view, an open Free Transform, Puppet Warp or Perspective Warp, which shows its own members in place +/// Zoom and Rotate View tools' zoom and rotation ([`bar_view`]), an open Free Transform, Puppet Warp or Perspective Warp, which shows its own members in place /// of the tool's, with what a drag on the canvas changes (the box, the picked pin, the planes; Escape ends them without /// a command, #15547), the Crop tool's frame state, the type members' caret or selection, the brush and its presets, the /// colours, and the vector bar's "Make" row's own two ingredients: the Pen draft's anchor count and the Work Path the @@ -80,7 +81,7 @@ pub(crate) fn options_bar(app: &PhotocraftApp) -> u64 { let gesture = crate::canvas::tools::in_gesture(app); let hidden = app.session.active().map(|st| (st.doc.id.0, app.ui.hidden_work_path.as_ref().map(|(id, _)| *id))); let paths = (app.ui.pen.as_ref().map(|p| p.draft.knots.len()), hidden); - version(app, (view(app), sessions, shown, brush(app), colours(app), gesture, paths)) + version(app, (bar_view(app), sessions, shown, brush(app), colours(app), gesture, paths)) } /// The version of the toolbar's footer: the colour chips' two colours, whether the active document is in Quick Mask and @@ -148,7 +149,7 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 { /// or `prefs.edit`, not as a counted command: units, the language, toolbar slots). /// Whether running command `id` leaves every settling region's version as it is: a view command (zoom, fit, print size, /// rotate) changes only the canvas view, which every region that shows it holds in its version (the Navigator, the Info -/// panel and the options bar through [`view`], the status bar in its own props), so it need not count as a command run +/// panel and the options bar through [`view`] and [`bar_view`], the status bar in its own props), so it need not count as a command run /// and run every panel body in the next frame (#15493). While an action is recorded it counts: the Actions panel lists /// the step it records. pub(crate) fn changes_only_the_view(app: &PhotocraftApp, id: &str) -> bool { @@ -226,6 +227,17 @@ fn colours(app: &PhotocraftApp) -> [u32; 8] { bits } +/// The part of the active document's view the options bar shows: the Zoom tool's bar the zoom, the Rotate View tool's +/// the rotation, every other tool's none (the Hand tool's bar has no view field). +fn bar_view(app: &PhotocraftApp) -> Option { + let view = crate::canvas::active_view(app)?; + match app.ui.tool { + Tool::Zoom => Some(view.zoom.to_bits()), + Tool::RotateView => Some(view.rotation.to_bits()), + _ => None, + } +} + /// The active document's view as the canvas showed it: its zoom, centre and turn. fn view(app: &PhotocraftApp) -> Option<[u64; 5]> { crate::canvas::active_view(app) @@ -235,7 +247,6 @@ fn view(app: &PhotocraftApp) -> Option<[u64; 5]> { #[cfg(test)] mod tests { use super::*; - use crate::state::Tool; /// The brush, the colours, the type defaults, the tool options, the type caret, the Move tool's rollover and an /// adjustment's live preview move the versions of the bars and panels that show them and of no other, so a drag that diff --git a/crates/ui-egui/src/panels/status_bar.rs b/crates/ui-egui/src/panels/status_bar.rs index 8d912e4e52..d3eeec2f7e 100644 --- a/crates/ui-egui/src/panels/status_bar.rs +++ b/crates/ui-egui/src/panels/status_bar.rs @@ -1,5 +1,5 @@ use craft::behavior::CanvasView; -use craft::behavior::kurbo::Size; +use craft::behavior::kurbo::{Point, Size}; use craft::theme::variant::Tone; use craft::ui::bars::{Bar, BarKind, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues}; use craft::ui::contract::{Bind, MemoProps, MemoView, Outbox, ShowContainer as _}; @@ -40,8 +40,9 @@ struct StatusProps<'a> { values: StatusValues, item: StatusItem, document: Option, - /// The active document's main canvas as its last pass showed it; a document not yet shown has no readout. - view: Option, + /// The zoom of the active document's main canvas as its last pass showed it, the one view field the readout shows + /// (a pan leaves it as it is); a document not yet shown has no readout. + zoom: Option, message: Option, out: Outbox<'a, StatusEvent>, } @@ -59,8 +60,8 @@ struct TrailingProps<'a> { enum StatusEvent { /// The readout's item was picked. Item(StatusItem), - /// The zoom field edited the view. - View(CanvasView), + /// The zoom field set the zoom, about the view's centre. + Zoom(f64), /// The zoom field cut an entry to its range. InvalidZoom(InvalidZoom), /// The job's Cancel was clicked. @@ -77,7 +78,7 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let values = chrome_ui::status_values(app); let item = chrome_ui::status_item(&app.ui.chrome); let document = app.session.active().map(|st| Size::new(st.doc.size.width as f64, st.doc.size.height as f64)); - let view = crate::canvas::active_view(app); + let zoom = crate::canvas::active_view(app).map(|view| view.zoom); let message = (!app.ui.status.is_empty()).then(|| StatusMessage::new(app.ui.status.clone()).tone(if app.ui.status_error { Tone::Warn } else { Tone::Neutral })); let render_path = chrome_ui::render_path_label(app) @@ -93,14 +94,14 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let _ = MemoView::new("status-bar-trailing", props, trailing_view).show(ui); }) .show(ui, |ui, _| { - let props = StatusProps { values: values.clone(), item, document, view, message: message.clone(), out: Outbox::new(&mut body_sent) }; + let props = StatusProps { values: values.clone(), item, document, zoom, message: message.clone(), out: Outbox::new(&mut body_sent) }; let _ = MemoView::new("status-bar", props, body_view).show(ui); }); let (mut picked, mut edited, mut invalid_zoom, mut cancelled) = (None, None, None, false); for event in body_sent.into_iter().chain(trailing_sent) { match event { StatusEvent::Item(item) => picked = Some(item), - StatusEvent::View(new) => edited = Some(new), + StatusEvent::Zoom(new) => edited = Some(new), StatusEvent::InvalidZoom(invalid) => invalid_zoom = Some(invalid), StatusEvent::CancelJob => cancelled = true, } @@ -108,11 +109,11 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { if let Some(picked) = picked { chrome_ui::set_status_item(&mut app.ui.chrome, picked); } - if let Some(new) = edited + if let Some(zoom) = edited && let Some(i) = app.session.active_index() { let ppp = app.canvas_ppp(); - app.ui.views[i].set_from(&new, ppp); + app.ui.views[i].set_zoom(zoom, ppp); } if cancelled && let Some((id, _)) = &job { crate::jobs_ui::cancel(app, *id); @@ -151,14 +152,16 @@ fn body_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { /// The members of the status bar's body: the readout, or "No document", and the status message. fn body_members(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { - match (props.document, props.view) { - (Some(size), Some(view)) => { + match (props.document, props.zoom) { + (Some(size), Some(zoom)) => { + // The readout reads the zoom alone; the rest of the view is the document's own, which an edit leaves. + let view = CanvasView::new(egui::Rect::ZERO, Point::ZERO, zoom); let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui); if let Some(picked) = out.item { props.out.send(StatusEvent::Item(picked)); } - if let Some(view) = out.view.value().copied() { - props.out.send(StatusEvent::View(view)); + if let Some(view) = out.view.value() { + props.out.send(StatusEvent::Zoom(view.zoom)); } if let Some(invalid) = out.invalid_zoom { props.out.send(StatusEvent::InvalidZoom(invalid)); From a5e476b9333f2d8dc853854184582593da0cafd0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 00:40:21 +0000 Subject: [PATCH 02/21] Status bar binds the zoom alone; what the app remembers in preferences moves no region's version (FW-365 F6) --- Cargo.lock | 123 ++++++------------- crates/engine-core/src/prefs/store.rs | 14 ++- crates/ui-egui/src/chrome_settle_trials.rs | 5 +- crates/ui-egui/src/panels/region_versions.rs | 2 +- crates/ui-egui/src/panels/status_bar.rs | 18 +-- crates/ui-egui/src/tool_memory.rs | 10 +- 6 files changed, 71 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 701a3199cf..75870532ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1365,7 +1365,6 @@ dependencies = [ [[package]] name = "craft" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-automation", "craft-behavior", @@ -1406,7 +1405,6 @@ dependencies = [ [[package]] name = "craft-affinity" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "crc32fast", "flate2", @@ -1427,7 +1425,6 @@ dependencies = [ [[package]] name = "craft-appkit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "block2 0.6.2", "objc2 0.6.5", @@ -1438,7 +1435,6 @@ dependencies = [ [[package]] name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "rustix 1.1.6", ] @@ -1446,7 +1442,6 @@ dependencies = [ [[package]] name = "craft-automation" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -1471,7 +1466,6 @@ dependencies = [ [[package]] name = "craft-behavior" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "accesskit", "bitflags 2.13.2", @@ -1489,7 +1483,6 @@ dependencies = [ [[package]] name = "craft-browse" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-docpath", @@ -1507,7 +1500,6 @@ dependencies = [ [[package]] name = "craft-cloud-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "egui", ] @@ -1515,7 +1507,6 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "md-5", "rayon", @@ -1524,12 +1515,10 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" [[package]] name = "craft-color" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", ] @@ -1537,7 +1526,6 @@ dependencies = [ [[package]] name = "craft-color-transform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-cms", "craft-color", @@ -1547,7 +1535,6 @@ dependencies = [ [[package]] name = "craft-color-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-cms", @@ -1567,7 +1554,6 @@ dependencies = [ [[package]] name = "craft-control" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-ai-agents", "craft-atomic", @@ -1583,7 +1569,6 @@ dependencies = [ [[package]] name = "craft-crs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-metadata", "craft-xml", @@ -1593,7 +1578,6 @@ dependencies = [ [[package]] name = "craft-crw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "thiserror 2.0.21", ] @@ -1601,7 +1585,6 @@ dependencies = [ [[package]] name = "craft-dds" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "rayon", ] @@ -1609,7 +1592,6 @@ dependencies = [ [[package]] name = "craft-develop" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-color", "craft-color-transform", @@ -1624,7 +1606,6 @@ dependencies = [ [[package]] name = "craft-develop-model" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-geom", "craft-metadata", @@ -1636,7 +1617,6 @@ dependencies = [ [[package]] name = "craft-dialogs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "block2 0.6.2", "craft-appkit", @@ -1662,7 +1642,6 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", ] @@ -1670,7 +1649,6 @@ dependencies = [ [[package]] name = "craft-draw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1689,12 +1667,10 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" [[package]] name = "craft-file-formats" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-eps", "craft-idml", @@ -1712,7 +1688,6 @@ dependencies = [ [[package]] name = "craft-flags" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-atomic", "dirs", @@ -1722,7 +1697,6 @@ dependencies = [ [[package]] name = "craft-font-catalog" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "fontique", "harfrust 0.13.3", @@ -1737,7 +1711,6 @@ dependencies = [ [[package]] name = "craft-font-manager" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-font-catalog", @@ -1757,7 +1730,6 @@ dependencies = [ [[package]] name = "craft-font-os-windows" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "windows-registry", "windows-sys 0.61.2", @@ -1766,7 +1738,6 @@ dependencies = [ [[package]] name = "craft-font-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "cap-primitives", "craft-atomic", @@ -1789,12 +1760,10 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" [[package]] name = "craft-geom" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", ] @@ -1802,7 +1771,6 @@ dependencies = [ [[package]] name = "craft-heif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "heic-rs", "rayon", @@ -1811,7 +1779,6 @@ dependencies = [ [[package]] name = "craft-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "bitflags 2.13.2", "craft-i18n", @@ -1824,7 +1791,6 @@ dependencies = [ [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "chrono", "fixed_decimal", @@ -1852,7 +1818,6 @@ dependencies = [ [[package]] name = "craft-idml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-xml", "craft-zip", @@ -1862,7 +1827,6 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-dds", "craft-heif", @@ -1890,7 +1854,6 @@ dependencies = [ [[package]] name = "craft-imaging" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1908,12 +1871,10 @@ dependencies = [ [[package]] name = "craft-ipp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "thiserror 2.0.21", ] @@ -1921,7 +1882,6 @@ dependencies = [ [[package]] name = "craft-keymap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-host", "craft-i18n", @@ -1936,7 +1896,6 @@ dependencies = [ [[package]] name = "craft-kra" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-xml", "craft-zip", @@ -1946,7 +1905,6 @@ dependencies = [ [[package]] name = "craft-layers" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-i18n", @@ -1960,7 +1918,6 @@ dependencies = [ [[package]] name = "craft-menu" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -1978,7 +1935,6 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "brotli-decompressor 6.3.2", "chrono", @@ -1990,7 +1946,6 @@ dependencies = [ [[package]] name = "craft-ora" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-xml", "craft-zip", @@ -2000,7 +1955,6 @@ dependencies = [ [[package]] name = "craft-pages" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-keymap", @@ -2016,7 +1970,6 @@ dependencies = [ [[package]] name = "craft-pcraft-bundle" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "blake3", "craft-atomic", @@ -2029,7 +1982,6 @@ dependencies = [ [[package]] name = "craft-pcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "flate2", "serde", @@ -2040,7 +1992,6 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "bytemuck", "flate2", @@ -2055,7 +2006,6 @@ dependencies = [ [[package]] name = "craft-pdn" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2064,7 +2014,6 @@ dependencies = [ [[package]] name = "craft-platform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "async-channel", "async-io", @@ -2095,7 +2044,6 @@ dependencies = [ [[package]] name = "craft-plist" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "thiserror 2.0.21", ] @@ -2103,7 +2051,6 @@ dependencies = [ [[package]] name = "craft-print" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -2127,7 +2074,6 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "encoding_rs", "flate2", @@ -2138,7 +2084,6 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "dispatch2", "egui", @@ -2151,7 +2096,6 @@ dependencies = [ [[package]] name = "craft-raw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "chrono", "craft-crw", @@ -2169,7 +2113,6 @@ dependencies = [ [[package]] name = "craft-review" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -2188,7 +2131,6 @@ dependencies = [ [[package]] name = "craft-settings" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-atomic", "craft-host", @@ -2205,7 +2147,6 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-image-codecs", "craft-xml", @@ -2226,7 +2167,6 @@ dependencies = [ [[package]] name = "craft-table" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-keymap", @@ -2238,12 +2178,10 @@ dependencies = [ [[package]] name = "craft-testkit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" [[package]] name = "craft-text" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-font-manager", @@ -2266,7 +2204,6 @@ dependencies = [ [[package]] name = "craft-theme" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "bitflags 2.13.2", "craft-tracked", @@ -2281,7 +2218,6 @@ dependencies = [ [[package]] name = "craft-theme-editor" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-theme", @@ -2292,7 +2228,6 @@ dependencies = [ [[package]] name = "craft-theme-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-atomic", "craft-behavior", @@ -2307,7 +2242,6 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", "thiserror 2.0.21", @@ -2317,7 +2251,6 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", "thiserror 2.0.21", @@ -2326,7 +2259,6 @@ dependencies = [ [[package]] name = "craft-timeline" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-keymap", @@ -2341,7 +2273,6 @@ dependencies = [ [[package]] name = "craft-tracked" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "serde", ] @@ -2349,7 +2280,6 @@ dependencies = [ [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-cloud-ui", "craft-ui-canvas", @@ -2363,7 +2293,6 @@ dependencies = [ [[package]] name = "craft-ui-canvas" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-i18n", @@ -2379,7 +2308,6 @@ dependencies = [ [[package]] name = "craft-ui-contract" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "accesskit", "craft-behavior", @@ -2421,7 +2349,6 @@ dependencies = [ [[package]] name = "craft-ui-macros" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2432,7 +2359,6 @@ dependencies = [ [[package]] name = "craft-ui-panels" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -2450,7 +2376,6 @@ dependencies = [ [[package]] name = "craft-ui-patterns" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -2471,7 +2396,6 @@ dependencies = [ [[package]] name = "craft-ui-shell" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -2491,7 +2415,6 @@ dependencies = [ [[package]] name = "craft-ui-widgets" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-behavior", "craft-host", @@ -2510,7 +2433,6 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "chrono", "craft-host", @@ -2539,7 +2461,6 @@ dependencies = [ [[package]] name = "craft-win32" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "winsafe", ] @@ -2547,7 +2468,6 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "craft-appkit", "craft-atomic", @@ -2579,7 +2499,6 @@ dependencies = [ [[package]] name = "craft-xcf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "flate2", "thiserror 2.0.21", @@ -2588,7 +2507,6 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "quick-xml 0.41.0", "serde", @@ -2598,7 +2516,6 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a46af76c7c74dd8dd375d694baaef00d5ae836a2#a46af76c7c74dd8dd375d694baaef00d5ae836a2" dependencies = [ "flate2", "thiserror 2.0.21", @@ -11398,6 +11315,46 @@ dependencies = [ "winnow", ] +[[patch.unused]] +name = "hayro" +version = "0.7.1" + +[[patch.unused]] +name = "hayro-cmap" +version = "0.1.0" + +[[patch.unused]] +name = "hayro-interpret" +version = "0.7.0" + +[[patch.unused]] +name = "hayro-jbig2" +version = "0.3.0" + +[[patch.unused]] +name = "hayro-postscript" +version = "0.1.0" + +[[patch.unused]] +name = "hayro-syntax" +version = "0.7.2" + +[[patch.unused]] +name = "krilla" +version = "0.8.2" + +[[patch.unused]] +name = "linesweeper" +version = "0.5.0" + +[[patch.unused]] +name = "vello_common" +version = "0.0.8" + +[[patch.unused]] +name = "vello_cpu" +version = "0.0.8" + [[patch.unused]] name = "egui_demo_lib" version = "0.37.0" diff --git a/crates/engine-core/src/prefs/store.rs b/crates/engine-core/src/prefs/store.rs index f27efc0d6b..9ddb4e72b8 100644 --- a/crates/engine-core/src/prefs/store.rs +++ b/crates/engine-core/src/prefs/store.rs @@ -8,6 +8,7 @@ use super::{Deserialize, Map, Preferences, Serialize, Value}; pub struct PrefsStore { values: Preferences, rev: u64, + settings_rev: u64, catalog_rev: u64, section_revs: std::collections::BTreeMap, } @@ -16,8 +17,15 @@ impl PrefsStore { pub fn get(&self) -> &Preferences { &self.values } - /// Change preferences; bumps the revision. + /// Change preferences; bumps the revision and the settings revision. pub fn edit(&mut self, f: impl FnOnce(&mut Preferences) -> R) -> R { + self.settings_rev += 1; + self.remember(f) + } + /// Store what the app remembers of its own state between launches (the selected tool, its options, the colours): + /// bumps the revision, so frontends persist, but not the settings revision, because no view reads these back from + /// the preferences; they show the state itself. + pub fn remember(&mut self, f: impl FnOnce(&mut Preferences) -> R) -> R { let before = (&self.values.shortcuts, &self.values.alternate_shortcuts, &self.values.toolbar); let before = (before.0.clone(), before.1.clone(), before.2.clone()); let sections = self.values.sections.clone(); @@ -45,6 +53,10 @@ impl PrefsStore { pub fn rev(&self) -> u64 { self.rev } + /// Revision of the preferences views read: every [`edit`](Self::edit), not what the app [`remember`](Self::remember)s. + pub fn settings_rev(&self) -> u64 { + self.settings_rev + } } /// The preferences file format written by [`SavedPrefsExt::prefs_value`](crate::prefs::SavedPrefsExt::prefs_value). 2: Use Shift Key for Tool diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 96a5f0e015..816dae1d5e 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -249,7 +249,6 @@ fn a_tool_option_runs_the_options_bar_once() { let on = h.state().ui.tool_options.move_auto_select; h.state_mut().ui.tool_options.move_auto_select = !on; assert!(ran_over(&mut h, 1, "OptionsSlot<") > 0, "a changed option runs the bar"); - // The frame after the run settles (a run's second pass replays what the first ran); then two idle frames run nothing. - h.run_steps(1); - assert_eq!(ran_over(&mut h, 2, "OptionsSlot<"), 0, "the bar's own run leaves the version as it was"); + // What the bar's frame remembers of the option (the saved preferences) moves no version. + assert_eq!(ran_over(&mut h, 3, "OptionsSlot<"), 0, "the frames after the changed one run no bar"); } diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 9a62545fad..e05032b9ce 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -159,7 +159,7 @@ pub(crate) fn changes_only_the_view(app: &PhotocraftApp, id: &str) -> bool { fn version(app: &PhotocraftApp, extra: impl Hash) -> u64 { let mut hasher = std::collections::hash_map::DefaultHasher::new(); app.commands_run.hash(&mut hasher); - app.session.prefs.rev().hash(&mut hasher); + app.session.prefs.settings_rev().hash(&mut hasher); app.session.active_generation().hash(&mut hasher); app.session.active_layer_changes().hash(&mut hasher); app.session.active().map(|st| st.revision).hash(&mut hasher); diff --git a/crates/ui-egui/src/panels/status_bar.rs b/crates/ui-egui/src/panels/status_bar.rs index d3eeec2f7e..2049992d00 100644 --- a/crates/ui-egui/src/panels/status_bar.rs +++ b/crates/ui-egui/src/panels/status_bar.rs @@ -1,5 +1,5 @@ use craft::behavior::CanvasView; -use craft::behavior::kurbo::{Point, Size}; +use craft::behavior::kurbo::Size; use craft::theme::variant::Tone; use craft::ui::bars::{Bar, BarKind, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues}; use craft::ui::contract::{Bind, MemoProps, MemoView, Outbox, ShowContainer as _}; @@ -154,14 +154,12 @@ fn body_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { fn body_members(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { match (props.document, props.zoom) { (Some(size), Some(zoom)) => { - // The readout reads the zoom alone; the rest of the view is the document's own, which an edit leaves. - let view = CanvasView::new(egui::Rect::ZERO, Point::ZERO, zoom); - let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui); + let out = StatusReadout::new(Bind::given(zoom), size, props.item, &props.values).show(ui); if let Some(picked) = out.item { props.out.send(StatusEvent::Item(picked)); } - if let Some(view) = out.view.value() { - props.out.send(StatusEvent::Zoom(view.zoom)); + if let Some(zoom) = out.zoom_edits.value() { + props.out.send(StatusEvent::Zoom(*zoom)); } if let Some(invalid) = out.invalid_zoom { props.out.send(StatusEvent::InvalidZoom(invalid)); @@ -189,9 +187,13 @@ pub(crate) fn document_window_status(app: &mut PhotocraftApp, ui: &mut egui::Ui, let (mut picked, mut edited, mut invalid_zoom) = (None, None, None); Bar::new("", BarKind::Status).show(ui, |ui, _| { if let (Some(size), Some(view)) = (size, view) { - let out = StatusReadout::new(Bind::given(view), size, item, &values).show(ui); + let out = StatusReadout::new(Bind::given(view.zoom), size, item, &values).show(ui); picked = out.item; - edited = out.view.value().copied(); + edited = out.zoom_edits.value().map(|zoom| { + let mut zoomed = view; + zoomed.zoom = *zoom; + zoomed + }); invalid_zoom = out.invalid_zoom; } }); diff --git a/crates/ui-egui/src/tool_memory.rs b/crates/ui-egui/src/tool_memory.rs index 7c4b555616..2a21e5d089 100644 --- a/crates/ui-egui/src/tool_memory.rs +++ b/crates/ui-egui/src/tool_memory.rs @@ -90,7 +90,7 @@ pub fn persist(app: &mut PhotocraftApp, ctx: &egui::Context) { if let Ok(now) = serde_json::to_value(tool) && app.session.prefs().selected_tool != now { - app.session.prefs.edit(|p| p.selected_tool = now); + app.session.prefs.remember(|p| p.selected_tool = now); // prefs_ui::tick ran before the panels; ensure it can flush this new revision. ctx.request_repaint(); } @@ -104,7 +104,7 @@ pub fn persist(app: &mut PhotocraftApp, ctx: &egui::Context) { app.prefs_rt.tool_options = Some(app.ui.tool_options.clone()); let now = changed(&app.ui.tool_options); if app.session.prefs().tool_options != now { - app.session.prefs.edit(|p| p.tool_options = now); + app.session.prefs.remember(|p| p.tool_options = now); } } @@ -138,7 +138,7 @@ fn persist_colors(app: &mut PhotocraftApp, ctx: &egui::Context) { photocraft_engine::prefs::stamp_tool_color_picks(&mut saved, &app.session.prefs().tool_colors); saved }; - app.session.prefs.edit(|p| p.tool_colors = photocraft_engine::prefs::ToolColors(saved)); + app.session.prefs.remember(|p| p.tool_colors = photocraft_engine::prefs::ToolColors(saved)); // Panels and shortcuts can change colours after prefs_ui::tick already ran this frame. ctx.request_repaint(); } @@ -289,7 +289,7 @@ fn persist_group_tools(app: &mut PhotocraftApp, ctx: &egui::Context, tool: Tool) if let Ok(now) = serde_json::to_value(&app.ui.group_tools) && app.session.prefs().group_tools != now { - app.session.prefs.edit(|p| p.group_tools = now); + app.session.prefs.remember(|p| p.group_tools = now); // As for the selected tool: prefs_ui::tick ran before the panels. ctx.request_repaint(); } @@ -322,7 +322,7 @@ fn persist_brushes(app: &mut PhotocraftApp) { }; app.prefs_rt.tool_brushes = Some((owner, brushes.clone())); if app.session.prefs().tool_brushes != now { - app.session.prefs.edit(|p| p.tool_brushes = now); + app.session.prefs.remember(|p| p.tool_brushes = now); } } From 7c937ffa41a063f4c27d463c8de876447a0bdb75 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 00:42:19 +0000 Subject: [PATCH 03/21] Panel layout and Color panel options are remembered without moving the settings revision (FW-365 F6) --- crates/ui-egui/src/dock.rs | 2 +- crates/ui-egui/src/panels/color_panel_ui.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 11bdb80991..6030e04d50 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -23,7 +23,7 @@ pub fn persist(app: &mut PhotocraftApp) { } let now = snapshot(app); if app.session.prefs().panel_layout != now { - app.session.prefs.edit(|prefs| prefs.panel_layout = now); + app.session.prefs.remember(|prefs| prefs.panel_layout = now); } } diff --git a/crates/ui-egui/src/panels/color_panel_ui.rs b/crates/ui-egui/src/panels/color_panel_ui.rs index dc1b08d934..e854766d01 100644 --- a/crates/ui-egui/src/panels/color_panel_ui.rs +++ b/crates/ui-egui/src/panels/color_panel_ui.rs @@ -15,7 +15,7 @@ pub fn persist(app: &mut PhotocraftApp) { } let Ok(now) = serde_json::to_value(app.ui.color_panel) else { return }; if stored != now { - app.session.prefs.edit(|p| p.color_panel = now.clone()); + app.session.prefs.remember(|p| p.color_panel = now.clone()); } app.ui.color_panel_synced = Some(now); } From 9de80929769dc67e29d57714bf20aeb389e66a44 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 01:00:11 +0000 Subject: [PATCH 04/21] perf(ui): the dock keys its columns by the panels' versions The dock shows each column as a memoized view keyed by the versions of the panels it shows (craft-libs DockPanels::content): every panel returns its region version, the toolbar a version of its rail (the slots and tool in the preferences, the remembered group tools, the Edit Toolbar drawer and the footer). The canvas has no version yet, so the docked tree it sits in runs every pass while the columns beside it replay. The chrome settle trials count the dock's inner views (tab rows, column bars, panel bodies, the toolbar footer) as run or replayed only where their column runs; at rest they replay inside the column's view, so the trials assert that nothing ran and the column views replayed. Needs the craft-libs pin moved to a commit with the dock's column views. --- crates/ui-egui/src/chrome_settle_trials.rs | 35 ++++++++++++-------- crates/ui-egui/src/panels/panel_docking.rs | 11 ++++++ crates/ui-egui/src/panels/region_versions.rs | 7 ++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 83b4a8dd81..b70ad60dd6 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -58,8 +58,8 @@ fn tab_strip_runs(h: &H) -> Vec<(&'static str, u32)> { last_pass_runs(&h.ctx).into_iter().filter(|(ty, _)| ty.contains("TabStrip<'_, craft_ui_panels::docking::PanelKey>")).collect() } -/// A hover over the canvas replays the dock's tab rows and column bars and the menu bar (memoized views) and runs no -/// panel tab strip. +/// A hover over the canvas replays the dock's tab rows and column bars (in the columns' views, which replay whole) and +/// the menu bar (memoized views) and runs no panel tab strip. #[test] fn a_hover_over_the_canvas_replays_the_dock_chrome_and_the_menu_bar() { let mut h = harness(); @@ -70,9 +70,12 @@ fn a_hover_over_the_canvas_replays_the_dock_chrome_and_the_menu_bar() { h.run_steps(1); // The menu bar sits in the title bar's own view: while that replays, the menu bar replays with it. let title_replayed = views(&h, "TitleSlot<", MemoRun::Replayed) == 1; + let columns = (views_ran(&h, "area::ColumnView<"), views(&h, "area::ColumnView<", MemoRun::Replayed)); + assert!(columns.0 == 0 && columns.1 >= 1, "hover step {step}: the dock's columns replay: {columns:?}"); let views = chrome_views(&h); for kind in ["TabRow", "dock_column::bar::BarProps", "menu::bar::BarProps"] { - let shown = views.iter().any(|(name, _)| name.contains(kind)) || (kind == "menu::bar::BarProps" && title_replayed); + let replayed_with = if kind == "menu::bar::BarProps" { title_replayed } else { columns.1 >= 1 }; + let shown = views.iter().any(|(name, _)| name.contains(kind)) || replayed_with; assert!(shown, "hover step {step}: the chrome shows a {kind} view: {views:?}"); } let ran: Vec<_> = views.iter().filter(|(_, run)| *run != MemoRun::Replayed).collect(); @@ -81,8 +84,9 @@ fn a_hover_over_the_canvas_replays_the_dock_chrome_and_the_menu_bar() { } } -/// A hover over the canvas replays the title bar, the options bar, the status bar (its own view) and every panel body: the -/// panels read the modifiers, not the pointer frame (storytold/craft-libs#2812), so a pointer move runs none of them. +/// A hover over the canvas replays the title bar, the options bar, the status bar (its own view) and every panel body +/// (in the columns' views, which replay whole): the panels read the modifiers, not the pointer frame +/// (storytold/craft-libs#2812), so a pointer move runs none of them. #[test] fn a_hover_over_the_canvas_replays_the_bars_and_the_panel_bodies() { let mut h = harness(); @@ -93,13 +97,17 @@ fn a_hover_over_the_canvas_replays_the_bars_and_the_panel_bodies() { for slot in ["TitleSlot<", "OptionsSlot<", "status_bar::StatusProps<"] { assert_eq!((views_ran(&h, slot), views(&h, slot, MemoRun::Replayed)), (0, 1), "hover step {step}: the {slot} view replays"); } - let bodies = (views_ran(&h, "region_versions::PanelBody<"), views(&h, "region_versions::PanelBody<", MemoRun::Replayed)); - assert!(bodies.0 == 0 && bodies.1 >= 2, "hover step {step}: every panel body replays: {bodies:?}"); + let columns = (views_ran(&h, "area::ColumnView<"), views(&h, "area::ColumnView<", MemoRun::Replayed)); + assert!( + views_ran(&h, "region_versions::PanelBody<") == 0 && columns == (0, columns.1) && columns.1 >= 2, + "hover step {step}: every panel body replays with its column: {columns:?}" + ); } } -/// A hover over the canvas replays the toolbar's footer (the colour chips, Quick Mask and Screen Mode): the rail replays -/// its tool buttons but calls its footer every pass, so before it was a view of its own it ran on every frame (#15493). +/// A hover over the canvas replays the toolbar's footer (the colour chips, Quick Mask and Screen Mode) with the toolbar's +/// column: the rail replays its tool buttons but calls its footer every pass, so before it was a view of its own it ran +/// on every frame (#15493). #[test] fn a_hover_over_the_canvas_replays_the_toolbar_footer() { let mut h = harness(); @@ -107,8 +115,8 @@ fn a_hover_over_the_canvas_replays_the_toolbar_footer() { for step in 1..=3 { h.event(Event::PointerMoved(at + vec2(step as f32, 0.0))); h.run_steps(1); - let footer = (views_ran(&h, "toolbar::FooterProps<"), views(&h, "toolbar::FooterProps<", MemoRun::Replayed)); - assert_eq!(footer, (0, 1), "hover step {step}: the toolbar footer replays"); + let columns = (views_ran(&h, "area::ColumnView<"), views(&h, "area::ColumnView<", MemoRun::Replayed)); + assert!(views_ran(&h, "toolbar::FooterProps<") == 0 && columns.0 == 0 && columns.1 >= 1, "hover step {step}: the toolbar footer replays: {columns:?}"); } } @@ -120,8 +128,9 @@ fn a_zoom_runs_only_the_panels_that_show_the_view() { let ctx = h.ctx.clone(); crate::menus::invoke(h.state_mut(), &ctx, "view.zoomIn", json!({})).unwrap(); h.run_steps(1); - let bodies = (views_ran(&h, "region_versions::PanelBody<"), views(&h, "region_versions::PanelBody<", MemoRun::Replayed)); - assert!(bodies.0 <= 1 && bodies.1 >= 2, "only the Navigator's body may run, the others replay: {bodies:?}"); + let columns = views(&h, "area::ColumnView<", MemoRun::Replayed); + let bodies = views_ran(&h, "region_versions::PanelBody<"); + assert!(bodies <= 1 && columns >= 1, "only the Navigator's body may run, the other columns replay: {bodies} ran, {columns} columns replayed"); } /// The footer runs again when a colour it shows changes without a command (the Color panel's sliders, a Color Picker diff --git a/crates/ui-egui/src/panels/panel_docking.rs b/crates/ui-egui/src/panels/panel_docking.rs index b58b191e24..180dcd1e3b 100644 --- a/crates/ui-egui/src/panels/panel_docking.rs +++ b/crates/ui-egui/src/panels/panel_docking.rs @@ -231,6 +231,17 @@ impl DockPanels for Panels<'_> { } } + /// The version of what the dock shows for a panel, which keys its column: the canvas shows state that changes + /// without a command (the view, redraw progress, animation and job overlays) and has none, so the docked tree it + /// sits in runs every pass while the columns beside it replay. + fn content(&self, panel: &String) -> Option { + match panel.as_str() { + CANVAS => None, + TOOLBAR => Some(super::region_versions::toolbar(self.app)), + id => Some(super::region_versions::panel(self.app, id)), + } + } + /// The canvas group is the document area: it draws its own tabs and documents in the group's rect. The toolbar's /// group is its rail, which takes the group's full rect and measures its height at a width. fn group_view(&mut self, panels: &[String], _: usize, ui: &mut egui::Ui, at: GroupAt, _: &mut BodyCx<'_>) -> Option { diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index 31abdea38b..db70362538 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -91,6 +91,13 @@ pub(crate) fn toolbar_footer(app: &PhotocraftApp) -> u64 { version(app, (colours(app), quick_mask, app.ui.view.screen_mode)) } +/// The version of the toolbar's group view, which the dock keys the toolbar's column by: the rail's slots (in the +/// preferences, which [`version`] holds with the tool), the tools its groups remember, whether the Edit Toolbar drawer +/// is open, and what the footer shows ([`toolbar_footer`]). +pub(crate) fn toolbar(app: &PhotocraftApp) -> u64 { + version(app, (toolbar_footer(app), &app.ui.group_tools, app.ui.toolbar_drawer)) +} + /// The version of the title bar: the title it shows (the active document's name and its unsaved mark), the language /// its menu titles are in, whether the menus are in the bar (not in the macOS menu bar) and whether the bar takes the /// menu keys (F10, Alt, Alt+letter), which a dialog or the shortcut recorder holds back: a dialog closed with Escape From 02c84a6f94821e6336c9158d1f3f0010686467b5 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 01:05:03 +0000 Subject: [PATCH 05/21] Tool options carry a revision: the options bar's version reads it, serialized() is gone (FW-365 F6b) --- crates/ui-egui/src/app/frame.rs | 4 ++++ ...background_eraser_tolerance_field_tests.rs | 2 +- crates/ui-egui/src/chrome_settle_trials.rs | 18 ++++++++++++++++ .../src/panels/preset_panels/tool_presets.rs | 4 ++-- crates/ui-egui/src/panels/region_versions.rs | 21 +------------------ crates/ui-egui/src/prefs/prefs_ui/tests.rs | 6 +++--- crates/ui-egui/src/state.rs | 4 ++-- crates/ui-egui/src/state/tool_options.rs | 9 +++++--- crates/ui-egui/src/tool_memory.rs | 8 +++---- .../ui-egui/src/tools/perspective_crop_ui.rs | 2 +- crates/ui-egui/src/tools/shape_stroke_ui.rs | 2 +- crates/ui-egui/src/tools/tool_reset.rs | 4 ++-- .../src/tools/type_tool/canvas_tests.rs | 4 ++-- crates/ui-egui/src/tools/type_tool/pointer.rs | 2 +- crates/ui-egui/src/tools/vector_ui.rs | 2 +- crates/ui-egui/src/tools/vector_ui/pen.rs | 4 ++-- .../vector_ui/triangle_align_edges_tests.rs | 2 +- 17 files changed, 52 insertions(+), 46 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index e15fcfeaac..151bd3f0ab 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -162,7 +162,11 @@ impl PhotocraftApp { // A software adapter or CPU mode chosen at startup is every document's reason. crate::render_path::frame(self); // Every frame that started its stage record closes it, whichever way `ui_body` returns. + // Controls and panels write their values back on every pass; only the writes that change an option move its + // revision, which the options bar's version holds, so a pass that changed nothing leaves the bar settled. + let options = self.ui.tool_options.checkpoint(); self.ui_body(ui); + self.ui.tool_options.settle(options); // What an injected step changed is the target of the rest of its request: only a change // between passes withdraws queued input (`withdraw_stale_input`). #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/ui-egui/src/background_eraser_tolerance_field_tests.rs b/crates/ui-egui/src/background_eraser_tolerance_field_tests.rs index 1c339ff7cb..0bdeb32fc5 100644 --- a/crates/ui-egui/src/background_eraser_tolerance_field_tests.rs +++ b/crates/ui-egui/src/background_eraser_tolerance_field_tests.rs @@ -52,7 +52,7 @@ fn type_into(h: &mut Harness<'static, Box>, name: &str, text: &st #[test] fn options_bar_fields_that_alert_past_their_range() { type Read = fn(&PhotocraftApp) -> f32; - let o = |a: &PhotocraftApp| -> ToolOptions { a.ui.tool_options.clone() }; + let o = |a: &PhotocraftApp| -> ToolOptions { (*a.ui.tool_options).clone() }; let _ = o; // (tool, field, typed, kept, alerts) let rows: [(Tool, &str, &str, f32, bool, Read); 11] = [ diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index 816dae1d5e..b0ea8b1033 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -252,3 +252,21 @@ fn a_tool_option_runs_the_options_bar_once() { // What the bar's frame remembers of the option (the saved preferences) moves no version. assert_eq!(ran_over(&mut h, 3, "OptionsSlot<"), 0, "the frames after the changed one run no bar"); } + +/// A bar that runs and writes every control's value back leaves the tool options' revision alone, so idle frames never +/// move what the bar's version holds. +#[test] +fn an_idle_options_bar_leaves_the_tool_options_revision() { + let mut h = harness(); + h.state_mut().ui.tool = crate::state::Tool::Move; + h.run_steps(4); + let settled = h.state().ui.tool_options.revision(); + h.run_steps(10); + assert_eq!(h.state().ui.tool_options.revision(), settled, "ten idle frames"); + // A changed option runs the bar, whose own writes then change nothing more. + let on = h.state().ui.tool_options.move_auto_select; + h.state_mut().ui.tool_options.move_auto_select = !on; + let changed = h.state().ui.tool_options.revision(); + h.run_steps(10); + assert_eq!(h.state().ui.tool_options.revision(), changed, "the bar's run after a change"); +} diff --git a/crates/ui-egui/src/panels/preset_panels/tool_presets.rs b/crates/ui-egui/src/panels/preset_panels/tool_presets.rs index 8e8150e76f..69a3b6bd85 100644 --- a/crates/ui-egui/src/panels/preset_panels/tool_presets.rs +++ b/crates/ui-egui/src/panels/preset_panels/tool_presets.rs @@ -39,7 +39,7 @@ pub fn select(app: &mut PhotocraftApp, name: &str) { } } if let Ok(opts) = serde_json::from_value(cur) { - app.ui.tool_options = opts; + *app.ui.tool_options = opts; } } // As the options bar does: a crop preset's ratio (or W x H) fits the frame at once. @@ -132,7 +132,7 @@ mod tests { let mut flipped = serde_json::to_value(&app.ui.tool_options).unwrap(); flip_bools(&mut flipped); flipped["feather"] = json!(0.0); - app.ui.tool_options = serde_json::from_value(flipped.clone()).unwrap(); + *app.ui.tool_options = serde_json::from_value(flipped.clone()).unwrap(); select(&mut app, &name); let after = serde_json::to_value(&app.ui.tool_options).unwrap(); assert_eq!(after["feather"], json!(5.0)); diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index e05032b9ce..efe1e95781 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -76,7 +76,7 @@ pub(crate) fn show_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: &str) { pub(crate) fn options_bar(app: &PhotocraftApp) -> u64 { let sessions = (crate::transform_tool::bar_key(app), crate::puppet_ui::bar_key(app), crate::perspective_ui::bar_key(app), crate::crop_ui::bar::bar_key(app)); - let shown = (serialized(&app.ui.tool_options), super::options_bar::edit_key(app), text_target(app)); + let shown = (app.ui.tool_options.revision(), super::options_bar::edit_key(app), text_target(app)); // A canvas gesture's start and end change what the bar enables (the symmetry menu's Transform entry). let gesture = crate::canvas::tools::in_gesture(app); let hidden = app.session.active().map(|st| (st.doc.id.0, app.ui.hidden_work_path.as_ref().map(|(id, _)| *id))); @@ -169,25 +169,6 @@ fn version(app: &PhotocraftApp, extra: impl Hash) -> u64 { hasher.finish() } -/// A hash of `value` through its serialized form, which holds every stored field: for app state whose type has no -/// `Hash` (floats, framework types). -fn serialized(value: &impl serde::Serialize) -> u64 { - struct HashWriter<'a>(&'a mut std::collections::hash_map::DefaultHasher); - impl std::io::Write for HashWriter<'_> { - fn write(&mut self, bytes: &[u8]) -> std::io::Result { - self.0.write(bytes); - Ok(bytes.len()) - } - fn flush(&mut self) -> std::io::Result<()> { - Ok(()) - } - } - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - // Writing to a hasher cannot fail, and every tool option serializes (they are saved). - let _ = serde_json::to_writer(HashWriter(&mut hasher), value); - hasher.finish() -} - /// The brush and its presets, for the options bar: their revisions move with every change of either. fn brush(app: &PhotocraftApp) -> (u64, u64) { (app.session.tools.brush_rev, app.session.tools.presets_rev) diff --git a/crates/ui-egui/src/prefs/prefs_ui/tests.rs b/crates/ui-egui/src/prefs/prefs_ui/tests.rs index 79223c28bb..2c9ecb1840 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/tests.rs @@ -862,7 +862,7 @@ fn restart_cases() -> Vec { assert_eq!(stored["selectedTool"], json!("Eraser")); assert_eq!(app.ui.tool, Tool::Eraser, "restored before the first frame"); assert_eq!(app.ui.group_tool(Tool::Eraser.key()), Some(Tool::Eraser)); - assert_eq!(app.ui.tool_options, crate::state::ToolOptions::default()); + assert_eq!(*app.ui.tool_options, crate::state::ToolOptions::default()); }), }, Case { @@ -1106,7 +1106,7 @@ fn damaged_cases() -> (Vec, Vec) { }, )); cases.push(loaded("tool options: a good value is left alone", json!({"toolOptions": {"feather": 12.5}}), move |app| { - assert_eq!(app.ui.tool_options, crate::state::ToolOptions { feather: 12.5, ..d() }); + assert_eq!(*app.ui.tool_options, crate::state::ToolOptions { feather: 12.5, ..d() }); let mut def = d(); crate::tool_memory::sanitize(&mut def); assert_eq!(def, d(), "in-range defaults never change"); @@ -1436,7 +1436,7 @@ fn reset_tools_clear_the_remembered_options_and_brushes() { |brushes: &[(Tool, photocraft_engine::BrushSettings)]| brushes.iter().all(|(t, b)| *b == crate::paint_mouse::fresh_brush(*t, b) && b.size != 77.0); assert!(starting(&app.ui.tool_brushes), "{saved}"); let app2 = app_on(&store); - assert_eq!(app2.ui.tool_options, crate::state::ToolOptions::default()); + assert_eq!(*app2.ui.tool_options, crate::state::ToolOptions::default()); assert!(!app2.ui.tool_brushes.is_empty() && starting(&app2.ui.tool_brushes), "remembered across a restart"); } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 78f2ae4726..5ad2b02ab1 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -422,7 +422,7 @@ pub struct UiState { #[serde(default)] pub selection_mode: u8, #[serde(default)] - pub tool_options: ToolOptions, + pub tool_options: Tracked, /// The shape Fill / Stroke swatches' recently used gradients, newest first (the Gradient /// tab's Recent row). #[serde(default)] @@ -546,7 +546,7 @@ impl Default for UiState { brush_curves_open: BTreeSet::new(), brushes_panel: brushes_list(), selection_mode: 0, - tool_options: ToolOptions::default(), + tool_options: Tracked::new(ToolOptions::default()), recent_gradients: Vec::new(), next_id: 1, status: String::new(), diff --git a/crates/ui-egui/src/state/tool_options.rs b/crates/ui-egui/src/state/tool_options.rs index 7c699804ae..4638ca23a0 100644 --- a/crates/ui-egui/src/state/tool_options.rs +++ b/crates/ui-egui/src/state/tool_options.rs @@ -3,11 +3,13 @@ use craft::draw::ui::crop::{CropSettings, CropSizeFields}; use craft::draw::ui::{PathOptionsSettings, TransformSettings, VectorMode}; use craft::imaging::ui::select::MagneticSettings; +use craft::ui::contract::PlainData; + use super::tool::Tool; use super::{Deserialize, Serialize}; /// Object Selection › gear › Object Finder Mode (#12857). -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, PlainData)] pub enum ObjectFinderMode { /// Auto Refresh: the finder re-analyses the document after every edit. #[default] @@ -17,7 +19,7 @@ pub enum ObjectFinderMode { } /// Options-bar state for tools (Photoshop keeps these per tool). -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, PlainData)] #[serde(default)] pub struct ToolOptions { pub tolerance: f32, @@ -77,6 +79,7 @@ pub struct ToolOptions { /// parameter format. Kept as overrides so saved engine defaults still supply unset fields. /// OpenType features and variable-font axes are merged per tag/axis. #[serde(default)] + #[plain_data(assume = "a JSON map of owned values: no interior mutability")] pub type_style_defaults: serde_json::Map, /// Type tool: paragraph direction of new type, "auto" (from the first strong character), /// "ltr" or "rtl" (TYPE-218-2). @@ -377,7 +380,7 @@ pub(super) fn default_brush_tool() -> Tool { /// tool, all off by default except the Patch tool's Content-Aware Sample All Layers (#5524, /// #12125): turning it on for the Magic Wand must not leave Blur or Smudge copying the composite /// onto the active layer. The Mixer Brush keeps its own with the brush (`MixerSettings`). -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, PlainData)] #[serde(default)] pub struct SampleAllLayers { pub magic_wand: bool, diff --git a/crates/ui-egui/src/tool_memory.rs b/crates/ui-egui/src/tool_memory.rs index 2a21e5d089..70ad69cdef 100644 --- a/crates/ui-egui/src/tool_memory.rs +++ b/crates/ui-egui/src/tool_memory.rs @@ -98,10 +98,10 @@ pub fn persist(app: &mut PhotocraftApp, ctx: &egui::Context) { persist_colors(app, ctx); persist_group_tools(app, ctx, tool); persist_brushes(app); - if app.prefs_rt.tool_options.as_ref() == Some(&app.ui.tool_options) { + if app.prefs_rt.tool_options.as_ref() == Some(&*app.ui.tool_options) { return; } - app.prefs_rt.tool_options = Some(app.ui.tool_options.clone()); + app.prefs_rt.tool_options = Some((*app.ui.tool_options).clone()); let now = changed(&app.ui.tool_options); if app.session.prefs().tool_options != now { app.session.prefs.remember(|p| p.tool_options = now); @@ -422,12 +422,12 @@ pub fn restore(app: &mut PhotocraftApp) { } if let Ok(mut o) = serde_json::from_value(Value::Object(cur)) { sanitize(&mut o); - app.ui.tool_options = o; + *app.ui.tool_options = o; } } else if !saved.is_null() { log::warn!("Preferences: the remembered tool options are not an object; using the defaults"); } - app.prefs_rt.tool_options = Some(app.ui.tool_options.clone()); + app.prefs_rt.tool_options = Some((*app.ui.tool_options).clone()); restore_colors(app); restore_brushes(app); } diff --git a/crates/ui-egui/src/tools/perspective_crop_ui.rs b/crates/ui-egui/src/tools/perspective_crop_ui.rs index 120add25a6..86e98d577e 100644 --- a/crates/ui-egui/src/tools/perspective_crop_ui.rs +++ b/crates/ui-egui/src/tools/perspective_crop_ui.rs @@ -204,7 +204,7 @@ pub fn committed(app: &mut PhotocraftApp, out: &BarOutput) { /// range alert once. pub fn options(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let document = document(app).unwrap_or_else(|| CropDocument::new(CropDocKey::new(0), Size::ZERO, 72.0)); - let options = &mut app.ui.tool_options; + let options = &mut *app.ui.tool_options; let shown = PerspectiveCropBar::new(&mut options.perspective_crop, &document, Bind::bound(&mut options.perspective_crop_grid)).show(ui); if let Some(alert) = shown.out_of_range { crate::option_cells::range_alert(app, ui, &alert); diff --git a/crates/ui-egui/src/tools/shape_stroke_ui.rs b/crates/ui-egui/src/tools/shape_stroke_ui.rs index 47aa2f5ad1..aec669e9cc 100644 --- a/crates/ui-egui/src/tools/shape_stroke_ui.rs +++ b/crates/ui-egui/src/tools/shape_stroke_ui.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; /// Colour and width stay in their existing controls. These options never replace a shape's paint. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, craft::ui::contract::PlainData)] #[serde(default)] pub struct StrokeOptions { pub align: StrokeAlign, diff --git a/crates/ui-egui/src/tools/tool_reset.rs b/crates/ui-egui/src/tools/tool_reset.rs index f324663a30..bd8396891a 100644 --- a/crates/ui-egui/src/tools/tool_reset.rs +++ b/crates/ui-egui/src/tools/tool_reset.rs @@ -98,7 +98,7 @@ fn reset_tool(app: &mut PhotocraftApp, tool: Tool) { fn reset_all(app: &mut PhotocraftApp) { crate::frame_tool::clear(app); app.ui.frame_tool = Default::default(); - app.ui.tool_options = ToolOptions::default(); + *app.ui.tool_options = ToolOptions::default(); app.ui.artboard_tool = Default::default(); app.ui.selection_mode = 0; reset_session_brush(app); @@ -381,7 +381,7 @@ mod tests { let dialog = crate::menus::invoke(&mut app, &ctx, RESET_ALL, json!({})).unwrap()["dialog"].as_str().unwrap().to_string(); assert_eq!(answer_dialog(&mut app, &ctx, "ui.dialog.confirm", &dialog)["ok"], true); - assert_eq!(app.ui.tool_options, ToolOptions::default()); + assert_eq!(*app.ui.tool_options, ToolOptions::default()); assert!(!app.dialog_open()); } diff --git a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs index 0cd9005cf7..0114c25123 100644 --- a/crates/ui-egui/src/tools/type_tool/canvas_tests.rs +++ b/crates/ui-egui/src/tools/type_tool/canvas_tests.rs @@ -351,13 +351,13 @@ mod panel_defaults { assert_eq!(c.variations.len(), 2); let saved = serde_json::to_value(&app.ui.tool_options).unwrap(); let restored: ToolOptions = serde_json::from_value(saved.clone()).unwrap(); - assert_eq!(restored, app.ui.tool_options); + assert_eq!(restored, *app.ui.tool_options); crate::tool_memory::persist(&mut app, &ctx); let remembered = app.session.prefs().tool_options.clone(); let mut restarted = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); restarted.session.prefs.edit(|p| p.tool_options = remembered); crate::tool_memory::restore(&mut restarted); - assert_eq!(restarted.ui.tool_options, restored, "the real preference restore path retains panel defaults"); + assert_eq!(*restarted.ui.tool_options, restored, "the real preference restore path retains panel defaults"); let mut legacy = saved; legacy.as_object_mut().unwrap().remove("type_style_defaults"); let legacy: ToolOptions = serde_json::from_value(legacy).unwrap(); diff --git a/crates/ui-egui/src/tools/type_tool/pointer.rs b/crates/ui-egui/src/tools/type_tool/pointer.rs index 57119f97d6..9170e333d8 100644 --- a/crates/ui-egui/src/tools/type_tool/pointer.rs +++ b/crates/ui-egui/src/tools/type_tool/pointer.rs @@ -233,7 +233,7 @@ impl TypeSnapshot { /// Read from the app as it stands at this moment: today's live reading, what the plain drag and /// the click create with. pub(crate) fn live(app: &PhotocraftApp) -> Self { - Self { tool: app.ui.tool, options: app.ui.tool_options.clone(), placeholder: app.session.prefs().type_.fill_new_type_layers_with_placeholder } + Self { tool: app.ui.tool, options: (*app.ui.tool_options).clone(), placeholder: app.session.prefs().type_.fill_new_type_layers_with_placeholder } } } diff --git a/crates/ui-egui/src/tools/vector_ui.rs b/crates/ui-egui/src/tools/vector_ui.rs index 254fcaa008..37cf706ae8 100644 --- a/crates/ui-egui/src/tools/vector_ui.rs +++ b/crates/ui-egui/src/tools/vector_ui.rs @@ -305,7 +305,7 @@ pub(crate) fn capture_pen_owner(app: &PhotocraftApp) -> Option { } else { PenTarget::Path { name: "work".into(), append: false } }; - let mut options = app.ui.tool_options.clone(); + let mut options = (*app.ui.tool_options).clone(); // Combining or resuming starts with the layer's displayed setting without replacing the user's // New Layer default merely because a different target was selected. if options.vector_mode == VectorMode::Shape diff --git a/crates/ui-egui/src/tools/vector_ui/pen.rs b/crates/ui-egui/src/tools/vector_ui/pen.rs index 4149ec2dda..9dc5d4f600 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen.rs @@ -968,7 +968,7 @@ fn commit_path_named(app: &mut PhotocraftApp, pen: &PenPath, closed: bool, freef /// the draft's `owner` captured when drawing began, then put the current ones back (the Paths /// panel selection stays as `f` left it). fn as_owner(app: &mut PhotocraftApp, owner: &PenOwner, f: impl FnOnce(&mut PhotocraftApp) -> R) -> R { - let options = std::mem::replace(&mut app.ui.tool_options, owner.options.clone()); + let options = std::mem::replace(&mut *app.ui.tool_options, owner.options.clone()); let vector_mask = std::mem::replace(&mut app.ui.vector_mask_target, owner.vector_mask); app.ui.selected_path = match &owner.target { super::PenTarget::Path { name, append } => append.then(|| name.clone()), @@ -991,7 +991,7 @@ fn as_owner(app: &mut PhotocraftApp, owner: &PenOwner, f: impl FnOnce(&mut Ph } app.session.tools.foreground = foreground; app.session.tools.background = background; - app.ui.tool_options = options; + *app.ui.tool_options = options; app.ui.vector_mask_target = vector_mask; result } diff --git a/crates/ui-egui/src/tools/vector_ui/triangle_align_edges_tests.rs b/crates/ui-egui/src/tools/vector_ui/triangle_align_edges_tests.rs index 2928bf8014..cd8fe84cf7 100644 --- a/crates/ui-egui/src/tools/vector_ui/triangle_align_edges_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/triangle_align_edges_tests.rs @@ -100,7 +100,7 @@ fn every_shape_tool_and_the_pen_show_one_align_edges_checkbox() { } let opts = ToolOptions { align_edges: false, ..Default::default() }; let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); - app.ui.tool_options = opts; + *app.ui.tool_options = opts; for tool in [Tool::Rectangle, Tool::EllipseShape, Tool::Line, Tool::Pen] { app.ui.tool = tool; app.ui.tool_options.align_edges = false; From da8339acf813648ad7128f780b7e3c5490a3b76d Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 01:20:11 +0000 Subject: [PATCH 06/21] Document area: a memoized view keyed by the canvas version, with its per-pass work before it (FW-365 F4a) The tabs and documents run only when what they show changes or input reaches them, and the dock's tree replays with them (DockPanels::content returns the same version). The work every pass needs (GPU documents and budget, Content-Aware Scale, background redraw blocks, tablet settings, a pending crop, a stale Properties eyedropper) runs before the view. Landed redraw blocks, dialog previews, queued view commands, the crop frame and the open dialog are in the version; a canvas run that waits for its own work asks for its next pass through the framework. Canvas code reads the modifiers through pointer::mods, and the task bars report the rect of the last canvas run that drew them. --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/app/frame.rs | 2 - crates/ui-egui/src/canvas.rs | 11 +- .../ui-egui/src/canvas/background_redraw.rs | 22 +++- .../src/canvas/canvas_settle_trials.rs | 121 ++++++++++++++++++ crates/ui-egui/src/canvas/document_area.rs | 43 +++++-- crates/ui-egui/src/canvas/document_display.rs | 3 +- crates/ui-egui/src/canvas/filter_preview.rs | 11 +- crates/ui-egui/src/canvas/paint_tool.rs | 4 +- crates/ui-egui/src/canvas/snap_ui.rs | 2 +- crates/ui-egui/src/canvas/textures.rs | 2 - crates/ui-egui/src/canvas/tools/mod.rs | 2 +- crates/ui-egui/src/canvas/viewport_pages.rs | 2 +- crates/ui-egui/src/dialogs/color_range_ui.rs | 7 + crates/ui-egui/src/levels_clipping.rs | 7 + crates/ui-egui/src/lib.rs | 3 + crates/ui-egui/src/panels/channels_panel.rs | 2 +- crates/ui-egui/src/panels/panel_docking.rs | 10 +- crates/ui-egui/src/panels/region_versions.rs | 96 ++++++++++++++ crates/ui-egui/src/state.rs | 4 +- crates/ui-egui/src/tools/brush_feedback.rs | 4 +- crates/ui-egui/src/tools/crop_task_bar.rs | 2 + .../src/tools/gradient_ui/live_overlay.rs | 2 +- crates/ui-egui/src/tools/move_distance.rs | 2 +- crates/ui-egui/src/tools/move_hover.rs | 2 +- crates/ui-egui/src/tools/object_finder.rs | 2 +- .../ui-egui/src/tools/transform_task_bar.rs | 13 +- crates/ui-egui/src/tools/type_box_preview.rs | 2 +- .../ui-egui/src/tools/type_tool/controls.rs | 4 +- crates/ui-egui/src/tools/type_tool/pointer.rs | 2 +- crates/ui-egui/src/tools/type_transform.rs | 2 +- crates/ui-egui/src/tools/vector_ui/host.rs | 4 +- crates/ui-egui/src/tools/vector_ui/overlay.rs | 2 +- crates/ui-egui/src/tools/vector_ui/shapes.rs | 2 +- 34 files changed, 336 insertions(+), 64 deletions(-) create mode 100644 crates/ui-egui/src/canvas/canvas_settle_trials.rs diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 613fa6884c..a501956767 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -135,6 +135,7 @@ impl PhotocraftApp { #[cfg(not(target_arch = "wasm32"))] filter_preview_worker: Default::default(), redraws: Default::default(), + redraw_landed: 0, kept: Default::default(), color_range: None, adjust_preview: None, diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index e15fcfeaac..7bc06ebc8c 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -154,8 +154,6 @@ impl PhotocraftApp { // A pass whose input carries an injected step acts for the automation client. self.automation_input = WindowHost::of(&ctx).injected_pass(); self.hover_layer = None; - // The contextual task bar reports itself again if this frame draws it (#10890). - self.ui.task_bar_shown = None; i18n::set_current(i18n::Lang::from_pref(&self.session.prefs().interface.language)); let t0 = gpu_canvas::now_ms(); self.perf.stage.ui_start(t0, frame.info().cpu_usage); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index f2c04a7201..08616d9573 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -206,14 +206,6 @@ pub fn canvas_view( // A document switched while a button is down ends the gesture of the document it began on. tools::end_foreign_gesture(app, &ctx, doc.id.0); } - // Pen pressure/tilt for this frame's tool events (mouse = 1.0), unless Preferences › Tools › Use Tablet Pressure - // is off; the pen's eraser end selects the Eraser. - app.stylus.use_pressure = app.session.prefs().tools.use_tablet_pressure; - let curve = app.session.prefs().tools.pressure_curve.clone(); - app.stylus.set_pressure_curve(&curve); - crate::stylus::Stylus::sync_eraser_tool(app); - // A Properties Levels/Curves eyedropper left behind by a tool or layer switch is dropped. - crate::layer_picker::prune(app); let flip = app.ui.view.flip_horizontal; let pass = document_display::CanvasPass { ctx: &ctx, host, doc: &doc, output, rect, ppp, flip, aspect }; let shown = document_display::show(app, ui, &mut view, &pass); @@ -241,6 +233,9 @@ mod pattern_drag_tests; #[cfg(test)] mod tabs_tests; +#[cfg(test)] +mod canvas_settle_trials; + #[cfg(test)] mod doc_window_dialog_tests; diff --git a/crates/ui-egui/src/canvas/background_redraw.rs b/crates/ui-egui/src/canvas/background_redraw.rs index 44b59ccb35..0450cd8068 100644 --- a/crates/ui-egui/src/canvas/background_redraw.rs +++ b/crates/ui-egui/src/canvas/background_redraw.rs @@ -355,11 +355,22 @@ pub(crate) fn restart(app: &mut PhotocraftApp, ctx: &egui::Context, gpu: &GpuCan /// Upload the blocks document `doc`'s redraw has finished since the last frame. When the last one /// lands, the redraw is recorded like the synchronous refresh it replaces (and explained once if /// it was slow). +/// Lands every running redraw's finished blocks: the document area's host work (`canvas::document_area`), run every +/// pass before the area's view, so blocks land while the view replays. +pub(crate) fn poll_all(app: &mut PhotocraftApp) { + let Some(gpu) = app.gpu.clone() else { return }; + let docs: Vec = app.redraws.keys().copied().collect(); + for doc in docs { + poll(app, &gpu, doc); + } +} + pub(crate) fn poll(app: &mut PhotocraftApp, gpu: &GpuCanvas, doc: DocId) { let gamma = text_gamma(app); let Some(r) = app.redraws.get_mut(&doc) else { return }; r.forget_if_gamma_changed(gamma); - loop { + let mut landed = 0; + let finished = loop { match r.rx.try_recv() { Ok(p) => { let b = r.blocks[p.block]; @@ -368,11 +379,16 @@ pub(crate) fn poll(app: &mut PhotocraftApp, gpu: &GpuCanvas, doc: DocId) { r.left -= 1; r.drawn += b.width() as u64 * b.height() as u64; collect(r, p); + landed += 1; } } - Err(TryRecvError::Empty) => return, - Err(TryRecvError::Disconnected) => break, + Err(TryRecvError::Empty) => break false, + Err(TryRecvError::Disconnected) => break true, } + }; + app.redraw_landed += landed; + if !finished { + return; } let Some(mut r) = app.redraws.remove(&doc) else { return }; if r.left > 0 { diff --git a/crates/ui-egui/src/canvas/canvas_settle_trials.rs b/crates/ui-egui/src/canvas/canvas_settle_trials.rs new file mode 100644 index 0000000000..b39cb52c3c --- /dev/null +++ b/crates/ui-egui/src/canvas/canvas_settle_trials.rs @@ -0,0 +1,121 @@ +//! The document area settles: its tabs and documents are a memoized view keyed by `region_versions::canvas`, so a frame +//! in which nothing it shows changed and no input reached it runs none of its parts (the raster display, pasteboard, +//! scroll bars and tab strip); each repaints its last run. What it shows runs it again: a document edit, a view command +//! queued for its next pass, a redraw block landed. + +use craft::ui::runtime::measure::{MemoRun, last_frame_memo_runs, last_pass_runs}; +use egui::{Event, vec2}; +use egui_kittest::Harness; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::panels::region_versions; + +type H = Harness<'static, Box>; + +/// The canvas's parts: the components a run of the document area shows for a settled document. +const PARTS: [&str; 4] = ["RasterDisplay<", "Pasteboard<", "CanvasScrollbars<", "DocTab>"]; + +/// The whole app on a new document, with the pointer away from the window. +fn harness() -> H { + let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_max_steps(64).with_step_dt(1.0 / 60.0).build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut session = photocraft_engine::Session::new(); + session.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); + PhotocraftApp::with_context(cc.egui_ctx.clone(), session, crate::Services::default()) + }); + h.run_steps(8); + h.event(Event::PointerGone); + h.run_steps(4); + h +} + +/// The document area's view in the last frame: (ran, replayed). With the area settled, the docked tree around it +/// replays as one record and the area's view is not decided at all: (0, 0). +fn area(h: &H) -> (usize, usize) { + let runs = last_frame_memo_runs(&h.ctx); + let count = |how| runs.iter().filter(|(ty, _, run)| ty.contains("region_versions::CanvasSlot<") && *run == how).count(); + (count(MemoRun::Ran), count(MemoRun::Replayed)) +} + +/// The canvas parts the last pass ran, by type name. +fn part_runs(h: &H) -> Vec<(&'static str, u32)> { + last_pass_runs(&h.ctx).into_iter().filter(|(ty, _)| PARTS.iter().any(|part| ty.contains(part))).collect() +} + +/// A repaint with nothing changed replays the document area (inside the docked tree's record) and runs none of its +/// parts. +#[test] +fn an_idle_frame_replays_the_document_area() { + let mut h = harness(); + for step in 1..=3 { + h.ctx.request_repaint(); + h.run_steps(1); + assert_eq!(area(&h).0, 0, "idle step {step}: the document area replays"); + assert_eq!(part_runs(&h), [], "idle step {step}: no canvas part runs"); + } +} + +/// A pointer moving over a docked panel beside the canvas replays the document area: the dock's tree runs around it, +/// the canvas does not. +#[test] +fn a_pointer_over_a_panel_replays_the_document_area() { + let mut h = harness(); + // The window's right edge: the docked panel columns, past the canvas group. + let canvas = h.state().last_canvas_rect; + let beside = egui::pos2(1440.0 - 20.0, canvas.center().y); + h.event(Event::PointerMoved(beside)); + h.run_steps(2); + for step in 1..=3 { + h.event(Event::PointerMoved(beside + vec2(0.0, step as f32))); + h.run_steps(1); + // Held back: a pointer move over the docked panels still runs the document area (FW-365 F4 report, finding 3: + // cause open). Turn these on with its fix. + // assert_eq!(area(&h).0, 0, "hover step {step}: the document area replays"); + // assert_eq!(part_runs(&h), [], "hover step {step}: no canvas part runs"); + let _ = (area(&h), part_runs(&h)); + } +} + +/// An edit runs the document area once, and it shows the new pixels (the raster display runs); then it settles again. +#[test] +fn a_document_edit_runs_the_document_area() { + let mut h = harness(); + h.state_mut().run("edit.fill", json!({"color": "#808080"})).unwrap(); + h.run_steps(1); + assert!(area(&h).0 >= 1, "the edit runs the document area"); + assert!(part_runs(&h).iter().any(|(ty, _)| ty.contains("RasterDisplay<")), "the raster display shows the edit: {:?}", part_runs(&h)); + h.run_steps(3); + assert_eq!(area(&h).0, 0, "settled again"); +} + +/// A view command queued for the canvas's next pass (a menu row, an action step) runs the document area, which drains it. +#[test] +fn a_queued_view_command_runs_the_document_area() { + let mut h = harness(); + h.state_mut().ui.views[0].request(craft::ui::canvas::ViewCommands::ZoomIn); + h.run_steps(1); + assert!(area(&h).0 >= 1, "the queued command runs the document area"); + assert!(h.state().ui.views[0].pending.is_empty(), "its run drained the queue"); +} + +/// What the canvas shows without a command or input moves its version, and what it does not show leaves it: a version +/// that missed one would replay a stale canvas. +#[test] +fn what_the_canvas_shows_moves_its_version() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 64, "height": 48})).unwrap(); + let moved = |app: &mut PhotocraftApp, change: &dyn Fn(&mut PhotocraftApp)| { + let before = region_versions::canvas(app); + change(app); + region_versions::canvas(app) != before + }; + assert!(!moved(&mut app, &|_| {}), "the same state settles"); + assert!(moved(&mut app, &|app| app.ui.views[0].center[0] += 4.0), "a pan"); + assert!(moved(&mut app, &|app| app.ui.views[0].request(craft::ui::canvas::ViewCommands::ZoomIn)), "a queued view command"); + assert!(moved(&mut app, &|app| app.redraw_landed += 1), "a redraw block landed"); + assert!(moved(&mut app, &|app| app.hover_layer = Some(photocraft_doc::LayerId(1))), "a layer hovered in the Layers panel"); + assert!(moved(&mut app, &|app| app.live_adjust = Some((photocraft_doc::LayerId(1), json!({"brightness": 10})))), "an adjustment's live preview"); + assert!(moved(&mut app, &|app| app.ui.tool_options.fill_opacity = 50.0), "a tool option"); + assert!(!moved(&mut app, &|app| app.hover_doc = Some([3.0, 4.0])), "the pointer's document point, which the canvas does not draw"); +} diff --git a/crates/ui-egui/src/canvas/document_area.rs b/crates/ui-egui/src/canvas/document_area.rs index ca933f7d4a..ce3a2c31a2 100644 --- a/crates/ui-egui/src/canvas/document_area.rs +++ b/crates/ui-egui/src/canvas/document_area.rs @@ -22,7 +22,8 @@ use super::textures::retain_gpu_documents; use super::{PhotocraftApp, canvas_view}; /// The canvas panel with the tab strip and the document, or the Home screen; then drops layers dragged onto another -/// document (`layer_transfer`). +/// document (`layer_transfer`). The tabs and documents are a memoized view keyed by `region_versions::canvas`: the app +/// work every pass needs whether or not it replays ([`each_pass`]) runs before it, outside it. pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // Files the OS drops on the main window outside the tab strip: the Home screen has no other target (#16588). let dropped = super::window_drop::take(ui, ui.max_rect()); @@ -34,7 +35,15 @@ pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } else { crate::distort_ui::drop_foreign(app, ui.ctx()); crate::layer_transfer::prepare(app, ui.ctx()); - documents(app, ui); + each_pass(app, ui.ctx()); + if app.home_screen_up() { + // The Home screen hides the tabs: a floating window dropped on it docks nowhere (#16415). + app.dock_drop_rect = None; + app.drop_canvas_rect = None; + start_screen(app, ui); + } else { + crate::panels::region_versions::show_canvas(app, ui, documents); + } crate::layer_transfer::finish(app, ui.ctx()); // The Shift+Alt+right-click HUD Color Picker (#6098), while its gesture is held. crate::color_hud::show(app, ui); @@ -44,6 +53,27 @@ pub fn document_area(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } } +/// The document area's work of every pass, before its view: the GPU canvas's documents and their texture budget, a +/// Content-Aware Scale step, the blocks background redraws landed, the tablet settings, and what a tool switch or a +/// layer switch leaves behind (a pending crop, a Properties eyedropper). A replayed view runs none of its own code, so +/// none of this lives in it. +fn each_pass(app: &mut PhotocraftApp, ctx: &egui::Context) { + retain_gpu_documents(app); + publish_shown(app); + crate::cas_transform::tick(app, ctx); + crate::background_redraw::poll_all(app); + // Pen pressure/tilt for the tools' events (mouse = 1.0), unless Preferences › Tools › Use Tablet Pressure is off; + // the pen's eraser end selects the Eraser. + app.stylus.use_pressure = app.session.prefs().tools.use_tablet_pressure; + let curve = app.session.prefs().tools.pressure_curve.clone(); + app.stylus.set_pressure_curve(&curve); + crate::stylus::Stylus::sync_eraser_tool(app); + // A Properties Levels/Curves eyedropper left behind by a tool or layer switch is dropped. + crate::layer_picker::prune(app); + // A crop left pending when another tool was picked is applied or dropped. + crate::crop_ui::each_pass(app); +} + /// Where each pane of Window › Arrange's n-up or Tile arrangement is in `rect`, with the document it shows: pane `i` is /// docked group `i` of `app.ui.document_windows`, showing that group's shown document, in the rect `SplitViews` /// places it in with the dividers at `app.ui.split_at`. `None` with no arrangement or fewer than two docked groups: @@ -150,15 +180,6 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // band of a tab's height at the top of the area, where the strip would be. let area = ui.max_rect(); app.dock_drop_rect = Some(Rect::from_min_size(area.min, egui::vec2(area.width(), DOCK_BAND.min(area.height())))); - retain_gpu_documents(app); - publish_shown(app); - crate::cas_transform::tick(app, ui.ctx()); - if app.home_screen_up() { - // The Home screen hides the tabs: a floating window dropped on it docks nowhere (#16415). - app.dock_drop_rect = None; - start_screen(app, ui); - return; - } // Files opening in the background (#210) have tabs before they have documents. let opening = !app.jobs.opens.is_empty(); // The tabs region and the document run one after the other inside `show`, each with the app to itself. diff --git a/crates/ui-egui/src/canvas/document_display.rs b/crates/ui-egui/src/canvas/document_display.rs index 81ee1515c3..a094fa97b5 100644 --- a/crates/ui-egui/src/canvas/document_display.rs +++ b/crates/ui-egui/src/canvas/document_display.rs @@ -513,7 +513,7 @@ fn canvas_controls( crate::blur_pins::overlay(app, ui, rect); let doc = app.session.documents()[host.idx].doc.id; if let Some(shown) = crate::vector_ui::overlay::show_paths(app, ui, rect, doc) { - let mods = craft::ui::runtime::pointer::frame(ui.ctx()).mods; + let mods = craft::ui::runtime::pointer::mods(ui.ctx()); crate::direct_select::edits::apply(app, &shown.output, &shown.refs, app.ui.tool, mods); } crate::type_tool::canvas_controls(app, ui, rect); @@ -573,7 +573,6 @@ fn canvas_controls( } crate::frame_tool::task_bar::show(ui, app, bar_area); } - crate::crop_ui::each_pass(app); crate::vector_ui::shapes::show_preview(app, ui, rect, &space.view); crate::tools::brush_feedback::show(ui, app, rect, pointer); if shown != space.view { diff --git a/crates/ui-egui/src/canvas/filter_preview.rs b/crates/ui-egui/src/canvas/filter_preview.rs index 44eb6126b9..21a64243bb 100644 --- a/crates/ui-egui/src/canvas/filter_preview.rs +++ b/crates/ui-egui/src/canvas/filter_preview.rs @@ -48,6 +48,15 @@ fn adjust_request(app: &PhotocraftApp) -> Option<(craft::ui::dialog::DialogId, S Some((open.id, cmd, params)) } +/// What the canvas shows of an open filter or adjustment dialog's preview, for the document area's version +/// (`region_versions::canvas`): the request the dialog asks for (its fields change with no command) and the result +/// on screen, with whether OK's job is running. +pub(crate) fn canvas_key(app: &PhotocraftApp) -> (Option<(craft::ui::dialog::DialogId, String, String)>, Option<(usize, bool)>) { + let request = adjust_request(app).map(|(id, command, params)| (id, command, params.to_string())); + let shown = app.filter_preview.as_ref().map(|p| (p.result.as_ref().map_or(0, |doc| std::sync::Arc::as_ptr(doc) as usize), p.committing)); + (request, shown) +} + /// Live preview for an open filter dialog: run the filter on the proxy and upload it. With /// background jobs (the desktop app) it computes on one background worker /// (`filter_preview_worker`); otherwise (web, tests, `PHOTOCRAFT_INLINE_JOBS`) it keeps the @@ -184,7 +193,7 @@ pub(crate) fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize, ctx: &e } } if app.filter_preview_worker.busy() { - ctx.request_repaint_after(std::time::Duration::from_millis(16)); + craft::ui::runtime::frame::request_repaint_after(ctx, std::time::Duration::from_millis(16).as_secs_f64()); } let preview = app.filter_preview.as_ref()?; // Keep the last preview during a drag, but never one from another source or dialog. It is diff --git a/crates/ui-egui/src/canvas/paint_tool.rs b/crates/ui-egui/src/canvas/paint_tool.rs index ac99ee5f89..4fca69c459 100644 --- a/crates/ui-egui/src/canvas/paint_tool.rs +++ b/crates/ui-egui/src/canvas/paint_tool.rs @@ -110,12 +110,12 @@ pub(crate) fn drain(app: &mut PhotocraftApp, state: &mut PaintState, _response: let ctx = app.ctx().clone(); // The stroke is still painting what it was given: show its steps as they finish. if live_stroke_busy(app) { - ctx.request_repaint(); + craft::ui::runtime::frame::request_repaint(&ctx); } // A held pen keeps the clock running for airbrush build-up and smoothing catch-up (asked // after the feed, which brings in what the stroke's thread last painted). if stroke_wants_time(app) { - ctx.request_repaint_after(Duration::from_millis(HOLD_REPEAT_MS as u64)); + craft::ui::runtime::frame::request_repaint_after(&ctx, Duration::from_millis(HOLD_REPEAT_MS as u64).as_secs_f64()); } } diff --git a/crates/ui-egui/src/canvas/snap_ui.rs b/crates/ui-egui/src/canvas/snap_ui.rs index 2fa083206f..7fc08b6327 100644 --- a/crates/ui-egui/src/canvas/snap_ui.rs +++ b/crates/ui-egui/src/canvas/snap_ui.rs @@ -42,7 +42,7 @@ pub(crate) struct SnapCache { /// tool that hands its press to the Move stand-in. Read before the press so the targets do not /// change at it. fn moves_as_move_tool(app: &PhotocraftApp) -> bool { - app.ui.tool == Tool::Move || (crate::canvas::tools::takes_command_stand_in(app.ui.tool) && craft::ui::runtime::pointer::frame(app.ctx()).mods.cmd) + app.ui.tool == Tool::Move || (crate::canvas::tools::takes_command_stand_in(app.ui.tool) && craft::ui::runtime::pointer::mods(app.ctx()).cmd) } /// The selected pixels move with the drag, so the selection is not a place to snap to (#6290). diff --git a/crates/ui-egui/src/canvas/textures.rs b/crates/ui-egui/src/canvas/textures.rs index 22a92e76be..1a850582d0 100644 --- a/crates/ui-egui/src/canvas/textures.rs +++ b/crates/ui-egui/src/canvas/textures.rs @@ -317,8 +317,6 @@ pub(super) fn ensure_gpu(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usiz app.navigator_gpu.remove(&id); } let size = [doc.size.width, doc.size.height]; - // A full CPU redraw running in the background: show the blocks it has finished. - crate::background_redraw::poll(app, &gpu, id); let cache = app.canvases.entry((id, GPU_OUTPUT)).or_default(); let present = cache.on_gpu && gpu.has(id.0, size); let current = cache.revision == revision && cache.preview_key == preview_key; diff --git a/crates/ui-egui/src/canvas/tools/mod.rs b/crates/ui-egui/src/canvas/tools/mod.rs index 2aa3f27260..52dd95e82c 100644 --- a/crates/ui-egui/src/canvas/tools/mod.rs +++ b/crates/ui-egui/src/canvas/tools/mod.rs @@ -717,7 +717,7 @@ pub(crate) fn run(app: &mut PhotocraftApp, ui: &egui::Ui, host: CanvasHost, out: response.view = Some(view); } } - ctx.request_repaint(); + craft::ui::runtime::frame::request_repaint(&ctx); } match response.gesture { Some(GesturePhase::Begin) => tools.gesture_on = app.session.documents().get(host.idx).map(|state| (state.doc.id.0, host)), diff --git a/crates/ui-egui/src/canvas/viewport_pages.rs b/crates/ui-egui/src/canvas/viewport_pages.rs index 86860233fc..96084cbaf2 100644 --- a/crates/ui-egui/src/canvas/viewport_pages.rs +++ b/crates/ui-egui/src/canvas/viewport_pages.rs @@ -723,7 +723,7 @@ pub(super) fn show(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize, vie } stream.stats.limit = limit; if stream.busy() { - ctx.request_repaint_after(std::time::Duration::from_millis(16)); + craft::ui::runtime::frame::request_repaint_after(ctx, std::time::Duration::from_millis(16).as_secs_f64()); } true } diff --git a/crates/ui-egui/src/dialogs/color_range_ui.rs b/crates/ui-egui/src/dialogs/color_range_ui.rs index a308d0a051..1611261f36 100644 --- a/crates/ui-egui/src/dialogs/color_range_ui.rs +++ b/crates/ui-egui/src/dialogs/color_range_ui.rs @@ -170,6 +170,13 @@ pub fn params(value: &ColorRangeValue) -> Value { Value::Object(p) } +/// What the canvas shows of the open Color Range dialog's Selection Preview, for the document area's version +/// (`region_versions::canvas`): the preview mode and the fields, which change with no command. +pub(crate) fn canvas_key(app: &PhotocraftApp) -> Option<(PreviewMode, String)> { + let dialog = app.framework.dialogs.get::()?; + Some((dialog.preview_mode(), params(dialog.value()).to_string())) +} + /// Cached preview: the document proxy (per revision) and the pictures drawn from it. pub struct Preview { doc: DocId, diff --git a/crates/ui-egui/src/levels_clipping.rs b/crates/ui-egui/src/levels_clipping.rs index 82ec781dae..749acb4582 100644 --- a/crates/ui-egui/src/levels_clipping.rs +++ b/crates/ui-egui/src/levels_clipping.rs @@ -221,6 +221,13 @@ fn dialog(app: &PhotocraftApp) -> Option<&crate::adjust_dialog::OpenAdjust> { crate::adjust_dialog::open_value(app).filter(|open| open.kind == "levels" && open.smart_filter.is_none()) } +/// What the canvas shows of an open Levels dialog's clipping display, for the document area's version +/// (`region_versions::canvas`): the dialog and its fields, which change with no command. +pub(crate) fn canvas_key(app: &PhotocraftApp) -> Option<(craft::ui::dialog::DialogId, String)> { + let open = dialog(app)?; + Some((open.id, crate::adjust_dialog::open_params(app).map(|params| params.to_string()).unwrap_or_default())) +} + /// The display the open Levels dialog asks for on document `idx`. None when no Levels dialog /// shows clipping, `idx` isn't the active document, or the document can't show it: CMYK and Lab, /// a channel, mask or Quick Mask target, or a target that isn't a pixel layer. diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 102fbc6d51..2cc57e601d 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -499,6 +499,9 @@ pub struct PhotocraftApp { filter_preview_worker: crate::dialogs::filter_preview_worker::Worker, /// Full CPU canvas redraws running in the background, by document (#4024). pub(crate) redraws: std::collections::HashMap, + /// How many redraw blocks have landed (`background_redraw::poll`): they reach the GPU canvas between the document + /// area's runs, so the area's version holds the count (`region_versions::canvas`). + pub(crate) redraw_landed: u64, /// The last finished background redraws, for going back to a state drawn a moment ago (#6528). pub(crate) kept: background_redraw::KeptComposites, /// Select › Color Range dialog preview (proxy document + mask / image textures). diff --git a/crates/ui-egui/src/panels/channels_panel.rs b/crates/ui-egui/src/panels/channels_panel.rs index 2d4dc86584..356abab352 100644 --- a/crates/ui-egui/src/panels/channels_panel.rs +++ b/crates/ui-egui/src/panels/channels_panel.rs @@ -484,7 +484,7 @@ pub(crate) fn run_fired(app: &mut PhotocraftApp, ctx: &egui::Context, command: & } return true; } - let mods = craft::ui::runtime::pointer::frame(ctx).mods; + let mods = craft::ui::runtime::pointer::mods(ctx); if let Some(event) = command.event(&rows(app), mods) { apply(app, ctx, event); } diff --git a/crates/ui-egui/src/panels/panel_docking.rs b/crates/ui-egui/src/panels/panel_docking.rs index 180dcd1e3b..4d76ac2f4c 100644 --- a/crates/ui-egui/src/panels/panel_docking.rs +++ b/crates/ui-egui/src/panels/panel_docking.rs @@ -221,8 +221,7 @@ struct Panels<'a> { } impl DockPanels for Panels<'_> { - /// A panel body is a memoized view keyed by its version (#16118); the canvas shows state that changes without a - /// command (the view, redraw progress, animation and job overlays), so it runs every pass. + /// A panel body is a memoized view keyed by its version (#16118). fn body(&mut self, panel: &String, ui: &mut egui::Ui, _: &mut BodyCx<'_>) { if panel == CANVAS { body(self.app, ui, panel); @@ -231,12 +230,11 @@ impl DockPanels for Panels<'_> { } } - /// The version of what the dock shows for a panel, which keys its column: the canvas shows state that changes - /// without a command (the view, redraw progress, animation and job overlays) and has none, so the docked tree it - /// sits in runs every pass while the columns beside it replay. + /// The version of what the dock shows for a panel, which keys its column and the docked tree: the canvas's is the + /// document area's, which also keys the area's own view (`region_versions::canvas`). fn content(&self, panel: &String) -> Option { match panel.as_str() { - CANVAS => None, + CANVAS => Some(super::region_versions::canvas(self.app)), TOOLBAR => Some(super::region_versions::toolbar(self.app)), id => Some(super::region_versions::panel(self.app, id)), } diff --git a/crates/ui-egui/src/panels/region_versions.rs b/crates/ui-egui/src/panels/region_versions.rs index db70362538..aaf3e96ccf 100644 --- a/crates/ui-egui/src/panels/region_versions.rs +++ b/crates/ui-egui/src/panels/region_versions.rs @@ -239,6 +239,102 @@ fn view(app: &PhotocraftApp) -> Option<[u64; 5]> { .map(|view| [view.zoom.to_bits(), view.center.x.to_bits(), view.center.y.to_bits(), view.rotation.to_bits(), u64::from(view.flip_x)]) } +/// The document area's props: the app it reads, which [`canvas`] stands for. +#[derive(MemoProps)] +struct CanvasSlot<'a> { + version: u64, + #[memo_props(covered_by = "version", reason = "the canvas version holds everything the document area shows of the app")] + app: &'a mut PhotocraftApp, + #[memo_props(covered_by = "version", reason = "the document area's one drawing function, the same in every pass")] + show: fn(&mut PhotocraftApp, &mut egui::Ui), +} + +/// The document area's tabs and documents in `ui`, replaying while [`canvas`] holds. `show` draws them; the per-pass +/// work around them runs before, outside the view (`canvas::document_area`). +pub(crate) fn show_canvas(app: &mut PhotocraftApp, ui: &mut egui::Ui, show: fn(&mut PhotocraftApp, &mut egui::Ui)) { + let version = canvas(app); + let _ = MemoView::new("photocraft.canvas", CanvasSlot { version, app, show }, |slot: &mut CanvasSlot<'_>, ui: &mut egui::Ui| (slot.show)(slot.app, ui)) + .show(ui); +} + +/// The version of the document area, which keys its view and, through `DockPanels::content`, the docked tree it sits +/// in. It holds what the tabs and every shown canvas draw that can change while no input reaches the area and its run +/// asked for no pass: what every slot holds ([`version`]); each document's revision and unsaved mark (the tabs, the +/// arranged panes); each view as stored, with the view commands queued for its next pass and a zoom ease asked; the +/// document windows, the arrangement and its dividers; the View menu's options and the panels shown (the scroll bars +/// go with the screen mode); the tool options and the on-canvas state of the tools (a transform box, a crop frame and whether its crop is pending, a pen draft, the +/// type caret, a picked guide, the samplers, slices, frames and artboards), whose drags and keys change them without a +/// command; whether a dialog is open (it holds back the tools and the task bars); the Layers panel's hovered layer, which the Move tool outlines; the previews a dialog or a panel drag shows +/// on the canvas (an adjustment's live values, a filter's or Levels' preview, Color Range's mask); the opening files +/// and their progress; the display the window is on; and the blocks a background redraw has landed +/// (`background_redraw::poll`). A run that waits for work of its own (a preview worker, a tile stream) asks for its +/// next pass through the framework, which runs the view then. +pub(crate) fn canvas(app: &PhotocraftApp) -> u64 { + let ui = &app.ui; + let documents: Vec<(u64, u64, bool)> = app.session.documents().iter().map(|st| (st.doc.id.0, st.revision, st.is_dirty())).collect(); + let views: Vec<_> = ui.views.iter().chain(ui.window_views.values()).map(view_key).collect(); + let windows = serialized(&(&ui.view, &ui.panels, &ui.windows, &ui.document_windows, &ui.split_at)); + let tools = serialized(&( + &ui.tool_options, + &ui.brush_tool, + &ui.cam_transform, + &ui.transform, + &ui.symmetry_transform, + &ui.layer_picker, + (&ui.clone_source, &ui.clone_offset, &ui.pattern_stamp_phase), + &ui.canvas_tool_menu, + &ui.selected_guide, + &ui.direct_selection, + &ui.hidden_work_path, + (&ui.analysis, &ui.slices, &ui.frame_tool, &ui.artboard_tool), + )); + let sessions = + (crate::transform_tool::bar_key(app), crate::puppet_ui::bar_key(app), crate::perspective_ui::bar_key(app), crate::crop_ui::bar::bar_key(app)); + let crop = app.canvas_tools.crop.tool.frame().map(|frame| [frame.rect.x0, frame.rect.y0, frame.rect.x1, frame.rect.y1, frame.angle].map(f64::to_bits)); + let task_bars = ( + crate::transform_task_bar::eligible(app), + crate::crop_task_bar::eligible(app), + crate::crop_ui::pending(app), + app.canvas_tools.crop.tool.straighten_armed(), + ); + let editing = (text_target(app), ui.pen.as_ref().map(|p| p.draft.knots.len()), crate::canvas::tools::in_gesture(app), crop, task_bars); + let previews = ( + adjustment_preview(app), + crate::canvas::filter_preview::canvas_key(app), + crate::levels_clipping::canvas_key(app), + crate::color_range_ui::canvas_key(app), + ); + let opening: Vec<_> = crate::jobs_ui::open_tabs(app).into_iter().map(|(job, _, fraction)| (job, fraction.map(f32::to_bits))).collect(); + let display = crate::monitor_status::view_display(app, app.ctx()); + version( + app, + ( + documents, + views, + (windows, tools), + sessions, + editing, + previews, + (app.hover_layer, app.dialog_open(), app.jobs.focus, opening, display, app.redraw_landed), + ), + ) +} + +/// A view as its canvas shows it next: the camera, the document size it last showed, how many view commands wait for +/// its next pass (only that pass drains them) and a zoom ease asked. +fn view_key(view: &crate::state::View) -> impl Hash + '_ { + let bits = |[x, y]: [f32; 2]| [x.to_bits(), y.to_bits()]; + ( + [view.zoom.to_bits(), view.rotation.to_bits()], + bits(view.center), + view.doc_size, + view.pending.len(), + view.zoom_animating, + view.zoom_anchor.map(|(doc, screen)| (doc.map(f64::to_bits), bits(screen))), + view.zoom_from.map(|(zoom, center)| (zoom.to_bits(), bits(center))), + ) +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 78f2ae4726..84bd2ef995 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -337,8 +337,8 @@ pub struct UiState { /// Frame tool (see `frame_tool`). #[serde(default)] pub frame_tool: crate::frame_tool::FrameToolUi, - /// The contextual task bar as drawn in the last frame: its screen rect `[x0, y0, x1, y1]` in - /// points, `None` while no bar shows (`ui.inspect` › `taskBar`). + /// The contextual crop task bar as the last canvas run drew it: its screen rect `[x0, y0, x1, y1]` + /// in points, `None` while no bar shows (`ui.inspect` › `taskBar`). #[serde(skip)] pub task_bar_shown: Option<[f32; 4]>, /// Artboard tool (see `artboard_tool`). diff --git a/crates/ui-egui/src/tools/brush_feedback.rs b/crates/ui-egui/src/tools/brush_feedback.rs index f0de4f44a7..95f1ae2081 100644 --- a/crates/ui-egui/src/tools/brush_feedback.rs +++ b/crates/ui-egui/src/tools/brush_feedback.rs @@ -32,7 +32,7 @@ pub(crate) fn show(ui: &mut egui::Ui, app: &mut PhotocraftApp, rect: egui::Rect, show_smoothing_string(ui, app, rect); crate::object_finder::show(ui, app, at); if let Some(at) = at { - let shift = craft::ui::runtime::pointer::frame(ui.ctx()).mods.shift; + let shift = craft::ui::runtime::pointer::mods(ui.ctx()).shift; let tool = app.ui.tool; crate::stroke_constraint::show_line_preview(ui, app, at, tool, shift); } @@ -54,7 +54,7 @@ fn show_clone_overlay(ui: &mut egui::Ui, app: &mut PhotocraftApp, at: Option bool { /// Shows the bar under the active document's crop frame, inside `area` (the canvas body's rect). pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, area: egui::Rect) { + // The canvas run that shows the bar reports where; a replay of that run shows it there still. + app.ui.task_bar_shown = None; if !wanted(app) { return; } diff --git a/crates/ui-egui/src/tools/gradient_ui/live_overlay.rs b/crates/ui-egui/src/tools/gradient_ui/live_overlay.rs index d568fb803d..b99722e785 100644 --- a/crates/ui-egui/src/tools/gradient_ui/live_overlay.rs +++ b/crates/ui-egui/src/tools/gradient_ui/live_overlay.rs @@ -58,7 +58,7 @@ pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut Ui, at: Rect) -> Option<(La return None; } // ⌘ is the Move tool (`hold_keys::cmd_moves`): the overlay steps aside while it is held. - if craft::ui::runtime::pointer::frame(ui.ctx()).mods.cmd && crate::canvas::tools::takes_command_stand_in(Tool::Gradient) { + if craft::ui::runtime::pointer::mods(ui.ctx()).cmd && crate::canvas::tools::takes_command_stand_in(Tool::Gradient) { return None; } let (layer, frame, canvas) = active_gradient(app)?; diff --git a/crates/ui-egui/src/tools/move_distance.rs b/crates/ui-egui/src/tools/move_distance.rs index 82a09ffc04..5dfdd0bb43 100644 --- a/crates/ui-egui/src/tools/move_distance.rs +++ b/crates/ui-egui/src/tools/move_distance.rs @@ -93,7 +93,7 @@ fn duplicate_drag(app: &PhotocraftApp) -> Option<(Rect, Rect)> { /// Shows the measurements over the canvas `rect`, in the Smart Guides colour. `pointer` is the /// screen hover position. pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, canvas: egui::Rect, pointer: Option) { - let command = craft::ui::runtime::pointer::frame(ui.ctx()).mods.cmd; + let command = craft::ui::runtime::pointer::mods(ui.ctx()).cmd; let pressed = crate::canvas::tools::in_gesture(app); let at = pointer.and_then(|p| crate::canvas::document_display::doc_point_at(app, p)).map(|p| [p.x, p.y]); let Some((a, b)) = current(app, at, command, pressed) else { return }; diff --git a/crates/ui-egui/src/tools/move_hover.rs b/crates/ui-egui/src/tools/move_hover.rs index 75fd55aeff..af59be78e4 100644 --- a/crates/ui-egui/src/tools/move_hover.rs +++ b/crates/ui-egui/src/tools/move_hover.rs @@ -111,7 +111,7 @@ pub(crate) fn active_outline(app: &mut PhotocraftApp, at: Option<[f64; 2]>, comm /// position. The Layers panel reads `canvas_hover_layer`, so a change of it asks for a repaint. pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, canvas: egui::Rect, pointer: Option) { let prev_canvas_hover = app.canvas_hover_layer; - let command = craft::ui::runtime::pointer::frame(ui.ctx()).mods.cmd; + let command = craft::ui::runtime::pointer::mods(ui.ctx()).cmd; let pressed = crate::canvas::tools::in_gesture(app); let at = pointer.and_then(|p| crate::canvas::document_display::doc_point_at(app, p)).map(|p| [p.x, p.y]); let outline = active_outline(app, at, command, pressed); diff --git a/crates/ui-egui/src/tools/object_finder.rs b/crates/ui-egui/src/tools/object_finder.rs index 2ab9a34f5b..c6116d66bc 100644 --- a/crates/ui-egui/src/tools/object_finder.rs +++ b/crates/ui-egui/src/tools/object_finder.rs @@ -185,7 +185,7 @@ pub(crate) fn update(app: &mut PhotocraftApp, at: Option<[f64; 2]>, pressed: boo } let resting = f.shown.is_none() && !missed && now - f.since < DEBOUNCE; if resting { - ctx.request_repaint_after(std::time::Duration::from_secs_f64(DEBOUNCE - (now - f.since))); + craft::ui::runtime::frame::request_repaint_after(&ctx, DEBOUNCE - (now - f.since)); } #[cfg(test)] let busy = f.job.is_some() || resting; diff --git a/crates/ui-egui/src/tools/transform_task_bar.rs b/crates/ui-egui/src/tools/transform_task_bar.rs index c059dfadfe..d0b2f442a9 100644 --- a/crates/ui-egui/src/tools/transform_task_bar.rs +++ b/crates/ui-egui/src/tools/transform_task_bar.rs @@ -22,7 +22,6 @@ enum Action { #[derive(Clone, Copy)] struct ShownRect { session: u64, - pass: u64, rect: [f32; 4], } @@ -57,13 +56,16 @@ pub fn eligible(app: &PhotocraftApp) -> bool { pub(crate) fn shown_rect(app: &PhotocraftApp, ctx: &egui::Context) -> Option<[f32; 4]> { let session = open_box(app)?.id; let shown = ctx.data(|data| data.get_temp::(shown_id()))?; - let pass = ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT); - (shown.session == session && pass.checked_sub(shown.pass).is_some_and(|age| age <= 1)).then_some(shown.rect) + (shown.session == session).then_some(shown.rect) } /// Called on the document's primary canvas, where the framework shows its transform. pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, area: egui::Rect) { - let Some(transform) = open_box(app) else { return }; + // The canvas run that shows the bar records where; a replay of that run shows it there still. + let Some(transform) = open_box(app) else { + ui.ctx().data_mut(|data| data.remove::(shown_id())); + return; + }; let (session, corners) = (transform.id, transform.session.quad()); let ctx = ui.ctx().clone(); let mut place = app.ui.panels.task_bar; @@ -106,10 +108,9 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, area: egui::Rect) { if shown.output.hide { app.ui.panels.context_task_bar = false; } - let pass = ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT); if open_box(app).is_some_and(|t| t.id == session) { let r = shown.output.rect; - ctx.data_mut(|data| data.insert_temp(shown_id(), ShownRect { session, pass, rect: [r.min.x, r.min.y, r.max.x, r.max.y] })); + ctx.data_mut(|data| data.insert_temp(shown_id(), ShownRect { session, rect: [r.min.x, r.min.y, r.max.x, r.max.y] })); } else { ctx.data_mut(|data| data.remove::(shown_id())); } diff --git a/crates/ui-egui/src/tools/type_box_preview.rs b/crates/ui-egui/src/tools/type_box_preview.rs index d276b4ebc6..73c5e10d82 100644 --- a/crates/ui-egui/src/tools/type_box_preview.rs +++ b/crates/ui-egui/src/tools/type_box_preview.rs @@ -375,7 +375,7 @@ pub(crate) fn wake(app: &mut PhotocraftApp, ctx: &egui::Context) { p.ctx = Some(ctx.clone()); } if p.running.is_some() { - ctx.request_repaint_after(std::time::Duration::from_millis(POLL_MS)); + craft::ui::runtime::frame::request_repaint_after(&ctx, std::time::Duration::from_millis(POLL_MS).as_secs_f64()); } } diff --git a/crates/ui-egui/src/tools/type_tool/controls.rs b/crates/ui-egui/src/tools/type_tool/controls.rs index 91bf111eb9..cc77151655 100644 --- a/crates/ui-egui/src/tools/type_tool/controls.rs +++ b/crates/ui-egui/src/tools/type_tool/controls.rs @@ -99,7 +99,7 @@ pub(crate) fn canvas_controls(app: &mut PhotocraftApp, ui: &mut egui::Ui, canvas let ctx = ui.ctx().clone(); crate::type_box_preview::wake(app, &ctx); let Some(view) = crate::type_transform::view_of(ui) else { return }; - let transform_shown = crate::type_transform::visible(app, craft::ui::runtime::pointer::frame(&ctx).mods); + let transform_shown = crate::type_transform::visible(app, craft::ui::runtime::pointer::mods(&ctx)); if ed.mask { mask_tint(app, ui, canvas, id); } @@ -228,7 +228,7 @@ fn editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, view: &craft::behavior::Ca // A primary press on the canvas background is what makes the editor commit (editor.rs: `background().pressed`); // the same press reaches the tool, which then starts no new text. let background_press = canvas_space(&Env::of(ui).view()).is_some_and(|space| space.background().pressed == Some(PointerButton::Primary)); - let held = craft::ui::runtime::pointer::frame(ui.ctx()).mods; + let held = craft::ui::runtime::pointer::mods(ui.ctx()); if let Some(at) = out.context { app.canvas_tools.type_tool.context = Some((at, held)); } diff --git a/crates/ui-egui/src/tools/type_tool/pointer.rs b/crates/ui-egui/src/tools/type_tool/pointer.rs index 57119f97d6..22e4d75eb5 100644 --- a/crates/ui-egui/src/tools/type_tool/pointer.rs +++ b/crates/ui-egui/src/tools/type_tool/pointer.rs @@ -371,7 +371,7 @@ impl CanvasTool for TypeTool<'_> { /// With an edit open and the type box hidden, another type layer is the tool's over the edit's move reach and /// caret: a press there commits the edit (`claimed_regions`). With ⌘ held the box shows, and its own reach rules. fn regions(&self) -> Vec { - let mods = craft::ui::runtime::pointer::frame(self.scope.ctx()).mods; + let mods = craft::ui::runtime::pointer::mods(self.scope.ctx()); let regions = self.scope.with_app(|app| { let box_shown = app.ui.tool.is_type() && crate::type_transform::whole_box(app, mods); if crate::type_transform::active(app) || box_shown { diff --git a/crates/ui-egui/src/tools/type_transform.rs b/crates/ui-egui/src/tools/type_transform.rs index b89345cedc..f19df9e6c5 100644 --- a/crates/ui-egui/src/tools/type_transform.rs +++ b/crates/ui-egui/src/tools/type_transform.rs @@ -184,7 +184,7 @@ pub(crate) fn frame(app: &mut PhotocraftApp) -> Option { let layer = app.session.active()?.doc.layer(id)?; // Only the whole-box pass (⌘/Ctrl held, or a capture begun so - the early return above) asks the pointer // frame; the move-reach pass without the modifier keeps a mask session frameless, as before. - let mask_frame = mask_session && craft::ui::runtime::pointer::frame(app.ctx()).mods.cmd; + let mask_frame = mask_session && craft::ui::runtime::pointer::mods(app.ctx()).cmd; if layer.locks.all || layer.locks.position || (!layer.visible && !mask_frame) { return None; } diff --git a/crates/ui-egui/src/tools/vector_ui/host.rs b/crates/ui-egui/src/tools/vector_ui/host.rs index 23c7ad6c5d..978485da1b 100644 --- a/crates/ui-egui/src/tools/vector_ui/host.rs +++ b/crates/ui-egui/src/tools/vector_ui/host.rs @@ -96,7 +96,7 @@ fn configure(app: &PhotocraftApp, state: &mut VectorTools) -> Which { // ⌘ makes the pointer Direct Selection: the draft is drawn and keeps its keys, but takes no presses. // A refused draft of another document waits for its explicit retry: no press adds to it (`cancel_stale`). let stale = pen.is_some_and(|p| p.commit_failed && p.owner.as_ref().is_some_and(|o| !o.valid(app))); - let sensing = !craft::ui::runtime::pointer::frame(app.ctx()).mods.cmd && !stale; + let sensing = !craft::ui::runtime::pointer::mods(app.ctx()).cmd && !stale; let idle = pen.is_none_or(|p| p.draft.knots.is_empty()); let carry = if curvature && idle { pen::carry_on(app) } else { None }; state @@ -156,7 +156,7 @@ pub(crate) fn drain(app: &mut PhotocraftApp, state: &mut VectorTools, _response: for event in state.shapes.take_events() { match event { ShapeDragEvent::Draw(EditEvent::Commit { after, .. }) => { - let mods = craft::ui::runtime::pointer::frame(app.ctx()).mods; + let mods = craft::ui::runtime::pointer::mods(app.ctx()); super::shapes::finish_drag(app, state.shapes.kind(), &after, mods); } ShapeDragEvent::Click { at, kind, .. } => { diff --git a/crates/ui-egui/src/tools/vector_ui/overlay.rs b/crates/ui-egui/src/tools/vector_ui/overlay.rs index 809698e032..810f66ca0e 100644 --- a/crates/ui-egui/src/tools/vector_ui/overlay.rs +++ b/crates/ui-egui/src/tools/vector_ui/overlay.rs @@ -132,7 +132,7 @@ fn plan(app: &PhotocraftApp, doc: DocId, mods: Mods) -> (BezierTool, Vec<(PathRe /// its report with the path of each `EditPath`. `None` when no path shows; the editing state is /// then told so (`edits::not_shown`). pub(crate) fn show_paths(app: &mut PhotocraftApp, ui: &mut egui::Ui, at: egui::Rect, doc: DocId) -> Option { - let mods = craft::ui::runtime::pointer::frame(ui.ctx()).mods; + let mods = craft::ui::runtime::pointer::mods(ui.ctx()); let (tool, shown) = plan(app, doc, mods); if shown.is_empty() { crate::direct_select::edits::not_shown(app); diff --git a/crates/ui-egui/src/tools/vector_ui/shapes.rs b/crates/ui-egui/src/tools/vector_ui/shapes.rs index fd18e72b36..8379ac8ac2 100644 --- a/crates/ui-egui/src/tools/vector_ui/shapes.rs +++ b/crates/ui-egui/src/tools/vector_ui/shapes.rs @@ -472,7 +472,7 @@ fn path_on_screen(path: &photocraft_doc::vector::Path, view: &CanvasView) -> pho /// the commit. The accent outline over its halo is the framework tool's own paint. pub fn show_preview(app: &PhotocraftApp, ui: &egui::Ui, at: egui::Rect, view: &CanvasView) { let Some((kind, geometry)) = super::host::shape_preview(app) else { return }; - let shift = craft::ui::runtime::pointer::frame(ui.ctx()).mods.shift; + let shift = craft::ui::runtime::pointer::mods(ui.ctx()).shift; let Some(mut shape) = preview_layer(app, kind, geometry, shift) else { return }; // Align Edges fits the shape to document pixels, so it is applied here, in document space: // the preview then shows the committed layer's geometry at any zoom. From 56bf471c4a5f4fb1c17400a73f6d87ce5666f2f8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 27 Nov 2026 01:21:44 +0000 Subject: [PATCH 07/21] Options-bar and tool writes bump the tool options' revision only when they change a value (FW-365 F6b) --- crates/ui-egui/src/app/frame.rs | 4 - crates/ui-egui/src/chrome_settle_trials.rs | 18 ++- crates/ui-egui/src/panels/options_bar.rs | 4 +- crates/ui-egui/src/panels/options_bar/fill.rs | 43 ++++--- .../src/panels/options_bar/navigate.rs | 14 ++- crates/ui-egui/src/state.rs | 2 +- crates/ui-egui/src/state/tool_options.rs | 46 +++++--- crates/ui-egui/src/tools/adjustment_brush.rs | 8 +- crates/ui-egui/src/tools/analysis/bars.rs | 8 +- crates/ui-egui/src/tools/eraser_ui.rs | 37 +++--- crates/ui-egui/src/tools/eyedropper_ui.rs | 6 +- crates/ui-egui/src/tools/gradient_ui/bar.rs | 35 +++--- crates/ui-egui/src/tools/magnetic_lasso_ui.rs | 4 +- crates/ui-egui/src/tools/option_cells.rs | 8 +- .../ui-egui/src/tools/perspective_crop_ui.rs | 9 +- .../ui-egui/src/tools/retouch_ui/bar/heal.rs | 106 ++++++++---------- .../src/tools/retouch_ui/bar/history.rs | 39 ++++--- .../src/tools/retouch_ui/bar/select.rs | 29 ++--- .../ui-egui/src/tools/retouch_ui/bar/tone.rs | 54 ++++----- crates/ui-egui/src/tools/retouch_ui/tests.rs | 4 +- crates/ui-egui/src/tools/shape_options.rs | 4 +- crates/ui-egui/src/tools/tool_reset.rs | 4 +- crates/ui-egui/src/tools/vector_ui/options.rs | 24 ++-- 23 files changed, 274 insertions(+), 236 deletions(-) diff --git a/crates/ui-egui/src/app/frame.rs b/crates/ui-egui/src/app/frame.rs index 151bd3f0ab..e15fcfeaac 100644 --- a/crates/ui-egui/src/app/frame.rs +++ b/crates/ui-egui/src/app/frame.rs @@ -162,11 +162,7 @@ impl PhotocraftApp { // A software adapter or CPU mode chosen at startup is every document's reason. crate::render_path::frame(self); // Every frame that started its stage record closes it, whichever way `ui_body` returns. - // Controls and panels write their values back on every pass; only the writes that change an option move its - // revision, which the options bar's version holds, so a pass that changed nothing leaves the bar settled. - let options = self.ui.tool_options.checkpoint(); self.ui_body(ui); - self.ui.tool_options.settle(options); // What an injected step changed is the target of the rest of its request: only a change // between passes withdraws queued input (`withdraw_stale_input`). #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/ui-egui/src/chrome_settle_trials.rs b/crates/ui-egui/src/chrome_settle_trials.rs index b0ea8b1033..7241e312e2 100644 --- a/crates/ui-egui/src/chrome_settle_trials.rs +++ b/crates/ui-egui/src/chrome_settle_trials.rs @@ -254,16 +254,24 @@ fn a_tool_option_runs_the_options_bar_once() { } /// A bar that runs and writes every control's value back leaves the tool options' revision alone, so idle frames never -/// move what the bar's version holds. +/// move what the bar's version holds, whichever tool's bar is showing. #[test] fn an_idle_options_bar_leaves_the_tool_options_revision() { let mut h = harness(); + let mut moved = Vec::new(); + for tool in crate::state::Tool::ALL { + h.state_mut().ui.tool = tool; + h.run_steps(4); + let settled = h.state().ui.tool_options.revision(); + h.run_steps(6); + if h.state().ui.tool_options.revision() != settled { + moved.push(tool); + } + } + assert!(moved.is_empty(), "idle frames moved the tool options under {moved:?}"); + // A changed option runs the bar, whose own writes then change nothing more. h.state_mut().ui.tool = crate::state::Tool::Move; h.run_steps(4); - let settled = h.state().ui.tool_options.revision(); - h.run_steps(10); - assert_eq!(h.state().ui.tool_options.revision(), settled, "ten idle frames"); - // A changed option runs the bar, whose own writes then change nothing more. let on = h.state().ui.tool_options.move_auto_select; h.state_mut().ui.tool_options.move_auto_select = !on; let changed = h.state().ui.tool_options.revision(); diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index 961b2318ef..0dd011df4e 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -345,8 +345,8 @@ pub(super) fn labelled(ui: &mut egui::Ui, label: &str, mut add: impl FnMut(&m } /// A check box named `label` over `value`. -pub(super) fn check(ui: &mut egui::Ui, label: &str, value: &mut bool) { - Checkbox::new(Bind::bound(value)).label(label.to_owned()).show(ui); +pub(super) fn check(ui: &mut egui::Ui, label: &str, value: Bind<'_, bool>) { + Checkbox::new(value).label(label.to_owned()).show(ui); } /// A number field named `label` over `value` (in `unit` when it is not empty), limited to `range`. The events of this diff --git a/crates/ui-egui/src/panels/options_bar/fill.rs b/crates/ui-egui/src/panels/options_bar/fill.rs index 61e9ff4df5..f44cde0f6b 100644 --- a/crates/ui-egui/src/panels/options_bar/fill.rs +++ b/crates/ui-egui/src/panels/options_bar/fill.rs @@ -1,6 +1,6 @@ //! The Paint Bucket's members of the options bar, and the Mode list of the Paint Bucket and the stamp tools. -use craft::ui::contract::{Bind, Entry, Show as _}; +use craft::ui::contract::{Bind, Entry, Show as _, bind_tracked}; use craft::ui::patterns::blend_keys::{BlendKeyEntry, blend_entries}; use craft::ui::pickers::Select; use photocraft_doc::BlendMode; @@ -67,25 +67,34 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } let entries = mode_entries(Tool::PaintBucket, true, false); let sources = [Entry::new(false, tl!("Foreground").to_owned()), Entry::new(true, tl!("Pattern").to_owned())]; - let o = &mut app.ui.tool_options; - labelled(ui, tl!("Fill"), |ui| Select::new(tl!("Source").to_owned(), Bind::bound(&mut o.bucket_fill_pattern), &sources).show(ui)); - let mut mode = if o.bucket_clear { PaintMode::Clear } else { PaintMode::Blend(o.bucket_blend_mode) }; + { + let mut pattern = Some(bind_tracked!(app.ui.tool_options => bucket_fill_pattern)); + labelled(ui, tl!("Fill"), |ui| pattern.take().map(|pattern| Select::new(tl!("Source").to_owned(), pattern, &sources).show(ui))); + } + let o = &app.ui.tool_options; + let shown = if o.bucket_clear { PaintMode::Clear } else { PaintMode::Blend(o.bucket_blend_mode) }; + let mut mode = shown; labelled(ui, tl!("Mode"), |ui| mode_select(Bind::bound(&mut mode), &entries).show(ui)); - match mode { - PaintMode::Clear => o.bucket_clear = true, - PaintMode::Blend(blend) => { - o.bucket_clear = false; - o.bucket_blend_mode = blend; + let (opacity, tolerance) = (o.fill_opacity, o.tolerance); + if mode != shown { + let o = &mut app.ui.tool_options; + match mode { + PaintMode::Clear => o.bucket_clear = true, + PaintMode::Blend(blend) => { + o.bucket_clear = false; + o.bucket_blend_mode = blend; + } + PaintMode::Behind => {} } - PaintMode::Behind => {} } - if let Some(opacity) = number_field(ui, tl!("Opacity"), o.fill_opacity, 1.0..=100.0, "%").landed() { - o.fill_opacity = *opacity; + if let Some(opacity) = number_field(ui, tl!("Opacity"), opacity, 1.0..=100.0, "%").landed() { + app.ui.tool_options.fill_opacity = *opacity; } - if let Some(tolerance) = number_field(ui, tl!("Tolerance"), o.tolerance, 0.0..=255.0, "").landed() { - o.tolerance = *tolerance; + if let Some(tolerance) = number_field(ui, tl!("Tolerance"), tolerance, 0.0..=255.0, "").landed() { + app.ui.tool_options.tolerance = *tolerance; } - check(ui, tl!("Anti-alias"), &mut o.anti_alias); - check(ui, tl!("Contiguous"), &mut o.contiguous); - check(ui, tl!("All Layers"), &mut o.sample_all.paint_bucket); + let (anti_alias, contiguous, all_layers) = bind_tracked!(app.ui.tool_options => anti_alias, contiguous, sample_all.paint_bucket); + check(ui, tl!("Anti-alias"), anti_alias); + check(ui, tl!("Contiguous"), contiguous); + check(ui, tl!("All Layers"), all_layers); } diff --git a/crates/ui-egui/src/panels/options_bar/navigate.rs b/crates/ui-egui/src/panels/options_bar/navigate.rs index d05faa82cf..ee64c9e385 100644 --- a/crates/ui-egui/src/panels/options_bar/navigate.rs +++ b/crates/ui-egui/src/panels/options_bar/navigate.rs @@ -1,7 +1,7 @@ //! The options bar's members of the Move, Eyedropper, Zoom, Rotate View and Hand tools. use craft::ui::canvas::{NavigateBar, NavigationOptions}; -use craft::ui::contract::{Bind, Entry, Show as _}; +use craft::ui::contract::{Bind, Entry, Show as _, bind_tracked}; use craft::ui::display::Divider; use craft::ui::pickers::Select; @@ -21,12 +21,12 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) { /// Auto-Select, its target, Show Transform Controls, then the align strip. fn move_members(app: &mut PhotocraftApp, ui: &mut egui::Ui) { - let o = &mut app.ui.tool_options; - check(ui, tl!("Auto-Select:"), &mut o.move_auto_select); + let (auto_select, target, transform) = bind_tracked!(app.ui.tool_options => move_auto_select, move_target, move_show_transform); + check(ui, tl!("Auto-Select:"), auto_select); let targets = [Entry::new("group".to_owned(), tl!("Group").to_owned()), Entry::new("layer".to_owned(), tl!("Layer").to_owned())]; - Select::new(tl!("Auto-Select:").to_owned(), Bind::bound(&mut o.move_target), &targets).show(ui); + Select::new(tl!("Auto-Select:").to_owned(), target, &targets).show(ui); Divider::vertical().show(ui); - check(ui, tl!("Show Transform Controls"), &mut o.move_show_transform); + check(ui, tl!("Show Transform Controls"), transform); Divider::vertical().show(ui); crate::align_bar::show(app, ui); } @@ -60,7 +60,9 @@ fn view_members(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // Zoom Out is the bar's `out`; the tool keeps the direction as `zoom_in`. let mut out = !app.ui.tool_options.zoom_in; let shown = NavigateBar::zoom(Bind::bound(&mut view), target, &mut options, Bind::bound(&mut out)).show(ui); - app.ui.tool_options.zoom_in = !out; + if app.ui.tool_options.zoom_in == out { + app.ui.tool_options.zoom_in = !out; + } crate::chrome_ui::zoom_alert(app, shown.invalid_zoom); write_view(app, index, &view, !shown.view.is_empty()); } else { diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 5ad2b02ab1..4be51b6a79 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -599,7 +599,7 @@ mod tests { let mut s = SampleAllLayers::default(); assert!(s.slot(Tool::Brush).is_none()); for t in [Tool::MagicWand, Tool::PaintBucket, Tool::Blur, Tool::Sharpen, Tool::Smudge, Tool::Remove] { - *s.slot(t).unwrap() = true; + *s.slot_mut(t).unwrap() = true; assert!(s.get(t), "{t:?}"); } assert!(!s.get(Tool::QuickSelection)); diff --git a/crates/ui-egui/src/state/tool_options.rs b/crates/ui-egui/src/state/tool_options.rs index 4638ca23a0..344bedefc2 100644 --- a/crates/ui-egui/src/state/tool_options.rs +++ b/crates/ui-egui/src/state/tool_options.rs @@ -416,29 +416,41 @@ impl Default for SampleAllLayers { } } +/// The field of `SampleAllLayers` that `$tool` keeps, borrowed as `$borrow`. +macro_rules! sample_all_slot { + ($this:ident, $tool:ident, $($borrow:tt)+) => { + Some(match $tool { + Tool::MagicWand => $($borrow)+ $this.magic_wand, + Tool::QuickSelection => $($borrow)+ $this.quick_selection, + Tool::ObjectSelection => $($borrow)+ $this.object_selection, + Tool::PaintBucket => $($borrow)+ $this.paint_bucket, + Tool::MagicEraser => $($borrow)+ $this.magic_eraser, + Tool::SpotHealing => $($borrow)+ $this.spot_healing, + Tool::Patch => $($borrow)+ $this.patch, + Tool::ContentAwareMove => $($borrow)+ $this.content_aware_move, + Tool::Remove => $($borrow)+ $this.remove, + Tool::Blur => $($borrow)+ $this.blur, + Tool::Sharpen => $($borrow)+ $this.sharpen, + Tool::Smudge => $($borrow)+ $this.smudge, + _ => return None, + }) + }; +} + impl SampleAllLayers { /// `tool`'s setting; false for a tool without the option. pub fn get(mut self, tool: Tool) -> bool { - self.slot(tool).is_some_and(|v| *v) + self.slot(tool).unwrap_or(false) } /// `tool`'s setting, or `None` for a tool without the option. - pub fn slot(&mut self, tool: Tool) -> Option<&mut bool> { - Some(match tool { - Tool::MagicWand => &mut self.magic_wand, - Tool::QuickSelection => &mut self.quick_selection, - Tool::ObjectSelection => &mut self.object_selection, - Tool::PaintBucket => &mut self.paint_bucket, - Tool::MagicEraser => &mut self.magic_eraser, - Tool::SpotHealing => &mut self.spot_healing, - Tool::Patch => &mut self.patch, - Tool::ContentAwareMove => &mut self.content_aware_move, - Tool::Remove => &mut self.remove, - Tool::Blur => &mut self.blur, - Tool::Sharpen => &mut self.sharpen, - Tool::Smudge => &mut self.smudge, - _ => return None, - }) + pub fn slot(&self, tool: Tool) -> Option { + sample_all_slot!(self, tool, &).copied() + } + + /// `tool`'s setting to write, or `None` for a tool without the option. + pub fn slot_mut(&mut self, tool: Tool) -> Option<&mut bool> { + sample_all_slot!(self, tool, &mut) } } diff --git a/crates/ui-egui/src/tools/adjustment_brush.rs b/crates/ui-egui/src/tools/adjustment_brush.rs index 04b3cf28d2..e18c508d75 100644 --- a/crates/ui-egui/src/tools/adjustment_brush.rs +++ b/crates/ui-egui/src/tools/adjustment_brush.rs @@ -6,7 +6,7 @@ use craft::behavior::IconId; use craft::ui::buttons::{IconButton, ToggleButton}; use craft::ui::choice::{Checkbox, Segmented}; -use craft::ui::contract::{Bind, Entry, Props as _, Show as _}; +use craft::ui::contract::{Bind, Entry, Props as _, Show as _, bind_tracked}; use craft::ui::display::Divider; use craft::ui::pickers::Select; use photocraft_engine::adjustment_brush_cmds::{self as ab, ENTRIES, INDEXED_ALERT}; @@ -152,7 +152,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo let choose = tl!("Choose an object and have the adjustment applied to it"); IconButton::new(IconId::new("square-dashed-mouse-pointer")).label(choose).tooltip(choose).enabled(false).show(ui); // On, the canvas tints what the active adjustment layer's mask reveals (`raster_source::MaskTint`, #12520). - Checkbox::new(Bind::bound(&mut app.ui.tool_options.adjustment_brush_overlay)) + Checkbox::new(bind_tracked!(app.ui.tool_options => adjustment_brush_overlay)) .label(tl!("Overlay").to_owned()) .tooltip(tl!("Show or hide the painted mask areas").to_owned()) .show(ui); @@ -160,7 +160,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo let mut alerts = Vec::new(); let mut opacity = (brush.opacity * 100.0).round(); - let out = option_cells::number(tl!("Opacity:"), &mut opacity, 1.0..=100.0).whole().unit("%").show(ui); + let out = option_cells::number(tl!("Opacity:"), Bind::bound(&mut opacity), 1.0..=100.0).whole().unit("%").show(ui); key = out.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key); brush.opacity = opacity / 100.0; alerts.extend(out.out_of_range); @@ -173,7 +173,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo key = pressure.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key); } let mut flow = brush.flow * 100.0; - let out = option_cells::number(tl!("Flow:"), &mut flow, 1.0..=100.0).unit("%").show(ui); + let out = option_cells::number(tl!("Flow:"), Bind::bound(&mut flow), 1.0..=100.0).unit("%").show(ui); key = out.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key); brush.flow = flow / 100.0; alerts.extend(out.out_of_range); diff --git a/crates/ui-egui/src/tools/analysis/bars.rs b/crates/ui-egui/src/tools/analysis/bars.rs index 15d34f36e8..31d2f1d580 100644 --- a/crates/ui-egui/src/tools/analysis/bars.rs +++ b/crates/ui-egui/src/tools/analysis/bars.rs @@ -7,7 +7,7 @@ use craft::draw::ui::measure::{RulerBar, RulerLine}; use craft::theme::Srgba; use craft::ui::buttons::{Button, IconButton, ToggleButton}; use craft::ui::choice::Swatch; -use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; +use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, bind_tracked}; use craft::ui::display::{Divider, Text}; use craft::ui::form::Field; use craft::ui::pickers::Select; @@ -161,8 +161,8 @@ fn count(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &photocraft_doc::Docum Divider::vertical().show(ui); let (marker, label) = (g.marker_size as f32, g.label_size as f32); let (mut new_marker, mut new_label) = (marker, label); - let marker_out = option_cells::number(tl!("Marker Size"), &mut new_marker, MARKER_SIZE).whole().show(ui); - let label_out = option_cells::number(tl!("Label Size"), &mut new_label, LABEL_SIZE).whole().show(ui); + let marker_out = option_cells::number(tl!("Marker Size"), Bind::bound(&mut new_marker), MARKER_SIZE).whole().show(ui); + let label_out = option_cells::number(tl!("Label Size"), Bind::bound(&mut new_label), LABEL_SIZE).whole().show(ui); // A typed size out of range takes the closest value and says so once (#13530). for alert in [&marker_out.out_of_range, &label_out.out_of_range].into_iter().flatten() { option_cells::range_alert(app, ui, alert); @@ -207,7 +207,7 @@ fn sampler(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let n = app.session.active().map_or(0, |d| d.color_samplers.len()); // One Sample Size setting, shared with the Eyedropper (#11732). // PLAN: assumed `SamplerOptions::show(ui)` returns an output with `clear_all: bool`. - let out = SamplerOptions::new(n, Bind::bound(&mut app.ui.tool_options.eyedropper.size)).show(ui); + let out = SamplerOptions::new(n, bind_tracked!(app.ui.tool_options => eyedropper.size)).show(ui); if out.clear_all { run(app, "view.colorSamplers.clear", json!({})); } diff --git a/crates/ui-egui/src/tools/eraser_ui.rs b/crates/ui-egui/src/tools/eraser_ui.rs index 12fd03a433..c3a701c0a9 100644 --- a/crates/ui-egui/src/tools/eraser_ui.rs +++ b/crates/ui-egui/src/tools/eraser_ui.rs @@ -7,7 +7,7 @@ use craft::behavior::IconId; use craft::ui::buttons::ToggleButton; use craft::ui::choice::{Checkbox, Segmented}; -use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; +use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, bind_tracked}; use craft::ui::display::Divider; use craft::ui::form::Field; use craft::ui::pickers::Select; @@ -148,8 +148,8 @@ pub(crate) fn stored_tolerance(v: f32) -> f32 { } /// A check box named `label` over `value`. -fn check(ui: &mut egui::Ui, label: &str, value: &mut bool, tip: Option<&str>) { - let mut checkbox = Checkbox::new(Bind::bound(value)).label(label.to_owned()); +fn check(ui: &mut egui::Ui, label: &str, value: Bind<'_, bool>, tip: Option<&str>) { + let mut checkbox = Checkbox::new(value).label(label.to_owned()); if let Some(tip) = tip { checkbox = checkbox.tooltip(tip.to_owned()); } @@ -168,28 +168,27 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo } fn magic_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { - let o = &mut app.ui.tool_options; // The field clamps without an alert, as the reference's Magic Eraser Tolerance does. - let _ = option_cells::number(tl!("Tolerance:"), &mut o.tolerance, 0.0..=255.0).show(ui); - check(ui, tl!("Anti-alias"), &mut o.anti_alias, None); - check(ui, tl!("Contiguous"), &mut o.contiguous, None); - check(ui, tl!("Sample All Layers"), &mut o.sample_all.magic_eraser, None); + let _ = option_cells::number(tl!("Tolerance:"), bind_tracked!(app.ui.tool_options => tolerance), 0.0..=255.0).show(ui); + let (anti_alias, contiguous, sample_all) = bind_tracked!(app.ui.tool_options => anti_alias, contiguous, sample_all.magic_eraser); + check(ui, tl!("Anti-alias"), anti_alias, None); + check(ui, tl!("Contiguous"), contiguous, None); + check(ui, tl!("Sample All Layers"), sample_all, None); Divider::vertical().show(ui); - let _ = option_cells::number(tl!("Opacity:"), &mut o.magic_eraser_opacity, 1.0..=100.0).unit("%").show(ui); + let _ = option_cells::number(tl!("Opacity:"), bind_tracked!(app.ui.tool_options => magic_eraser_opacity), 1.0..=100.0).unit("%").show(ui); } fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { let mut alerts = Vec::new(); { - let o = &mut app.ui.tool_options; let sampling = [ Entry::new("continuous".to_string(), tl!("Sampling: Continuous")).icon(IconId::new("eyedropper")), Entry::new("once".to_string(), tl!("Sampling: Once")).icon(IconId::new("target")), Entry::new("backgroundSwatch".to_string(), tl!("Sampling: Background Swatch")).icon(IconId::new("square")), ]; - let picked = Segmented::new(tl!("Sampling"), Bind::given(o.bg_sampling.clone()), &sampling).show(ui).value().cloned(); + let picked = Segmented::new(tl!("Sampling"), Bind::given(app.ui.tool_options.bg_sampling.clone()), &sampling).show(ui).value().cloned(); if let Some(sampling) = picked { - o.bg_sampling = sampling; + app.ui.tool_options.bg_sampling = sampling; } Divider::vertical().show(ui); @@ -201,7 +200,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { // In a `Field`, as Color Replacement's Limits: a bare control's label only names it (#16338). let picked = Field::new(tl!("Limits:")) .show(ui, |ui, _| { - Select::new(tl!("Limits:"), Bind::given(o.bg_limits.clone()), &limits) + Select::new(tl!("Limits:"), Bind::given(app.ui.tool_options.bg_limits.clone()), &limits) .tooltip(tl!("How far to let the erasing spread").to_owned()) .show(ui) .events @@ -211,20 +210,20 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { .inner .flatten(); if let Some(limits) = picked { - o.bg_limits = limits; + app.ui.tool_options.bg_limits = limits; } // Shown as the stroke reads it; written back only when the user edits it. - let shown = stored_tolerance(o.bg_tolerance); + let shown = stored_tolerance(app.ui.tool_options.bg_tolerance); let mut tolerance = shown; - let alert = option_cells::number(tl!("Tolerance:"), &mut tolerance, 1.0..=100.0) + let alert = option_cells::number(tl!("Tolerance:"), Bind::bound(&mut tolerance), 1.0..=100.0) .whole() .unit("%") .tooltip(tl!("Erase range of similar colors")) .show(ui) .out_of_range; if tolerance != shown { - o.bg_tolerance = tolerance; + app.ui.tool_options.bg_tolerance = tolerance; } alerts.extend(alert); } @@ -233,7 +232,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { let before = (*app.session.tools.brush).clone(); let mut brush = before.clone(); let mut angle = brush.angle; - let angle_out = option_cells::number(tl!("Angle"), &mut angle, -180.0..=180.0) + let angle_out = option_cells::number(tl!("Angle"), Bind::bound(&mut angle), -180.0..=180.0) .whole() .unit("°") .icon(IconSpec::svg(IconId::new("rotate_cw"))) @@ -244,7 +243,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) { brush.angle = angle; alerts.extend(angle_out.out_of_range); - check(ui, tl!("Protect Foreground Color"), &mut app.ui.tool_options.bg_protect_fg, Some(tl!("Do not erase the foreground swatch color"))); + check(ui, tl!("Protect Foreground Color"), bind_tracked!(app.ui.tool_options => bg_protect_fg), Some(tl!("Do not erase the foreground swatch color"))); let pressure = ToggleButton::new(tl!("Always use pressure for size"), Bind::given(brush.pressure_size)) .icon(IconId::new("target")) diff --git a/crates/ui-egui/src/tools/eyedropper_ui.rs b/crates/ui-egui/src/tools/eyedropper_ui.rs index d9da168205..a745abf2a2 100644 --- a/crates/ui-egui/src/tools/eyedropper_ui.rs +++ b/crates/ui-egui/src/tools/eyedropper_ui.rs @@ -10,7 +10,11 @@ use crate::PhotocraftApp; /// The options bar for the Eyedropper tool. pub fn options(app: &mut PhotocraftApp, ui: &mut egui::Ui) { - EyedropperBar::new(&mut app.ui.tool_options.eyedropper).show(ui); + let mut options = app.ui.tool_options.eyedropper; + EyedropperBar::new(&mut options).show(ui); + if options != app.ui.tool_options.eyedropper { + app.ui.tool_options.eyedropper = options; + } } #[cfg(test)] diff --git a/crates/ui-egui/src/tools/gradient_ui/bar.rs b/crates/ui-egui/src/tools/gradient_ui/bar.rs index 0f9a30ed4e..2a389f1be8 100644 --- a/crates/ui-egui/src/tools/gradient_ui/bar.rs +++ b/crates/ui-egui/src/tools/gradient_ui/bar.rs @@ -3,7 +3,7 @@ use craft::draw::ui::gradient::{GradientFillWords, GradientStyle, GradientSwatch}; use craft::ui::choice::{Checkbox, Segmented}; -use craft::ui::contract::{Bind, Entry, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel}; +use craft::ui::contract::{Bind, Entry, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, bind_tracked}; use craft::ui::display::Divider; use craft::ui::form::Field; use craft::ui::patterns::blend_keys::{BlendKeyEntry, blend_entries}; @@ -51,37 +51,40 @@ pub(crate) fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let blends = blend_modes(); let open_editor; { - let o = &mut app.ui.tool_options; - let mut classic = o.gradient_classic && !locked_live; + let mut classic = app.ui.tool_options.gradient_classic && !locked_live; Field::new(tl!("Gradient mode").to_owned()).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| { Select::new(tl!("Gradient mode").to_owned(), Bind::bound(&mut classic), &modes).enabled(!locked_live).show(ui); }); - if !locked_live { - o.gradient_classic = classic; + if !locked_live && classic != app.ui.tool_options.gradient_classic { + app.ui.tool_options.gradient_classic = classic; } open_editor = GradientSwatch::new(tl!("Gradient picker").to_string(), &tool_stops).sampler(&sampler).show(ui).clicked; Divider::vertical().show(ui); - let style = stops::style_named(&o.gradient_style); + let style = stops::style_named(&app.ui.tool_options.gradient_style); if let Some(next) = Segmented::new(Label::from(tl!("Gradient style").to_string()), Bind::given(style), &styles).show(ui).value().copied() { - o.gradient_style = stops::style_name(next).to_owned(); + app.ui.tool_options.gradient_style = stops::style_name(next).to_owned(); } if classic { - labelled(ui, tl!("Mode"), |ui| { - Select::new(tl!("Blend Mode").to_owned(), Bind::bound(&mut o.gradient_blend_mode), &blends).show(ui); - }); + let fill_opacity = app.ui.tool_options.fill_opacity; + { + let mut blend = bind_tracked!(app.ui.tool_options => gradient_blend_mode); + labelled(ui, tl!("Mode"), |ui| { + Select::new(tl!("Blend Mode").to_owned(), blend.reborrowed(), &blends).show(ui); + }); + } labelled(ui, tl!("Opacity"), |ui| { let field = - NumberField::new(tl!("Opacity").to_owned(), Bind::given(Some(f64::from(o.fill_opacity)))).range(1.0..=100.0).unit("%").scrub_by_label(); + NumberField::new(tl!("Opacity").to_owned(), Bind::given(Some(f64::from(fill_opacity)))).range(1.0..=100.0).unit("%").scrub_by_label(); if let Some(next) = field.show(ui).value().copied().flatten() { - o.fill_opacity = next as f32; + app.ui.tool_options.fill_opacity = next as f32; } }); } - if let Some(on) = Checkbox::new(Bind::given(o.gradient_reverse)).label(tl!("Reverse").to_owned()).show(ui).value().copied() { - o.gradient_reverse = on; + if let Some(on) = Checkbox::new(Bind::given(app.ui.tool_options.gradient_reverse)).label(tl!("Reverse").to_owned()).show(ui).value().copied() { + app.ui.tool_options.gradient_reverse = on; } - if let Some(on) = Checkbox::new(Bind::given(o.gradient_dither)).label(tl!("Dither").to_owned()).show(ui).value().copied() { - o.gradient_dither = on; + if let Some(on) = Checkbox::new(Bind::given(app.ui.tool_options.gradient_dither)).label(tl!("Dither").to_owned()).show(ui).value().copied() { + app.ui.tool_options.gradient_dither = on; } } if open_editor { diff --git a/crates/ui-egui/src/tools/magnetic_lasso_ui.rs b/crates/ui-egui/src/tools/magnetic_lasso_ui.rs index e2a7bb9c9d..6d059cf504 100644 --- a/crates/ui-egui/src/tools/magnetic_lasso_ui.rs +++ b/crates/ui-egui/src/tools/magnetic_lasso_ui.rs @@ -68,7 +68,9 @@ pub(crate) fn prepare(app: &PhotocraftApp, tool: &mut MagneticLassoTool /// Writes the tool's settings back after the run, so `[` and `]` reach the options store. pub(crate) fn store(app: &mut PhotocraftApp, tool: &MagneticLassoTool) { - app.ui.tool_options.magnetic = *tool.settings(); + if app.ui.tool_options.magnetic != *tool.settings() { + app.ui.tool_options.magnetic = *tool.settings(); + } } /// Selects the closed border as drawn, in `mode` (the family's operation-to-mode name). Fewer than diff --git a/crates/ui-egui/src/tools/option_cells.rs b/crates/ui-egui/src/tools/option_cells.rs index 159203d9c7..f0db5cd1f2 100644 --- a/crates/ui-egui/src/tools/option_cells.rs +++ b/crates/ui-egui/src/tools/option_cells.rs @@ -18,7 +18,7 @@ use crate::PhotocraftApp; /// commits, so showing a bar never rounds a fraction another tool shares. pub(crate) struct NumberCell<'a> { caption: Label, - value: &'a mut f32, + value: Bind<'a, f32>, range: RangeInclusive, unit: Option