mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-24 19:41:51 +01:00
Merge pull request #2830 from davidmann4/fix/2812-panels-read-mods
Panels and widgets read the modifiers, not the pointer frame
This commit is contained in:
21 files changed
+154
-22
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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() };
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -638,7 +638,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;
|
||||
|
||||
@@ -134,3 +134,52 @@ 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 PresetSource<'a, 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 pointer and the modifiers only for its rows' own events, and its tile grid reads the
|
||||
/// modifiers, not the pointer frame: a pointer move beside it replays its view in both views (#2812). Before, every
|
||||
/// pointer move in the window ran it.
|
||||
#[trial]
|
||||
fn a_pointer_move_beside_the_browser_replays_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 = PresetSource::new(
|
||||
(),
|
||||
PresetFns::new(|_, _| 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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