Lists: stacking keys move the rows a drag takes; a held release asks for its pass

key_reorder takes the rows acted_on names, so a stacking key on a selected sub-row moves that sub-row and not its
row. While a press holds a release for a later pass, sensing asks for a repaint, so the release goes out in the next
frame without new input.
This commit is contained in:
aiongg
2026-11-12 22:02:35 +00:00
parent 70dfca7f24
commit ff3638f870
7 changed files with 53 additions and 19 deletions
+3 -2
View File
@@ -113,8 +113,9 @@ pub trait ItemSource<K>: DisplayOrder<K> {
/// `Some(steps)` when entry `at` is a sub-row of an entry above it (a layer's effects): a compact row whose toggle
/// cells sit in its content, `steps` indent steps from its start, instead of in their columns (`sub_row_cells`).
/// A press flips them there, and a sweep down the toggle columns passes them by. A drag or Delete of a selected
/// sub-row takes the selected sub-rows only, and one of any other selected row the selected rows that are not sub-rows.
/// A press flips them there, and a sweep down the toggle columns passes them by. A drag, stacking key or Delete on
/// a selected sub-row takes the selected sub-rows only; on any other selected row it takes the selected rows that
/// are not sub-rows.
fn sub_row(&self, _at: usize) -> Option<usize> {
None
}
+6
View File
@@ -496,6 +496,12 @@ impl<T: Copy> PressMachine<T> {
self.open.is_some_and(|open| open.dragging)
}
/// Whether the button went up and the release waits for a later pass, which the caller must ask for: no input may
/// come to start it.
pub fn release_held(&self) -> bool {
self.open.is_some_and(|open| open.released_at.is_some())
}
/// Runs one pass. `pick` chooses the press winner and what it senses at a press position; it returns `None`
/// when no shape of this root takes the press.
pub fn step(&mut self, input: PassInput<'_>, mut pick: impl FnMut(Pos2) -> Option<(T, Sense)>) -> PressStep<T> {
+20 -1
View File
@@ -5,7 +5,7 @@ use craft_behavior::{EditEvent, SelectionChange};
use craft_layers::testing;
use craft_layers::ui::mock::{FakeLayers, sub_row};
use craft_layers::ui::panel::{ActivateOn, LayerDrop, LayersEvent, LayersPanel, MaskMove};
use craft_layers::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerSelection, MaskInfo, SubRow, SubRows};
use craft_layers::ui::tree::{LayerInfo, LayerKind, LayerPart, LayerRowKey, LayerSelection, MaskInfo, SubRow, SubRowGroup, SubRows};
use craft_ui::testing::{Fixture, Target, pointer, trial};
use egui::{Key, Modifiers, Vec2};
use std::cell::RefCell;
@@ -265,6 +265,7 @@ fn a_smart_filter_row_dragged_onto_another_smart_object_moves_there() {
})
.collect();
assert_eq!(transfers, [(vec![LayerRowKey::Filters(SMART, Some(0))], other, false)], "{events:?}");
// The rig applies selections only, so the filter stays on its layer and its row stays selected for this drag.
let from = node(&fixture, "Smart Object").center();
fixture.drag_hold_at(from, to - from).release_at(to).idle(2);
let events = take(&app);
@@ -277,3 +278,21 @@ fn a_smart_filter_row_dragged_onto_another_smart_object_moves_there() {
.collect();
assert_eq!(moved, [vec![SMART]], "{events:?}");
}
/// A stacking key on a selected Smart Filter row, selected beside its layer, moves that filter within its stack.
#[trial]
fn a_stacking_key_on_a_selected_smart_filter_row_moves_the_filter() {
let (mut fixture, app) = rig(tree());
fixture.click(&node(&fixture, "Gaussian Blur")).idle(2);
take(&app);
fixture.key(Key::OpenBracket, Modifiers::COMMAND).idle(2);
let events = take(&app);
let moves: Vec<_> = events
.iter()
.filter_map(|event| match event {
LayersEvent::Drop(EditEvent::Set { after: LayerDrop::SubRows(mv), .. }) => Some((mv.layer, mv.group, mv.from, mv.to)),
_ => None,
})
.collect();
assert_eq!(moves, [(SMART, SubRowGroup::SmartFilters, 0, 1)], "{events:?}");
}
@@ -408,7 +408,7 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
fn begin_row_drag(&mut self, cx: &mut Cx<'_, C>, props: &CollectionProps, at: usize) {
let id = cx.core.id;
let key = self.source.key(at);
let keys = self.acted_on(at);
let keys = self.keys_at(&self.acted_on(at));
let count = keys.len() as u64;
let preview = match props.drag_count {
Some(word) => DragPreview::Badge(Label::from(cx.env.counted(word, count))),
@@ -621,13 +621,13 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
}
}
/// A stacking key on the lead row `at`: the selection moves when the lead is in it, else the lead, as a row drag
/// takes them (`reorder::key_move`).
/// A stacking key on the lead row `at`: the rows `acted_on` names move, as a row drag takes them
/// (`reorder::key_move`).
pub(super) fn key_reorder(&mut self, cx: &mut Cx<'_, C>, props: &CollectionProps, at: usize, mv: reorder::ItemMove) {
let groups = props.reorder.is_some_and(|rule| rule.into_groups);
let outline = Outline::new(self.source);
let tree = groups.then_some(&outline as &dyn craft_behavior::NavOutline);
let mut places: Vec<usize> = if self.holds(at) { self.placed().rows() } else { vec![at] };
let mut places = self.acted_on(at);
places.sort_unstable();
// A selected row inside another selected row moves with it.
if groups {
@@ -653,7 +653,7 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
if to == from && together && parent == held {
return;
}
let keys: Vec<C::Key> = places.iter().map(|&place| self.source.key(place)).collect();
let keys = self.keys_at(&places);
let key = self.source.key(at);
let before = ReorderMove::new(key.clone(), keys.clone(), from, false).in_group(held);
let after = ReorderMove::new(key, keys, to, false).in_group(parent);
@@ -175,9 +175,8 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
}
}
/// Delete and Backspace at the lead of a `deletable` collection: the request names the selected items of the lead's
/// kind (rows or sub-rows) when the lead is one of them, else the lead alone. The keys stay untaken (shortcut candidates) in a collection that is not
/// `deletable`.
/// Delete and Backspace at the lead of a `deletable` collection: the request names the rows `acted_on` names. The
/// keys stay untaken (shortcut candidates) in a collection that is not `deletable`.
pub(super) fn delete_key(&mut self, cx: &mut Cx<'_, C>, props: &CollectionProps, lead_at: Option<usize>) {
if !props.deletable {
return;
@@ -185,7 +184,7 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
let forward = cx.core.intents.take_exact(&Intent::delete(true, Granularity::Unit));
let back = cx.core.intents.take_exact(&Intent::delete(false, Granularity::Unit));
let Some(row) = lead_at.filter(|_| forward || back) else { return };
self.events.push(CollectionEvent::Delete(self.acted_on(row)));
self.events.push(CollectionEvent::Delete(self.keys_at(&self.acted_on(row))));
}
/// Space on the lead row `row`, as `CollectionProps.space` says.
+11 -6
View File
@@ -100,15 +100,20 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
selection.placed(self.source).rows().into_iter().map(|at| self.source.key(at)).collect()
}
/// The keys a gesture on the row at `at` acts on, in the display order: the selected rows of its kind when the
/// selection holds it (sub-rows for a sub-row, the other rows for any other row), else that row alone. A sub-row
/// belongs to the row above it, so the two kinds never move or go together.
pub(super) fn acted_on(&self, at: usize) -> Vec<C::Key> {
/// The positions a gesture on the row at `at` (a drag, a stacking key, Delete) acts on, in the display order: the
/// selected rows of its kind when the selection holds it (sub-rows for a sub-row, the other rows for any other
/// row), else that row alone. A sub-row belongs to the row above it, so the two kinds never move or go together.
pub(super) fn acted_on(&self, at: usize) -> Vec<usize> {
if !self.holds(at) {
return vec![self.source.key(at)];
return vec![at];
}
let sub = self.source.sub_row(at).is_some();
self.placed().rows().into_iter().filter(|row| self.source.sub_row(*row).is_some() == sub).map(|row| self.source.key(row)).collect()
self.placed().rows().into_iter().filter(|row| self.source.sub_row(*row).is_some() == sub).collect()
}
/// The keys of the rows at `places`.
pub(super) fn keys_at(&self, places: &[usize]) -> Vec<C::Key> {
places.iter().map(|&at| self.source.key(at)).collect()
}
/// A pick of the rows `from` to `to` in a model of cells: one range of whole rows (the rows' cells in every column
+5 -1
View File
@@ -722,7 +722,7 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab
// Hover needs the root's layer on top under the pointer, or egui's layer cover (a popup) would be ignored.
let top = pass_pointer.hover.and_then(|at| areas::layer_at(ctx, at));
let hover_layer_ok = top.is_some_and(|top| top == layer || Some(top) == body_layer);
let mut cancelled = false;
let (mut cancelled, mut release_held) = (false, false);
let outcome = with_arena(ctx, arena, pass_nr, |state| {
let root = state.root.unwrap_or(RootInfo { id: Id::NULL, rect: Rect::NOTHING, own_sense: Sense::empty() });
let pos = pos.unwrap_or(Pos2::ZERO);
@@ -769,6 +769,7 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab
hit.map(|hit| (hit, hit.sense))
});
cancelled = matches!(step.phase, Some(PressPhase::Cancel { .. }));
release_held = machine.release_held();
let open = machine.target();
let dragging = step.dragging;
state.machine = machine;
@@ -786,6 +787,9 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab
if cancelled {
crate::runtime::frame::note_cancelled_press(ctx);
}
if release_held {
crate::runtime::egui::repaint::request(ctx);
}
outcome
}