diff --git a/crates/browse/src/ui/bin/free_view.rs b/crates/browse/src/ui/bin/free_view.rs index 3b42beebd..9eddab3f5 100644 --- a/crates/browse/src/ui/bin/free_view.rs +++ b/crates/browse/src/ui/bin/free_view.rs @@ -32,7 +32,7 @@ where let (entries, _) = entries_of(model, state, collator); let searching = !state.search.trim().is_empty(); let shown = Cards::new(model, entries); - let mods = craft_ui::runtime::pointer::frame(ui.ctx()).mods; + let mods = craft_ui::runtime::pointer::mods(ui.ctx()); if let Some(key) = rename { request_rename(ui.ctx(), id, &key); } diff --git a/crates/browse/src/ui/bin/icon.rs b/crates/browse/src/ui/bin/icon.rs index 941e44333..9fde6bb1d 100644 --- a/crates/browse/src/ui/bin/icon.rs +++ b/crates/browse/src/ui/bin/icon.rs @@ -152,7 +152,7 @@ where let (entries, user_order) = entries_of(model, state, collator); let searching = !state.search.trim().is_empty(); let cards = Cards::new(model, entries); - let mods = craft_ui::runtime::pointer::frame(ui.ctx()).mods; + let mods = craft_ui::runtime::pointer::mods(ui.ctx()); if let Some(key) = rename { request_rename(ui.ctx(), id, &key); } diff --git a/crates/browse/src/ui/bin/list.rs b/crates/browse/src/ui/bin/list.rs index 2893f2225..78c587f30 100644 --- a/crates/browse/src/ui/bin/list.rs +++ b/crates/browse/src/ui/bin/list.rs @@ -103,7 +103,7 @@ where let thumb = state.settings.thumbnails; let specs = columns_of(columns, &state.settings.widths, words.name.clone()); let value_columns: Vec = specs.iter().map(|spec| spec.key.clone()).filter(|key| *key != NAME).collect(); - let mods = craft_ui::runtime::pointer::frame(ui.ctx()).mods; + let mods = craft_ui::runtime::pointer::mods(ui.ctx()); let tile_words = Env::of(ui).words::(); if let Some(key) = rename { request_rename(ui.ctx(), id, &key); diff --git a/crates/draw/src/ui/crop/tool.rs b/crates/draw/src/ui/crop/tool.rs index 4b6308fd0..11eca1c61 100644 --- a/crates/draw/src/ui/crop/tool.rs +++ b/crates/draw/src/ui/crop/tool.rs @@ -260,7 +260,7 @@ impl CropTool { // Straighten surface is there for a press on the pass after the key came down; a line in progress keeps the // state it started with, so letting go of the key mid-line does not turn it into a frame drag. if !self.dragging { - self.session.straighten_mut().set_held(pointer::frame(ui.ctx()).mods.cmd); + self.session.straighten_mut().set_held(pointer::mods(ui.ctx()).cmd); } let (ratio, default, straighten, dismissed) = (settings.ratio_value(document, &units), self.session.is_default(), self.session.straighten().on(), self.session.dismissed()); diff --git a/crates/imaging/src/ui/channels/panel.rs b/crates/imaging/src/ui/channels/panel.rs index fe9539467..f81be39e7 100644 --- a/crates/imaging/src/ui/channels/panel.rs +++ b/crates/imaging/src/ui/channels/panel.rs @@ -154,7 +154,7 @@ impl<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> ChannelsPanel<'a, events.borrow_mut().extend(out); }) .show(ui, |ui, stack| { - let mods = craft_ui::runtime::pointer::frame(&ctx).mods; + let mods = craft_ui::runtime::pointer::mods(&ctx); while let Some((command, _)) = stack.take_command::() { match (command, targeted_row(rows)) { (ChannelsCommands::RenameChannel, Some(row)) if row.kind.renames() => request_rename(&ctx, list, &row.key), diff --git a/crates/imaging/src/ui/color_range/dialog.rs b/crates/imaging/src/ui/color_range/dialog.rs index 5a6ff114b..308292570 100644 --- a/crates/imaging/src/ui/color_range/dialog.rs +++ b/crates/imaging/src/ui/color_range/dialog.rs @@ -223,7 +223,7 @@ impl<'a> ColorRangeDialog<'a> { let preview_words = env.words::(); // Holding ⌘ (Ctrl off macOS; `Mods` folds Ctrl into `cmd` there) shows the other view while held: view only, // `show_image` does not change. - let swapped = pointer::frame(ui.ctx()).mods.cmd; + let swapped = pointer::mods(ui.ctx()).cmd; let image_shown = show_image != swapped; let source = if image_shown { image } else { mask }; let state = match (&error, source) { @@ -288,7 +288,7 @@ impl<'a> ColorRangeDialog<'a> { f64::from(p.x.floor().max(0.0)) * f64::from(k) + f64::from(k / 2), f64::from(p.y.floor().max(0.0)) * f64::from(k) + f64::from(k / 2), ]; - let mods = pointer::frame(ui.ctx()).mods; + let mods = pointer::mods(ui.ctx()); let mut next = pass.current.clone(); next.samples.pick(at, document, tool, mods); pass.set(&words.eyedropper, next); diff --git a/crates/imaging/src/ui/raw_develop/mod.rs b/crates/imaging/src/ui/raw_develop/mod.rs index 98f0249be..1a695e6ef 100644 --- a/crates/imaging/src/ui/raw_develop/mod.rs +++ b/crates/imaging/src/ui/raw_develop/mod.rs @@ -524,7 +524,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace { let words = env.words::(); let common = env.words::(); let ctx = ui.ctx().clone(); - let alt = craft_ui::runtime::pointer::frame(&ctx).mods.alt; + let alt = craft_ui::runtime::pointer::mods(&ctx).alt; self.open_scope(&ctx, source); let name = if self.target == RawTarget::OpenRaw { words.name.clone() } else { words.name_filter.clone() }; diff --git a/crates/imaging/tests/it/channels_memo.rs b/crates/imaging/tests/it/channels_memo.rs new file mode 100644 index 000000000..bc42aced8 --- /dev/null +++ b/crates/imaging/tests/it/channels_memo.rs @@ -0,0 +1,52 @@ +//! The Channels panel in a host's memoized view: a pointer move beside it replays it (#2812). + +use craft_ui::contract::{MemoProps, MemoView}; +use craft_ui::testing::{Fixture, MemoRun, last_frame_memo_runs, pointer, trial}; +use egui::{Modifiers, Pos2, Rect, UiBuilder, Vec2}; + +use crate::ui::channels::{ChannelKind, ChannelRow, ChannelsPanel}; + +const PANEL: Vec2 = Vec2::new(320.0, 400.0); + +/// What a host's view of the panel reads: its rows, which the host's revision stands for. +#[derive(MemoProps)] +struct Host<'a> { + revision: u64, + #[memo_props(covered_by = "revision", reason = "the rows are fixed in this trial")] + rows: &'a [ChannelRow], +} + +fn host(props: &mut Host<'_>, ui: &mut egui::Ui) { + let _ = ChannelsPanel::new(props.rows).show(ui); +} + +/// The panel reads the modifiers its commands take, not the pointer: a pointer move beside it replays its view, and a +/// modifier change runs it. Before, every pointer move in the window ran it. +#[trial] +fn a_pointer_move_beside_the_panel_replays_it_and_a_modifier_runs_it() { + let rows = + [(0, ChannelKind::Composite, "RGB"), (1, ChannelKind::Color, "Red"), (2, ChannelKind::Color, "Green"), (3, ChannelKind::Color, "Blue")] + .map(|(key, kind, name)| ChannelRow::new(key, kind, name)); + let mut fixture = Fixture::new(move |ui| { + let at = Rect::from_min_size(ui.max_rect().min, PANEL); + ui.scope_builder(UiBuilder::new().max_rect(at), |ui| { + MemoView::new("channels", Host { revision: 0, rows: &rows }, host).show(ui); + }); + }); + fixture.room(Vec2::new(PANEL.x + 400.0, PANEL.y)).settle().idle(2); + let runs = |fixture: &Fixture| { + let runs = last_frame_memo_runs(fixture.ctx()); + let count = |wanted: MemoRun| runs.iter().filter(|(name, _, run)| name.contains("Host") && *run == wanted).count(); + (count(MemoRun::Ran), count(MemoRun::Replayed)) + }; + // The pointer enters the window beside the panel; in an app it is already there. + fixture.frame(vec![pointer::moved(Pos2::new(PANEL.x + 200.0, 90.0))]); + for step in 0..3 { + fixture.frame(vec![pointer::moved(Pos2::new(PANEL.x + 200.0, 100.0 + step as f32 * 10.0))]); + assert_eq!(runs(&fixture), (0, 1), "pointer move {step} beside the panel replays its view"); + } + fixture.hold(Modifiers::ALT).frame(Vec::new()); + assert_eq!(runs(&fixture).0, 1, "Alt held runs the view"); + fixture.frame(Vec::new()); + assert_eq!(runs(&fixture), (0, 1), "and it replays while Alt stays held"); +} diff --git a/crates/imaging/tests/it/main.rs b/crates/imaging/tests/it/main.rs index 2a7b0442b..250998236 100644 --- a/crates/imaging/tests/it/main.rs +++ b/crates/imaging/tests/it/main.rs @@ -4,6 +4,7 @@ pub(crate) mod adjust_editors; pub(crate) mod adjust_tone; pub(crate) mod blur_pins; pub(crate) mod channels_delete; +pub(crate) mod channels_memo; pub(crate) mod color_range; pub(crate) mod contour_field; pub(crate) mod curve; diff --git a/crates/layers/src/ui/panel/body.rs b/crates/layers/src/ui/panel/body.rs index 155359e35..94c6371a4 100644 --- a/crates/layers/src/ui/panel/body.rs +++ b/crates/layers/src/ui/panel/body.rs @@ -76,9 +76,7 @@ pub(super) fn show_body( .columns(columns) .selection(Bind::bound(&mut selection)) .can_rename(|key| matches!(key, LayerRowKey::Layer(id) if tree.info(id).renamable)) - .accepts(|drag: &ListDrag>, _over, insert| { - accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::frame(&ctx).mods) - }) + .accepts(|drag: &ListDrag>, _over, insert| accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::mods(&ctx))) .drag_payload({ let document = cx.document; move |drag: &ListDrag>| Some(LayersDrag::of_rows(drag, document)) diff --git a/crates/layers/src/ui/panel/mod.rs b/crates/layers/src/ui/panel/mod.rs index 65073fec8..21f08aff0 100644 --- a/crates/layers/src/ui/panel/mod.rs +++ b/crates/layers/src/ui/panel/mod.rs @@ -378,7 +378,7 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> { lock_column, visibility_key, trailing: trailing.as_deref(), - held: craft_ui::runtime::pointer::frame(ui.ctx()).mods, + held: craft_ui::runtime::pointer::mods(ui.ctx()), }; let events = RefCell::new(Vec::new()); let current = RefCell::new(LayerFilter::default()); diff --git a/crates/layers/tests/it/panel_memo.rs b/crates/layers/tests/it/panel_memo.rs index 5f72626bf..753c3f8e4 100644 --- a/crates/layers/tests/it/panel_memo.rs +++ b/crates/layers/tests/it/panel_memo.rs @@ -132,3 +132,35 @@ fn a_clicks_event_is_delivered_once_across_the_run_and_the_replays() { let selects = rig.seen.borrow().iter().filter(|event| matches!(event, LayersEvent::Select(_))).count(); assert_eq!(selects, 1, "{:?}", rig.seen.borrow()); } + +/// A pointer move beside the panel replays its view: the panel reads the modifiers it shows its rows with, not the +/// pointer, so only a modifier change runs it (#2812). Before, every pointer move in the window ran it. +#[trial] +fn a_pointer_move_beside_the_panel_replays_it_and_a_modifier_runs_it() { + let tree = Tracked::new(FakeLayers::fifty()); + let mut fixture = Fixture::new(move |ui| { + let mut filter = LayerFilter::default(); + let mut events = Vec::new(); + let at = egui::Rect::from_min_size(ui.max_rect().min, PANEL); + ui.scope_builder(egui::UiBuilder::new().max_rect(at), |ui| { + MemoView::new("layers", Host { tree: &tree, filter: Bind::bound(&mut filter), events: Outbox::new(&mut events) }, host).show(ui); + }); + }); + fixture.room(Vec2::new(PANEL.x + 400.0, PANEL.y)); + fixture.settle().idle(2); + let runs = |fixture: &Fixture| { + let runs = last_frame_memo_runs(fixture.ctx()); + let count = |wanted: MemoRun| runs.iter().filter(|(name, _, run)| name.contains("Host") && *run == wanted).count(); + (count(MemoRun::Ran), count(MemoRun::Replayed)) + }; + // The pointer enters the window beside the panel; in an app it is already there. + fixture.frame(vec![pointer::moved(egui::Pos2::new(PANEL.x + 200.0, 90.0))]); + for step in 0..3 { + fixture.frame(vec![pointer::moved(egui::Pos2::new(PANEL.x + 200.0, 100.0 + step as f32 * 10.0))]); + assert_eq!(runs(&fixture), (0, 1), "pointer move {step} beside the panel replays its view"); + } + fixture.hold(egui::Modifiers::ALT).frame(Vec::new()); + assert_eq!(runs(&fixture).0, 1, "Alt held runs the view"); + fixture.frame(Vec::new()); + assert_eq!(runs(&fixture), (0, 1), "and it replays while Alt stays held"); +} diff --git a/crates/table/src/ui/conditions.rs b/crates/table/src/ui/conditions.rs index 3c75105a8..d415433d5 100644 --- a/crates/table/src/ui/conditions.rs +++ b/crates/table/src/ui/conditions.rs @@ -445,7 +445,7 @@ impl Rows<'_> { .id_salt((path.to_vec(), "add")) .show(ui); if clicked(&plus) { - let group = pointer::frame(ui.ctx()).mods.alt && depth < MAX_DEPTH; + let group = pointer::mods(ui.ctx()).alt && depth < MAX_DEPTH; let item = if group { ConditionItem::Group(self.new_group()) } else { ConditionItem::Rule(self.new_rule()) }; *insert = Some((at + 1, item)); } diff --git a/crates/text/src/ui/style_panel.rs b/crates/text/src/ui/style_panel.rs index dbd74a307..2a5b7e070 100644 --- a/crates/text/src/ui/style_panel.rs +++ b/crates/text/src/ui/style_panel.rs @@ -407,9 +407,9 @@ impl<'a> TextStylesPanel<'a> { }); let (events, second) = (shown_rows.events, shown_rows.activation_clicks >= 2); - let pointer = craft_ui::runtime::pointer::frame(ui.ctx()); - let alt = pointer.mods.alt; - let plain = !pointer.mods.shift && !pointer.mods.cmd; + let mods = craft_ui::runtime::pointer::mods(ui.ctx()); + let alt = mods.alt; + let plain = !mods.shift && !mods.cmd; for event in events { match event { CollectionEvent::Activate(id) if second && (id != 0 || paragraph) => action.set(Some(TextStyleAction::Options(id))), diff --git a/crates/ui-canvas/src/canvas_controls/guides/mod.rs b/crates/ui-canvas/src/canvas_controls/guides/mod.rs index 47899d7a9..0fd6e4fb6 100644 --- a/crates/ui-canvas/src/canvas_controls/guides/mod.rs +++ b/crates/ui-canvas/src/canvas_controls/guides/mod.rs @@ -479,7 +479,7 @@ impl Component for Guides<'_> { /// `run_pointer` reads only declared parts, so this is the one gate of the pointer. fn parts(&mut self, rect: egui::Rect, cx: &mut PartsCx<'_, Self>) { let held = cx.press_slot::().is_some() || cx.gesture_running(); - let takes = self.interactive || (self.moves_with_command && (crate::runtime::pointer::frame(cx.ui.ctx()).mods.cmd || held)); + let takes = self.interactive || (self.moves_with_command && (crate::runtime::pointer::mods(cx.ui.ctx()).cmd || held)); let (Some(space), Some(guides), true) = (canvas_space(&cx.env), cx.value(), takes) else { return }; let mut any = false; for &at in &place::keyboard_order(guides) { diff --git a/crates/ui-panels/src/docking/drop.rs b/crates/ui-panels/src/docking/drop.rs index b08d63c16..887a46116 100644 --- a/crates/ui-panels/src/docking/drop.rs +++ b/crates/ui-panels/src/docking/drop.rs @@ -326,7 +326,7 @@ impl DockDropTarget<'_, P> { } let unit = drag.unit(self.layout)?; let window = matches!(unit, DragUnit::Window(_)); - if pointer::frame(self.ctx).mods.cmd { + if pointer::mods(self.ctx).cmd { return if window { None } else { self.float(&unit, at, drag.source(), drag.strip()) }; } if window && !self.title_bar_docks { diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index d983d9722..07c093c1f 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -681,7 +681,7 @@ impl FooterBar { } }); let inner = shown.inner.unwrap_or_default(); - let mods = if inner.picked.is_some() { crate::runtime::pointer::frame(ui.ctx()).mods } else { craft_keymap::Mods::NONE }; + let mods = if inner.picked.is_some() { crate::runtime::pointer::mods(ui.ctx()) } else { craft_keymap::Mods::NONE }; let output = FooterOutput { response: shown.output, picked: inner.picked, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs index 1a0caefeb..69d9af12a 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/dialog.rs @@ -638,7 +638,7 @@ impl ResetFooter { pub fn new(ui: &Ui, cancel: Option