mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Every panel and widget reads the modifiers, not the pointer frame (#2812)
The same read as in the Layers and Channels panels: pointer::frame(..).mods notes the pointer as a tracked input, so a memoized view holding the component ran on every pointer move in the window. pointer::mods returns the same modifiers and notes only the modifiers. Fifteen more sites read the frame for its modifiers only (the preset browser, the tile grid, the section footer, the dock's drop, the canvas guides, the crop tool, the bins, Color Range, the raw develop dialog, the table conditions, the form dialogs, Save for Web) and the text style panel; each reads pointer::mods now. The preset browser also reads the pointer's buttons, press and release for its rows' events; it reads the frame only when there are events, so a pass without one does not depend on the pointer. In PhotoCraft this left Swatches, Gradients, Patterns, Styles, Shapes, Tool Presets, Character and Paragraph Styles, Brushes and Glyphs running on every pointer move over the canvas; with the change every docked panel replays. Trial: the preset browser in a host view replays on a pointer move beside it, in its list view (fails without the browser change) and its tile view (fails without the tile grid change), and Alt held runs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ec5bcc602d
commit
3b572a3954
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<ColumnKey> = 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::<TileWords>();
|
||||
if let Some(key) = rename {
|
||||
request_rename(ui.ctx(), id, &key);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -223,7 +223,7 @@ impl<'a> ColorRangeDialog<'a> {
|
||||
let preview_words = env.words::<SelectionWords>();
|
||||
// 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);
|
||||
|
||||
@@ -524,7 +524,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
|
||||
let words = env.words::<RawDevelopWords>();
|
||||
let common = env.words::<CommonWords>();
|
||||
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() };
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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))),
|
||||
|
||||
@@ -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::<HeldGuide>().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) {
|
||||
|
||||
@@ -326,7 +326,7 @@ impl<P: Clone + Eq + Hash + Send + 'static> 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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -636,7 +636,7 @@ impl ResetFooter {
|
||||
pub fn new(ui: &Ui, cancel: Option<Label>, alt_resets: bool) -> Self {
|
||||
let env = Env::of(ui);
|
||||
ResetFooter {
|
||||
resetting: alt_resets && crate::runtime::pointer::frame(ui.ctx()).mods.alt,
|
||||
resetting: alt_resets && crate::runtime::pointer::mods(ui.ctx()).alt,
|
||||
cancel: cancel.unwrap_or_else(|| env.words::<CommonWords>().cancel.clone()),
|
||||
reset: env.words::<ParamDialogWords>().reset.clone(),
|
||||
extra: Vec::new(),
|
||||
|
||||
@@ -154,7 +154,7 @@ fn one_pane(ui: &mut Ui, panes: &Panes<'_>, live: &Live, pane: WebPane, at: usiz
|
||||
if let Some(point) = shown.clicked
|
||||
&& let Some(number) = slice_at(panes.slices, point)
|
||||
{
|
||||
reported.slice = Some(SliceClick { number, add: crate::runtime::pointer::frame(ui.ctx()).mods.shift });
|
||||
reported.slice = Some(SliceClick { number, add: crate::runtime::pointer::mods(ui.ctx()).shift });
|
||||
}
|
||||
if reported.moved.is_none() {
|
||||
reported.moved = shown.view;
|
||||
|
||||
@@ -812,7 +812,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
|
||||
(out.response.clone(), shown.clone(), Pass { seen: seen(out.events), grid: Vec::new() })
|
||||
};
|
||||
|
||||
let mods = crate::runtime::pointer::frame(ui.ctx()).mods;
|
||||
let mods = crate::runtime::pointer::mods(ui.ctx());
|
||||
let row_of = |key: &K| rows.iter().position(|row| row.key == *key);
|
||||
if let Some(zone) = drop_zone {
|
||||
let target = ZoneDrop { source: response.id, rows, zone };
|
||||
@@ -848,15 +848,18 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> PresetBrowser<'_, K> {
|
||||
}
|
||||
// A secondary press or release selects the row it lands on so that the row's menu acts on it; that selection
|
||||
// is not a pick, and a picker would commit it.
|
||||
let frame = crate::runtime::pointer::frame(ui.ctx());
|
||||
let secondary =
|
||||
frame.buttons.contains(craft_behavior::Buttons::SECONDARY) || frame.release == Some(craft_behavior::PointerButton::Secondary);
|
||||
// The pointer is read only for the rows' events: a pass without one does not depend on it, so a memoized view
|
||||
// holding the list replays while the pointer moves elsewhere (#2812).
|
||||
let frame = (!pass.seen.is_empty()).then(|| crate::runtime::pointer::frame(ui.ctx()));
|
||||
let secondary = frame.as_ref().is_some_and(|frame| {
|
||||
frame.buttons.contains(craft_behavior::Buttons::SECONDARY) || frame.release == Some(craft_behavior::PointerButton::Secondary)
|
||||
});
|
||||
// An action row of the list is a plain row: a single press picks it, and Enter activates it. Its selection by
|
||||
// an arrow key, and the activation by the second click of a double click, are not a choice. The grid's
|
||||
// tail rows report Enter and a click as their activation.
|
||||
let list = view == PresetView::List;
|
||||
let first_press = frame.press.as_ref().is_some_and(|press| press.clicks == 1);
|
||||
let released = frame.release.is_some();
|
||||
let first_press = frame.as_ref().and_then(|frame| frame.press.as_ref()).is_some_and(|press| press.clicks == 1);
|
||||
let released = frame.as_ref().is_some_and(|frame| frame.release.is_some());
|
||||
let action = |events: &mut Vec<PresetEvent<K>>, at: usize| {
|
||||
if !events.contains(&PresetEvent::Action(at)) {
|
||||
events.push(PresetEvent::Action(at));
|
||||
|
||||
@@ -125,3 +125,53 @@ fn delete_and_backspace_on_a_selected_preset_report_delete() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What a host's view of the browser reads: its rows and its state, which the host's revision stands for.
|
||||
#[derive(craft_ui::contract::MemoProps)]
|
||||
struct Host<'a> {
|
||||
revision: u64,
|
||||
#[memo_props(covered_by = "revision", reason = "the rows are fixed in this trial")]
|
||||
rows: &'a [PresetRow<u32>],
|
||||
#[memo_props(covered_by = "revision", reason = "nothing writes the state in this trial")]
|
||||
state: &'a mut PresetState<u32>,
|
||||
#[memo_props(hash = "a fieldless enum")]
|
||||
view: PresetView,
|
||||
}
|
||||
|
||||
fn host(props: &mut Host<'_>, ui: &mut egui::Ui) {
|
||||
let _ = PresetBrowser::new("Patterns", Bind::bound(props.state), props.rows).view_lock(props.view).show(ui);
|
||||
}
|
||||
|
||||
/// The browser reads the modifiers its picks take, and the pointer only for its rows' own events: a pointer move
|
||||
/// beside it replays its view in both views, and a modifier change runs it (#2812). Before, every pointer move in
|
||||
/// the window ran it.
|
||||
#[trial]
|
||||
fn a_pointer_move_beside_the_browser_replays_it_and_a_modifier_runs_it() {
|
||||
use craft_ui::contract::MemoView;
|
||||
use craft_ui::testing::{MemoRun, last_frame_memo_runs, pointer};
|
||||
for view in [PresetView::List, PresetView::Grid] {
|
||||
let rows = vec![PresetRow::group(GROUP, "Group", 0), PresetRow::item(ALPHA, "Alpha", 1), PresetRow::item(2, "Beta", 1)];
|
||||
let mut state = PresetState::<u32>::new();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
ui.scope_builder(UiBuilder::new().max_rect(BROWSER), |ui| {
|
||||
MemoView::new("browser", Host { revision: 0, rows: &rows, state: &mut state, view }, host).show(ui);
|
||||
});
|
||||
});
|
||||
fixture.room(vec2(480.0, 320.0)).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 browser; in an app it is already there.
|
||||
fixture.frame(vec![pointer::moved(pos2(360.0, 90.0))]);
|
||||
for step in 0..3 {
|
||||
fixture.frame(vec![pointer::moved(pos2(360.0, 100.0 + step as f32 * 10.0))]);
|
||||
assert_eq!(runs(&fixture), (0, 1), "{view:?}: pointer move {step} beside the browser replays its view");
|
||||
}
|
||||
fixture.hold(Modifiers::ALT).frame(Vec::new());
|
||||
assert_eq!(runs(&fixture).0, 1, "{view:?}: Alt held runs the view");
|
||||
fixture.frame(Vec::new());
|
||||
assert_eq!(runs(&fixture), (0, 1), "{view:?}: and it replays while Alt stays held");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,7 +700,7 @@ impl<K: Clone + Eq + Hash + Send + Sync + 'static> Component for TileGrid<'_, K>
|
||||
let selected = self.rated(&cx);
|
||||
let mut response = cx.collection_response();
|
||||
let mut events = self.events;
|
||||
let mods = crate::runtime::pointer::frame(&cx.core.ctx).mods;
|
||||
let mods = crate::runtime::pointer::mods(&cx.core.ctx);
|
||||
let group_of = |key: &K| self.groups.iter().position(|group| group.key == *key);
|
||||
let is_tail = |key: &K| self.tail.iter().any(|row| row.key == *key);
|
||||
let mut kept = Vec::with_capacity(response.events.len());
|
||||
|
||||
Reference in New Issue
Block a user