Layers and Channels panels read the modifiers, not the pointer frame (#2812)

Both panels read pointer::frame(..).mods on every pass: the Layers
panel for its rows' held modifiers and its drop test, the Channels
panel before it takes its commands. pointer::frame notes the pointer
as a tracked input, so a memoized view holding either panel ran on
every pointer move in the window. pointer::mods reads the same
modifiers and notes only the modifiers.

Trials: a pointer move beside each panel replays its host view and Alt
held runs it; both fail without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-21 12:28:28 +01:00
1 parent 2946b2041a
commit ec5bcc602d
6 files changed
+88 -5

No files matched your search

+1 -1
View File
@@ -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::<ChannelsCommands>() {
match (command, targeted_row(rows)) {
(ChannelsCommands::RenameChannel, Some(row)) if row.kind.renames() => request_rename(&ctx, list, &row.key),
+52
View File
@@ -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<u8>],
}
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");
}
+1
View File
@@ -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;
+1 -3
View File
@@ -76,9 +76,7 @@ pub(super) fn show_body<T: LayerTree>(
.columns(columns)
.selection(Bind::bound(&mut selection))
.can_rename(|key| matches!(key, LayerRowKey::Layer(id) if tree.info(id).renamable))
.accepts(|drag: &ListDrag<LayerRowKey<T::Id>>, _over, insert| {
accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::frame(&ctx).mods)
})
.accepts(|drag: &ListDrag<LayerRowKey<T::Id>>, _over, insert| accepts_drop(tree, drag, order, insert, craft_ui::runtime::pointer::mods(&ctx)))
.drag_payload({
let document = cx.document;
move |drag: &ListDrag<LayerRowKey<T::Id>>| Some(LayersDrag::of_rows(drag, document))
+1 -1
View File
@@ -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());
+32
View File
@@ -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");
}