mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
Collection response reports the drop a release would make: PendingDrop (own reorder, items from another collection, OS files) while the collection's target wins; LayersPanel previews it as drop_preview, PageThumbnails reports drop_target and file_gap
This commit is contained in:
@@ -10,15 +10,17 @@ pub(in crate::ui::panel) use rows::{LayerRows, ToggleSweeps, reveal_plan};
|
||||
use rows::{RevealPlan, list_selection};
|
||||
|
||||
use craft_behavior::{ColumnWidth, IconId};
|
||||
use craft_ui::contract::{Bind, CollectionEvent, ColumnKind, ColumnSpec, ListDrag, Props as _, ReorderRule, ShowCollection as _, ToggleColumn};
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ColumnKind, ColumnSpec, ListDrag, PendingDrop, Props as _, ReorderRule, ShowCollection as _, ToggleColumn,
|
||||
};
|
||||
use craft_ui::list::List;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use egui::Ui;
|
||||
|
||||
use super::Session;
|
||||
use super::context::PanelContext;
|
||||
use super::drag::{LayersDrag, accepts_drop};
|
||||
use super::events::LayersEvent;
|
||||
use super::drag::{LayersDrag, accepts_drop, layer_drop};
|
||||
use super::events::{LayerDrop, LayerMove, LayersEvent};
|
||||
use super::row::{EYE, LOCK, NAME, build_row};
|
||||
use crate::ui::tree::{LayerRowKey, LayerTree};
|
||||
|
||||
@@ -26,6 +28,8 @@ use crate::ui::tree::{LayerRowKey, LayerTree};
|
||||
pub(super) struct BodyOutput<Id> {
|
||||
pub(super) events: Vec<LayersEvent<Id>>,
|
||||
pub(super) response: egui::Response,
|
||||
/// The layer move a release of the held rows would make, while the option to preview it is on.
|
||||
pub(super) drop_preview: Option<LayerMove<Id>>,
|
||||
}
|
||||
|
||||
/// Shows the list over `rows` and maps what it reports.
|
||||
@@ -84,6 +88,13 @@ pub(super) fn show_body<T: LayerTree>(
|
||||
});
|
||||
|
||||
let mut events: Vec<LayersEvent<T::Id>> = reveal.opens.iter().cloned().map(LayersEvent::Open).collect();
|
||||
let drop_preview = match &out.pending_drop {
|
||||
Some(PendingDrop::Reorder(mv)) if cx.options.preview_on_canvas_when_reordering => match layer_drop(mv, &order, &parent_of, filtered) {
|
||||
Some(LayerDrop::Layers(layers)) => Some(layers),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
let selection_changed = out.events.iter().any(|event| matches!(event, CollectionEvent::Selection(_)));
|
||||
let list_events = out.events;
|
||||
map_events(cx, &order, &parent_of, filtered, lock_name, session, list_events, &mut events);
|
||||
@@ -97,5 +108,5 @@ pub(super) fn show_body<T: LayerTree>(
|
||||
session.anchor = selection.anchor.as_ref().map(|key| LayerRowKey::Layer(key.layer().clone()));
|
||||
session.produced = layers;
|
||||
}
|
||||
BodyOutput { events, response: out.response }
|
||||
BodyOutput { events, response: out.response, drop_preview }
|
||||
}
|
||||
|
||||
@@ -171,6 +171,9 @@ pub struct LayersPanel<'a, T: LayerTree> {
|
||||
pub struct LayersOutput<Id> {
|
||||
/// What the user did this pass, in order.
|
||||
pub events: Vec<LayersEvent<Id>>,
|
||||
/// While rows are dragged and Preview on Canvas When Reordering Layers is on, the layer move the release would
|
||||
/// make, for the app's canvas preview; `None` otherwise.
|
||||
pub drop_preview: Option<LayerMove<Id>>,
|
||||
/// The panel.
|
||||
pub response: Response,
|
||||
}
|
||||
@@ -349,11 +352,12 @@ impl<'a, T: LayerTree> LayersPanel<'a, T> {
|
||||
while let Some((key, _)) = stack.take_command::<LayersPanelKeys>() {
|
||||
reported.extend(key.event(tree));
|
||||
}
|
||||
reported
|
||||
(reported, body.drop_preview)
|
||||
});
|
||||
// Only the real run's result comes back, so the reveal's opens and the list's events are reported once.
|
||||
let mut events = events.into_inner();
|
||||
events.extend(shown.inner.unwrap_or_default());
|
||||
LayersOutput { events, response: shown.output }
|
||||
let (body, drop_preview) = shown.inner.unwrap_or_default();
|
||||
events.extend(body);
|
||||
LayersOutput { events, drop_preview, response: shown.output }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use super::view::PageSource;
|
||||
use craft_behavior::{EditEvent, IconId, Selection, SelectionChange, keyed};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{
|
||||
Bind, CollectionEvent, ContextMenuRequest, NoValue, Outcome, ReorderMove, ReorderRule, Show as _, ShowCollection as _, clicked,
|
||||
Bind, CollectionEvent, ContextMenuRequest, NoValue, Outcome, PendingDrop, ReorderMove, ReorderRule, Show as _, ShowCollection as _, clicked,
|
||||
};
|
||||
use craft_ui::list::ThumbAspect;
|
||||
use craft_ui::primitives::textures::{Priority, ThumbPaint, ThumbRequest, ThumbnailOptions, Thumbnails};
|
||||
@@ -156,6 +156,11 @@ pub struct PageThumbnailsOutput {
|
||||
pub response: Response,
|
||||
/// What happened this pass, in order.
|
||||
pub events: Vec<ThumbnailEvent>,
|
||||
/// While pages are dragged, the move their release would make.
|
||||
pub drop_target: Option<ReorderMove<usize>>,
|
||||
/// While files from the OS are held over the grid, the page they would land before (the page count after the
|
||||
/// last).
|
||||
pub file_gap: Option<usize>,
|
||||
}
|
||||
|
||||
impl Outcome for PageThumbnailsOutput {
|
||||
@@ -331,6 +336,11 @@ impl<'a> PageThumbnails<'a> {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let (drop_target, file_gap) = match shown.response.pending_drop {
|
||||
Some(PendingDrop::Reorder(mv)) => (Some(mv), None),
|
||||
Some(PendingDrop::Files { insert }) => (None, Some(insert)),
|
||||
_ => (None, None),
|
||||
};
|
||||
for event in shown.response.events {
|
||||
match event {
|
||||
CollectionEvent::Selection(change) => events.push(ThumbnailEvent::Selection(change)),
|
||||
@@ -356,7 +366,7 @@ impl<'a> PageThumbnails<'a> {
|
||||
if new_page_row && clicked(&Button::new(words.new_page.clone()).show(ui)) {
|
||||
events.push(ThumbnailEvent::NewPage);
|
||||
}
|
||||
PageThumbnailsOutput { response: shown.response.response, events }
|
||||
PageThumbnailsOutput { response: shown.response.response, events, drop_target, file_gap }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,5 @@ pub use props::{
|
||||
ActivateOn, CollectionProps, DragPayload, ItemKeys, LeadOnOpen, LeadSource, ReorderRule, RowPressed, RowState, SelectMode, SpaceAction,
|
||||
};
|
||||
pub(crate) use response::Gestures;
|
||||
pub use response::{CollectionResponse, ShownRow};
|
||||
pub(crate) use response::ItemsOut;
|
||||
pub use response::{CollectionResponse, PendingDrop, ShownRow};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! A collection's output: `CollectionResponse`, the rows it showed and the gestures it allows.
|
||||
|
||||
use super::events::CollectionEvent;
|
||||
use super::events::{CollectionEvent, ReorderMove};
|
||||
use super::props::{CollectionProps, SelectMode};
|
||||
use craft_behavior::ColumnKey;
|
||||
use egui::Response;
|
||||
@@ -27,12 +27,36 @@ pub struct CollectionResponse<K, E> {
|
||||
/// The click count of the press behind this pass's `Activate`: 2 for the second click of a double click, 0 when a
|
||||
/// key or no pointer activated.
|
||||
pub activation_clicks: u8,
|
||||
/// While a drag is over the collection, the drop its release would make; `None` when the collection would take
|
||||
/// none. An app previews it (a layer move on the canvas); the drop itself comes as its event.
|
||||
pub pending_drop: Option<PendingDrop<K>>,
|
||||
}
|
||||
|
||||
/// The drop a release would make on a collection now.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PendingDrop<K> {
|
||||
/// The collection's own items move: the move `CollectionEvent::Reorder` would carry.
|
||||
Reorder(ReorderMove<K>),
|
||||
/// Items dragged from another collection land before `insert`, over `key` (none over an empty collection), as
|
||||
/// `CollectionEvent::Dropped` would report.
|
||||
Items {
|
||||
/// The item under the pointer.
|
||||
key: Option<K>,
|
||||
/// The position of the display order the items land before.
|
||||
insert: usize,
|
||||
},
|
||||
/// Files from the OS land before `insert`, as `CollectionEvent::FilesDropped` would report.
|
||||
Files {
|
||||
/// The position of the display order the files land before.
|
||||
insert: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl<K, E> CollectionResponse<K, E> {
|
||||
pub(crate) fn new(
|
||||
response: Response,
|
||||
(events, shown, activation_clicks): (Vec<CollectionEvent<K, E>>, Vec<ShownRow<K>>, u8),
|
||||
ItemsOut { events, shown, activation_clicks, pending_drop }: ItemsOut<K, E>,
|
||||
visible: Range<usize>,
|
||||
gestures: Gestures,
|
||||
) -> Self {
|
||||
@@ -45,6 +69,7 @@ impl<K, E> CollectionResponse<K, E> {
|
||||
rename: gestures.rename,
|
||||
reorder: gestures.reorder,
|
||||
activation_clicks,
|
||||
pending_drop,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +80,20 @@ impl<K, E> CollectionResponse<K, E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the item step hands to `collection_response`.
|
||||
pub(crate) struct ItemsOut<K, E> {
|
||||
pub(crate) events: Vec<CollectionEvent<K, E>>,
|
||||
pub(crate) shown: Vec<ShownRow<K>>,
|
||||
pub(crate) activation_clicks: u8,
|
||||
pub(crate) pending_drop: Option<PendingDrop<K>>,
|
||||
}
|
||||
|
||||
impl<K, E> Default for ItemsOut<K, E> {
|
||||
fn default() -> Self {
|
||||
ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The geometry of one row the collection showed this pass.
|
||||
#[derive(Clone, Debug)]
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
|
||||
use super::ItemsHooks;
|
||||
use super::marquee::MarqueeDrag;
|
||||
use crate::contract::collection::{CollectionEvent, CollectionProps, ColumnKind, ListDrag, ReorderMove, ToggleColumn, ToggleEdit};
|
||||
use crate::contract::collection::{CollectionEvent, CollectionProps, ColumnKind, ListDrag, PendingDrop, ReorderMove, ToggleColumn, ToggleEdit};
|
||||
use crate::contract::reorder;
|
||||
use crate::contract::{Collection, Cx, DragPreview, DropMark, DropTarget, OsFiles, Pointer as _};
|
||||
use crate::runtime::drag;
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::{
|
||||
Axis, CancelReason, ColumnKey, DropOperation, EditEvent, Flow, GestureId, ItemLayout, Mixed, NavShape, Outline, PointerButton, PressCancel,
|
||||
@@ -149,8 +150,8 @@ pub(super) struct Drags<K> {
|
||||
pub(super) grabbed: Option<K>,
|
||||
sweep: Option<Sweep<K>>,
|
||||
moving: Option<GestureId>,
|
||||
/// The row a drag from another collection would drop on this pass.
|
||||
pub(super) over: Option<K>,
|
||||
/// The drop a release would make this pass.
|
||||
pub(super) pending: Option<PendingDrop<K>>,
|
||||
/// The selected row a plain press landed on: a click on it narrows the selection to it, a drag keeps it.
|
||||
pub(super) collapse: Option<K>,
|
||||
/// The row whose rename column got a double press: the editor opens when the press ends as a click, not when it
|
||||
@@ -180,7 +181,7 @@ pub(super) struct SlowClick<K> {
|
||||
|
||||
impl<K> Default for Drags<K> {
|
||||
fn default() -> Self {
|
||||
Drags { grabbed: None, sweep: None, moving: None, over: None, collapse: None, rename: None, activate: None, marquee: None, slow: None }
|
||||
Drags { grabbed: None, sweep: None, moving: None, pending: None, collapse: None, rename: None, activate: None, marquee: None, slow: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,34 +428,44 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
false
|
||||
}
|
||||
|
||||
/// The move a drop of the collection's own `payload` at `landed` makes, before and after; `None` when it would
|
||||
/// leave every item where it is.
|
||||
fn own_move(&self, payload: &ListDrag<C::Key>, landed: Landed, groups: bool) -> Option<(ReorderMove<C::Key>, ReorderMove<C::Key>)> {
|
||||
// The moved items in display order, as they stand in the source now.
|
||||
let at: Vec<usize> =
|
||||
payload.keys.iter().filter_map(|key| self.index_of(key)).collect::<std::collections::BTreeSet<_>>().into_iter().collect();
|
||||
let &from = at.first()?;
|
||||
let to = reorder::move_all_to(&at, landed.spot.insert);
|
||||
let copy = matches!(landed.op, DropOperation::Copy);
|
||||
let together = at.iter().enumerate().all(|(n, &place)| place == from + n);
|
||||
let parent = landed.spot.parent.map(|row| self.source.key(row));
|
||||
let held = if groups { reorder::parent_of(&Outline::new(self.source), from).map(|row| self.source.key(row)) } else { None };
|
||||
if to == from && together && !copy && parent == held {
|
||||
return None;
|
||||
}
|
||||
let keys: Vec<C::Key> = at.iter().map(|&place| self.source.key(place)).collect();
|
||||
let key = payload.grabbed.clone();
|
||||
Some((ReorderMove::new(key.clone(), keys.clone(), from, false).in_group(held), ReorderMove::new(key, keys, to, copy).in_group(parent)))
|
||||
}
|
||||
|
||||
/// The drop `payload` makes at `landed`: a reorder of the collection's own items, or items from another one.
|
||||
fn drop_of(&self, own: bool, payload: &ListDrag<C::Key>, landed: Landed, groups: bool) -> Option<PendingDrop<C::Key>> {
|
||||
if own {
|
||||
return self.own_move(payload, landed, groups).map(|(_, after)| PendingDrop::Reorder(after));
|
||||
}
|
||||
let key = (!self.source.is_empty()).then(|| self.source.key(landed.spot.over));
|
||||
Some(PendingDrop::Items { key, insert: landed.spot.insert })
|
||||
}
|
||||
|
||||
fn land(&mut self, cx: &mut Cx<'_, C>, payload: &ListDrag<C::Key>, landed: Landed, groups: bool) {
|
||||
if payload.list != cx.core.id {
|
||||
let key = (!self.source.is_empty()).then(|| self.source.key(landed.spot.over));
|
||||
self.events.push(CollectionEvent::Dropped { key, insert: landed.spot.insert, op: landed.op, keys: payload.keys.clone() });
|
||||
return;
|
||||
}
|
||||
// The moved items in display order, as they stand in the source now.
|
||||
let at: Vec<usize> =
|
||||
payload.keys.iter().filter_map(|key| self.index_of(key)).collect::<std::collections::BTreeSet<_>>().into_iter().collect();
|
||||
let Some(&from) = at.first() else { return };
|
||||
let insert = landed.spot.insert;
|
||||
let to = reorder::move_all_to(&at, insert);
|
||||
let copy = matches!(landed.op, DropOperation::Copy);
|
||||
let together = at.iter().enumerate().all(|(n, &place)| place == from + n);
|
||||
let parent = landed.spot.parent.map(|row| self.source.key(row));
|
||||
let held = if groups { reorder::parent_of(&Outline::new(self.source), from).map(|row| self.source.key(row)) } else { None };
|
||||
if to == from && together && !copy && parent == held {
|
||||
return;
|
||||
if let Some((before, after)) = self.own_move(payload, landed, groups) {
|
||||
self.events.push(CollectionEvent::Reorder(EditEvent::set(Mixed::Same(before), after, cx.core.label_arc(), None)));
|
||||
}
|
||||
let keys: Vec<C::Key> = at.iter().map(|&place| self.source.key(place)).collect();
|
||||
let key = payload.grabbed.clone();
|
||||
let before = ReorderMove::new(key.clone(), keys.clone(), from, false).in_group(held);
|
||||
self.events.push(CollectionEvent::Reorder(EditEvent::set(
|
||||
Mixed::Same(before),
|
||||
ReorderMove::new(key, keys, to, copy).in_group(parent),
|
||||
cx.core.label_arc(),
|
||||
None,
|
||||
)));
|
||||
}
|
||||
|
||||
/// Step 9: sweeps, row drags, drops and the free-layout move, from the collection's own press and the drag session.
|
||||
@@ -466,7 +477,7 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
(rect, offset, rtl): (Rect, ScrollPos, bool),
|
||||
props: &CollectionProps,
|
||||
) {
|
||||
self.drags.over = None;
|
||||
self.drags.pending = None;
|
||||
let free = matches!(layout.nav(), NavShape::Spatial);
|
||||
let phase = cx.core.press.phase;
|
||||
// The pointer comes in screen space; the rows and a move's offset are in the rows' own space.
|
||||
@@ -519,15 +530,17 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
.filter(|spot| comp.accepts(&payload, Some(&self.source.key(spot.over)), spot.insert))
|
||||
.filter(|spot| !(own && groups) || !self.inside_dragged(&payload, spot.parent))
|
||||
};
|
||||
if let Some(spot) = spot
|
||||
&& !own
|
||||
&& !self.source.is_empty()
|
||||
{
|
||||
self.drags.over = Some(self.source.key(spot.over));
|
||||
}
|
||||
let copy_ok = !own || props.reorder.is_some_and(|rule| rule.copy_with_alt);
|
||||
let ordinal = drag::next_ordinal(&cx.core.ctx, cx.core.id);
|
||||
if let Some(landed) = cx.drop_target::<ListDrag<C::Key>, _>(&RowDrop { spot, copy_ok }) {
|
||||
self.land(cx, &payload, landed, groups);
|
||||
} else if let Some(spot) = spot
|
||||
&& drag::winning(&cx.core.ctx, cx.core.id, ordinal)
|
||||
{
|
||||
let op = drag::current_operation(&cx.core.ctx);
|
||||
if copy_ok || !matches!(op, DropOperation::Copy) {
|
||||
self.drags.pending = self.drop_of(own, &payload, Landed { spot, op }, groups);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -538,8 +551,13 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
{
|
||||
let at = layer(at);
|
||||
let spot = if self.source.is_empty() { self.empty_spot(rect, at) } else { self.spot(layout, rect, offset, rtl, None, at) };
|
||||
let ordinal = drag::next_ordinal(&cx.core.ctx, cx.core.id);
|
||||
if let Some(spot) = cx.drop_target::<OsFiles, _>(&FileDrop { spot }) {
|
||||
self.events.push(CollectionEvent::FilesDropped { insert: spot.insert, files: files.files.clone() });
|
||||
} else if let Some(spot) = spot
|
||||
&& drag::winning(&cx.core.ctx, cx.core.id, ordinal)
|
||||
{
|
||||
self.drags.pending = Some(PendingDrop::Files { insert: spot.insert });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::members::Member;
|
||||
use super::{Held, ITEM_NODE, ItemsHooks, LastLayout, Lead, Placement, Renaming, Rows, SCROLL, Scrolled, View, key_hash, section_part};
|
||||
use super::{request, rows};
|
||||
use crate::contract::ValueOf;
|
||||
use crate::contract::collection::{CollectionEvent, ContextMenuRequest, Gestures, OpenChange, Rename, RowState, ShownRow};
|
||||
use crate::contract::collection::{CollectionEvent, ContextMenuRequest, Gestures, ItemsOut, OpenChange, PendingDrop, Rename, RowState, ShownRow};
|
||||
use crate::contract::cx::{BodyCx, Pointer as _};
|
||||
use crate::contract::run::{Measuring, ShapeHooks, ShowAt};
|
||||
use crate::contract::steps::ShapeKind;
|
||||
@@ -458,7 +458,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
run.is_multiple_of(2) && !self.source.is_section(at)
|
||||
},
|
||||
dragging: self.drags.grabbed.as_ref() == Some(&key),
|
||||
drop_target: self.drags.over.as_ref() == Some(&key),
|
||||
drop_target: matches!(&self.drags.pending, Some(PendingDrop::Items { key: Some(over), .. }) if *over == key),
|
||||
current: current.as_ref() == Some(&key),
|
||||
open: self.source.has_children(at) && self.source.open(at),
|
||||
hovered: hover_at.is_some_and(|pos| row.contains(pos)),
|
||||
@@ -711,7 +711,12 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
|
||||
self.header.report(&cx.core.ctx, id, cx);
|
||||
*cx.core.memory.session::<Renaming<C::Key>>(sub(id, "rename")) = self.renaming.clone();
|
||||
cx.core.collection_selection = Some(Box::new(self.selection.clone()));
|
||||
cx.core.collection_events = Some(Box::new((std::mem::take(&mut self.events), std::mem::take(&mut self.shown), self.activation_clicks)));
|
||||
cx.core.collection_events = Some(Box::new(ItemsOut {
|
||||
events: std::mem::take(&mut self.events),
|
||||
shown: std::mem::take(&mut self.shown),
|
||||
activation_clicks: self.activation_clicks,
|
||||
pending_drop: self.drags.pending.clone(),
|
||||
}));
|
||||
cx.core.visible_rows = self.visible.clone();
|
||||
cx.core.gestures = Gestures::of(comp.items());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! What a collection's caller reads from `Cx` after the item step: its selection and response.
|
||||
|
||||
use crate::contract::collection::{CollectionEvent, CollectionResponse, ShownRow};
|
||||
use crate::contract::collection::{CollectionResponse, ItemsOut};
|
||||
use crate::contract::{Collection, Cx};
|
||||
|
||||
impl<C: Collection> Cx<'_, C> {
|
||||
@@ -17,7 +17,7 @@ impl<C: Collection> Cx<'_, C> {
|
||||
.core
|
||||
.collection_events
|
||||
.take()
|
||||
.and_then(|held| held.downcast::<(Vec<CollectionEvent<C::Key, C::ItemEvent>>, Vec<ShownRow<C::Key>>, u8)>().ok())
|
||||
.and_then(|held| held.downcast::<ItemsOut<C::Key, C::ItemEvent>>().ok())
|
||||
.map(|held| *held)
|
||||
.unwrap_or_default();
|
||||
CollectionResponse::new(self.core.response.clone(), events, self.core.visible_rows.clone(), self.core.gestures)
|
||||
|
||||
@@ -49,8 +49,8 @@ pub use body::REORDER_BAND;
|
||||
pub use body::pad_of;
|
||||
pub use collection::{
|
||||
ActivateOn, CollectionEvent, CollectionProps, CollectionResponse, ColumnAlign, ColumnEvent, ColumnKind, ColumnSort, ColumnSpec,
|
||||
ContextMenuRequest, DragPayload, HeaderMenuRequest, ItemKeys, LeadOnOpen, LeadSource, ListDrag, OpenChange, Rename, ReorderMove, ReorderRule,
|
||||
RowPressed, RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
ContextMenuRequest, DragPayload, HeaderMenuRequest, ItemKeys, LeadOnOpen, LeadSource, ListDrag, OpenChange, PendingDrop, Rename, ReorderMove,
|
||||
ReorderRule, RowPressed, RowState, SelectMode, ShownRow, SpaceAction, ToggleColumn, ToggleEdit,
|
||||
};
|
||||
#[doc(hidden)]
|
||||
pub use container::InBar;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Reordering into the groups of a tree: where a drop lands below an open group, and that a group does not drop
|
||||
//! inside itself.
|
||||
//! Reordering into the groups of a tree: where a drop lands below an open group, that a group does not drop inside
|
||||
//! itself, and the drop a release would make, reported while the drag is held.
|
||||
|
||||
use super::kit::{Dismissed, List, ROW_H, Row, Words};
|
||||
use craft_ui::contract::{CollectionEvent, CollectionResponse, Props as _, SelectMode, ShowCollection as _};
|
||||
use craft_ui::contract::{CollectionEvent, CollectionResponse, PendingDrop, Props as _, SelectMode, ShowCollection as _};
|
||||
use craft_ui::runtime::drag;
|
||||
use craft_ui::testing::layout::in_region;
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
@@ -28,6 +28,7 @@ fn grove() -> Words {
|
||||
struct Run {
|
||||
events: RefCell<Vec<CollectionEvent<usize, Dismissed>>>,
|
||||
rows: RefCell<Vec<(usize, Rect)>>,
|
||||
pending: RefCell<Option<PendingDrop<usize>>>,
|
||||
}
|
||||
|
||||
impl Run {
|
||||
@@ -37,6 +38,7 @@ impl Run {
|
||||
|
||||
fn take(&self, out: CollectionResponse<usize, Dismissed>) {
|
||||
self.events.borrow_mut().extend(out.events);
|
||||
*self.pending.borrow_mut() = out.pending_drop;
|
||||
}
|
||||
|
||||
/// Every reorder reported: the moved keys, the position and the group.
|
||||
@@ -114,3 +116,24 @@ fn a_group_does_not_drop_inside_itself() {
|
||||
release_at(&mut frames, at, &mut show);
|
||||
assert!(run.moves().is_empty());
|
||||
}
|
||||
|
||||
/// While rows are held over the list, the response carries the move a release would make; the release reports that
|
||||
/// move, and over no row there is none.
|
||||
#[trial]
|
||||
fn a_held_drag_reports_the_move_its_release_makes() {
|
||||
let (words, run) = (grove(), Run::default());
|
||||
let mut frames = Frames::new();
|
||||
let mut show = |ui: &mut Ui| show_grove(ui, List::new(SelectMode::Single).tree().reorder_into_groups(), &words, &run);
|
||||
frames.idle(3, &mut show);
|
||||
let outside = ORIGIN + VIEW + Vec2::splat(20.0);
|
||||
drag_to(&mut frames, &run, 0, outside, &mut show);
|
||||
assert_eq!(*run.pending.borrow(), None, "outside the list a release drops nothing here");
|
||||
let at = point(&run, 4, SHALLOW, ROW_H * 0.75);
|
||||
frames.frame(vec![moved(at)], &mut show);
|
||||
frames.idle(1, &mut show);
|
||||
let Some(PendingDrop::Reorder(pending)) = run.pending.borrow().clone() else { panic!("a held reorder: {:?}", run.pending.borrow()) };
|
||||
assert!(run.moves().is_empty(), "nothing moves before the release");
|
||||
release_at(&mut frames, at, &mut show);
|
||||
assert_eq!(run.moves(), vec![(pending.keys, pending.to, pending.parent)]);
|
||||
assert_eq!(*run.pending.borrow(), None, "after the drop nothing is pending");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user