From 0bff3fce1f1412d5eb572ee0ce05f39e7fb18170 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 10:42:24 -0500 Subject: [PATCH] Framework fwb11-b: port follow-ups (see runs/fwb11-b.md) --- crates/ui-contract/src/contract/cx/pointer.rs | 8 ++- .../ui-contract/src/contract/items/access.rs | 9 ++- .../ui-contract/src/contract/items/hooks.rs | 2 +- crates/ui-contract/src/contract/text.rs | 2 +- .../ui-contract/src/primitives/text_input.rs | 3 + crates/ui-contract/src/runtime/drag.rs | 9 ++- crates/ui-contract/tests/it/drag/mod.rs | 56 +++++++++++++++++++ crates/ui-shell/tests/it/shell/start.rs | 39 +++++++++++++ crates/ui-widgets/src/popover/drop_veil.rs | 25 ++++++++- .../src/popover/drop_veil/stories.rs | 7 +++ .../ui-widgets/src/tabs/document/stories.rs | 2 +- crates/ui-widgets/src/tabs/rules.rs | 8 +-- crates/ui-widgets/src/text/text_field.rs | 9 +-- crates/ui-widgets/tests/it/list.rs | 19 +++++++ crates/ui-widgets/tests/it/tabs.rs | 7 +++ crates/ui-widgets/tests/it/text/text_field.rs | 18 ++++++ 16 files changed, 198 insertions(+), 25 deletions(-) diff --git a/crates/ui-contract/src/contract/cx/pointer.rs b/crates/ui-contract/src/contract/cx/pointer.rs index f1899e1108..69f993326e 100644 --- a/crates/ui-contract/src/contract/cx/pointer.rs +++ b/crates/ui-contract/src/contract/cx/pointer.rs @@ -58,9 +58,8 @@ pub trait Pointer { /// pass, when it was the topmost accepting target under the pointer last pass and accepts now. fn drop_target>(&mut self, target: &T) -> Option; /// Registers `target` over the whole window of the running viewport for this pass, in `update`; a target over a - /// component beats it wherever that accepts. The payload is read without a pointer position, so files hovered - /// before the pointer has a position reach it. OS file drops (`OsFiles`) land on it wherever no other target - /// takes them. + /// component beats it wherever that accepts. By default the payload is read without a pointer position; a target + /// that requires one waits for it so the target at that position can take the drop. fn window_drop_target>(&mut self, target: &T) -> Option; /// The operation of a drop of this component's payload, in the pass after the drop; `None` while dragging, when the /// drag was cancelled and when no target took it. @@ -157,6 +156,9 @@ impl Pointer for CxCore<'_> { } fn window_drop_target>(&mut self, target: &T) -> Option { + if target.requires_pointer() && self.dragging::

().is_none() { + return None; + } let payload = drag::active::

(&self.ctx).filter(|_| !drag::moves_viewport(&self.ctx))?; let op = drag::current_operation(&self.ctx, craft_behavior::CopyKeys::Alt); let drop = target.accept(&payload, op)?; diff --git a/crates/ui-contract/src/contract/items/access.rs b/crates/ui-contract/src/contract/items/access.rs index 8b72bb9ab7..12f4480e0e 100644 --- a/crates/ui-contract/src/contract/items/access.rs +++ b/crates/ui-contract/src/contract/items/access.rs @@ -74,9 +74,9 @@ impl ItemsHooks<'_, '_, C> { } /// AccessKit requests on an item row's node or on a section row's collection node (`report_section_node`): Focus - /// moves the lead to the row and key focus to the collection; Click does that and picks an item or activates a - /// section, as a press does; Expand and Collapse open and close a row that has children. - pub(super) fn node_by_access(&mut self, comp: &C, cx: &mut Cx<'_, C>, layout: &C::ItemLayout, place: Placement) { + /// moves the lead to the row and key focus to the collection; Click also picks an item and activates it when the + /// collection activates on click, or activates a section; Expand and Collapse open and close rows with children. + pub(super) fn node_by_access(&mut self, comp: &C, cx: &mut Cx<'_, C>, props: &crate::contract::CollectionProps, layout: &C::ItemLayout, place: Placement) { use craft_behavior::AccessAction; let (_, built) = self.built(layout, place.rect, place.offset); let rows: Vec<(u64, usize)> = built @@ -109,6 +109,9 @@ impl ItemsHooks<'_, '_, C> { self.events.push(CollectionEvent::Activate(key)); } else { self.pick(comp, at, false, false); + if matches!(props.activate, crate::contract::ActivateOn::Click) { + self.events.push(CollectionEvent::Activate(key)); + } } } } diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index 78cdef4fd0..5072a5601f 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -441,7 +441,7 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { self.context_key(cx, &layout, at, lead_at); self.delete_key(cx, &props, lead_at); self.toggle_by_access(cx, &layout, at); - self.node_by_access(comp, cx, &layout, at); + self.node_by_access(comp, cx, &props, &layout, at); self.reorder_and_rename(comp, cx, &props, lead_at); self.requested_rename(comp, cx, &props, &layout); self.requested_reveal(comp, &layout); diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index f451693de3..7b7e18c300 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -422,7 +422,7 @@ pub(crate) fn run( let ink = if enabled { ink } else { crate::style::rgba_color(crate::runtime::env::Env::of(ui).tokens.color.text.disabled) }; let held = cx.popup(EDIT_MENU).is_open_in(&mut cx.core); serve_access(cx, &mut state, widget, &decl.shown, read_only); - let select_all = std::mem::take(&mut state.select_all); + let select_all = (std::mem::take(&mut state.select_all) || decl.options.select_all) && !crate::runtime::ime::composing(&ctx, widget); if select_all { let len = state.draft.as_deref().unwrap_or(&decl.shown).chars().count(); adapter::select(&ctx, widget, 0, len); diff --git a/crates/ui-contract/src/primitives/text_input.rs b/crates/ui-contract/src/primitives/text_input.rs index 54613e049d..513677d55d 100644 --- a/crates/ui-contract/src/primitives/text_input.rs +++ b/crates/ui-contract/src/primitives/text_input.rs @@ -73,6 +73,8 @@ pub struct TextOptions { pub steps_value: bool, /// The whole text is selected when the field takes focus, whatever the codec's caret rule says. pub select_on_focus: bool, + /// Selects the current text before this pass's typing, unless an IME composition is active. + pub select_all: bool, /// Enter does something in the field itself (it saves or runs a search): the field takes the `Submit` intent, so the /// enclosing dialog's default button does not act on it. pub submits: bool, @@ -133,6 +135,7 @@ impl Default for TextOptions { enabled: true, steps_value: false, select_on_focus: false, + select_all: false, submits: false, mixed: false, centred: false, diff --git a/crates/ui-contract/src/runtime/drag.rs b/crates/ui-contract/src/runtime/drag.rs index 343b9c0ec6..9077eea77f 100644 --- a/crates/ui-contract/src/runtime/drag.rs +++ b/crates/ui-contract/src/runtime/drag.rs @@ -123,12 +123,17 @@ pub trait DropTarget { } } -/// What a component registers with `Pointer::window_drop_target`: a target over the whole window, which needs no -/// pointer position. +/// What a component registers with `Pointer::window_drop_target`: a target over the whole window, optionally waiting +/// for a pointer position before it accepts. pub trait WindowDropTarget

{ /// What a drop on this target carries to the component's caller. type Drop; + /// Whether this target waits for a pointer position before taking a drop. + fn requires_pointer(&self) -> bool { + false + } + /// `None` rejects. `op` is the operation the held modifiers pick, which a target may refuse. fn accept(&self, payload: &P, op: DropOperation) -> Option; diff --git a/crates/ui-contract/tests/it/drag/mod.rs b/crates/ui-contract/tests/it/drag/mod.rs index 513d1d26b3..ba18e15879 100644 --- a/crates/ui-contract/tests/it/drag/mod.rs +++ b/crates/ui-contract/tests/it/drag/mod.rs @@ -207,6 +207,18 @@ impl DropTarget for OnRow { /// A drop of files anywhere in the window. struct OnWindow; +struct OnPositionalWindow; + +impl WindowDropTarget for OnPositionalWindow { + type Drop = Vec; + + fn requires_pointer(&self) -> bool { true } + + fn accept(&self, files: &OsFiles, _: DropOperation) -> Option { Some(names(files)) } + + fn mark(&self, _: &Self::Drop) -> DropMark { DropMark::Into(WINDOW) } +} + impl WindowDropTarget for OnWindow { type Drop = Vec; @@ -241,6 +253,50 @@ struct WindowOnly<'a> { landed: &'a RefCell, } +#[derive(Component)] +struct PositionalWindow<'a> { + #[common] + common: Common, + landed: &'a RefCell, +} + +impl Component for PositionalWindow<'_> { + const ROLE: Role = Role::GROUP; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: PositionalWindowStyleKey) -> PlainStyle { PlainStyle::default() } + fn measure(&mut self, _: &MeasureCx<'_, Self>) -> Vec2 { WINDOW.size() } + fn update(&mut self, cx: &mut Cx<'_, Self>) { + if let Some(files) = cx.window_drop_target(&OnPositionalWindow) { + self.landed.borrow_mut().window.push(files); + } + } + fn finish(self, cx: Cx<'_, Self>) -> Response { cx.response.clone() } +} + +#[trial] +fn positional_window_waits_for_pointer_to_choose_a_row() { + let landed = RefCell::new(Landed::default()); + let mut frames = Frames::new(); + let mut show = |ui: &mut Ui| { + PositionalWindow { common: Common::new(), landed: &landed }.id_salt("window").show_at(ui, WINDOW); + RowOnly { common: Common::new(), landed: &landed }.id_salt("rows").show_at(ui, LIST); + }; + frames.idle(2, &mut show); + frames.hover_files(&["a.png"]); + frames.frame(vec![], &mut show); + frames.idle(2, &mut show); + frames.drop_files(&["a.png"]); + frames.frame(vec![], &mut show); + frames.idle(2, &mut show); + assert!(landed.borrow().window.is_empty(), "the window waits while the pointer is unknown"); + frames.frame(vec![moved(LIST.center())], &mut show); + frames.idle(3, &mut show); + assert_eq!(landed.borrow().rows.len(), 1, "the row under the pointer takes the drop"); + assert!(landed.borrow().window.is_empty()); +} + impl Component for WindowOnly<'_> { const ROLE: Role = Role::GROUP; type Style = PlainStyle; diff --git a/crates/ui-shell/tests/it/shell/start.rs b/crates/ui-shell/tests/it/shell/start.rs index ee127a1c5e..067542453c 100644 --- a/crates/ui-shell/tests/it/shell/start.rs +++ b/crates/ui-shell/tests/it/shell/start.rs @@ -18,6 +18,45 @@ use std::rc::Rc; type Log = Rc>>; +#[trial] +fn recent_files_follow_the_supplied_list_when_cleared() { + let files = Rc::new(RefCell::new(vec![ + RecentFile::new("/tmp/first", "First document"), + RecentFile::new("/tmp/second", "Second document"), + RecentFile::new("/tmp/third", "Third document"), + ])); + let supplied = files.clone(); + let mut fixture = Fixture::new(move |ui| { + let (mut view, mut sort) = (RecentView::List, RecentSort::Opened); + let current = supplied.borrow().clone(); + let out = StartScreen::new(Bind::bound(&mut view), Bind::bound(&mut sort), ¤t) + .drop_hint("Drop files here") + .section(StartPlace::BeforeRecent, |ui, _| { Text::new("Welcome").show(ui); }) + .show(ui); + for action in out.actions { + match action { + StartAction::RemoveRecent(path) => supplied.borrow_mut().retain(|file| file.path != path), + StartAction::ClearRecent => supplied.borrow_mut().clear(), + _ => {} + } + } + }); + fixture.room(egui::Vec2::new(1100.0, 700.0)).settle(); + let row = fixture.by_label("Second document, /tmp").expect("the recent row"); + fixture.frame(vec![moved(row.center())]).idle(2); + let remove = fixture.by_label("Remove Second document from Recent").expect("the remove button"); + fixture.click(&remove).idle(2); + assert_eq!(files.borrow().len(), 2); + let row = fixture.by_label("First document, /tmp").expect("the recent row"); + let at = row.center(); + fixture.frame(vec![moved(at)]).frame(vec![secondary(at, true)]).frame(vec![secondary(at, false)]).idle(2); + let clear = fixture.by_label("Clear Recent Files").expect("the recent menu"); + fixture.click(&clear).idle(3); + assert!(files.borrow().is_empty()); + assert!(fixture.by_label("First document, /tmp").is_none(), "removed files no longer appear"); + assert!(fixture.by_label("Drop files here").is_some(), "the empty hint appears"); +} + /// A start screen of two recent files and a link in a room wide enough for the rail; every action it reports goes to /// the log. fn screen() -> (Fixture, Log) { diff --git a/crates/ui-widgets/src/popover/drop_veil.rs b/crates/ui-widgets/src/popover/drop_veil.rs index 530f81cfb8..6d23f14cf8 100644 --- a/crates/ui-widgets/src/popover/drop_veil.rs +++ b/crates/ui-widgets/src/popover/drop_veil.rs @@ -117,18 +117,30 @@ impl Outcome for DropVeilOutput { /// the files nothing else in their window took use it too. pub struct WholeWindow { rect: Rect, + positional: bool, } impl WholeWindow { /// A target over the window, marked with `rect` while files hover. pub fn new(rect: Rect) -> Self { - WholeWindow { rect } + WholeWindow { rect, positional: false } + } + + /// Waits for the pointer so a more specific target can take the drop at that position. + #[must_use] + pub fn positional(mut self) -> Self { + self.positional = true; + self } } impl WindowDropTarget for WholeWindow { type Drop = OsFiles; + fn requires_pointer(&self) -> bool { + self.positional + } + fn accept(&self, payload: &OsFiles, _op: DropOperation) -> Option { (!payload.files.is_empty()).then(|| payload.clone()) } @@ -152,6 +164,7 @@ pub struct DropVeil { #[container] props: ContainerProps, hovering: bool, + positional: bool, /// The files dropped this pass: `update` writes them before the body runs, the body and `finish` read them. A veil /// is built anew every pass, so nothing outlives it. dropped: Arc>>, @@ -163,7 +176,14 @@ impl DropVeil { /// A veil saying `label` ("Import 3 photos") while files hover. pub fn new(label: impl Into