From aafc82051ec9ac5a3c51ada51a35ea0035998f97 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 22:38:38 -0500 Subject: [PATCH] Contract stubs: craft-ui-contract --- crates/ui-contract/src/contract/body/hooks.rs | 4 +- .../ui-contract/src/contract/body/reorder.rs | 4 +- .../src/contract/collection/props.rs | 21 ++++++++++- .../src/contract/collection/response.rs | 8 +++- crates/ui-contract/src/contract/container.rs | 3 ++ crates/ui-contract/src/contract/cx/pointer.rs | 34 ++++++++++++++++- crates/ui-contract/src/contract/entry.rs | 26 ++++++++++++- crates/ui-contract/src/contract/items.rs | 3 ++ .../ui-contract/src/contract/items/hooks.rs | 4 +- crates/ui-contract/src/contract/mod.rs | 1 + .../ui-contract/src/contract/steps/report.rs | 2 + crates/ui-contract/src/fonts/mod.rs | 6 +++ crates/ui-contract/src/fonts/stack.rs | 5 ++- crates/ui-contract/src/fonts/stack/chain.rs | 2 +- .../src/primitives/auto_scroll_mark.rs | 37 +++++++++++++++++++ crates/ui-contract/src/primitives/draw.rs | 24 +++++++++++- crates/ui-contract/src/primitives/mod.rs | 13 ++++--- .../ui-contract/src/primitives/text_input.rs | 15 ++++++++ .../src/primitives/textures/loader.rs | 3 +- .../src/primitives/textures/mod.rs | 4 +- .../src/primitives/textures/thumbnails.rs | 28 +++++++++++++- .../src/primitives/textures/words.rs | 3 ++ crates/ui-contract/src/runtime/access/emit.rs | 9 +++-- .../ui-contract/src/runtime/commands/board.rs | 9 +++++ .../ui-contract/src/runtime/commands/mod.rs | 3 ++ crates/ui-contract/src/runtime/egui/access.rs | 20 +++++++++- .../src/runtime/egui/access/node.rs | 3 ++ .../src/runtime/egui/access/tree.rs | 14 +++++-- .../ui-contract/src/runtime/egui/injected.rs | 25 +++++++++++++ crates/ui-contract/src/runtime/egui/plugin.rs | 5 +++ crates/ui-contract/src/runtime/env.rs | 2 +- crates/ui-contract/src/runtime/env/system.rs | 6 +++ crates/ui-contract/src/runtime/frame.rs | 3 ++ crates/ui-contract/src/runtime/toast.rs | 15 ++++++++ crates/ui-contract/src/runtime/wheel.rs | 27 ++++++++++++++ .../ui-contract/src/runtime/windows/host.rs | 32 ++++++++++++++++ crates/ui-contract/src/style/cx.rs | 12 ++++++ crates/ui-macros/src/props.rs | 1 + 38 files changed, 407 insertions(+), 29 deletions(-) create mode 100644 crates/ui-contract/src/primitives/auto_scroll_mark.rs diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index e5d94a6f3..5ac65d9d5 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -121,7 +121,9 @@ impl ShapeHooks for BodyHooks<'_> { fn key_role(&self, comp: &C) -> KeyRole { let props = comp.props(Internal::new()); - KeyRole::new().reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder)).document(props.scroll_owner) + KeyRole::new() + .reorderable(props.header.is_some_and(|header| header.band == DragBand::Reorder).then_some(craft_behavior::ReorderKeys::Stacking)) // P3(pdf-workflows-w1): WF-W4 + .document(props.scroll_owner) } fn position(&self, comp: &C) -> Option { diff --git a/crates/ui-contract/src/contract/body/reorder.rs b/crates/ui-contract/src/contract/body/reorder.rs index 8b2c51f25..e04d8b40a 100644 --- a/crates/ui-contract/src/contract/body/reorder.rs +++ b/crates/ui-contract/src/contract/body/reorder.rs @@ -28,7 +28,9 @@ impl BodyHooks<'_> { keys::capture(&ctx, id, chord); } while keys::take_claimed(&ctx, id, chord) { - if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods) { + if let Some(intent) = key_table::reorder_intent(chord.key, chord.mods, craft_behavior::ReorderKeys::Stacking, craft_behavior::Axis::Y) + { + // P3(pdf-workflows-w1): WF-W3 cx.core.intents.push(intent); } } diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index 081ae575b..6dea6475b 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -34,12 +34,21 @@ pub struct ReorderRule { /// In a tree, a drop or a stacking-key move may land inside a group, and `ReorderMove::parent` names the group. A row /// that `has_children` is a group; an open group without visible children takes items through the middle of its row. pub into_groups: bool, + /// The key scheme that reorders the collection's items; default `Stacking`. + pub keys: craft_behavior::ReorderKeys, } impl ReorderRule { /// A rule that only moves. pub const fn new() -> Self { - ReorderRule { copy_with_alt: false, into_groups: false } + ReorderRule { copy_with_alt: false, into_groups: false, keys: craft_behavior::ReorderKeys::Stacking } + } + + /// The key scheme that reorders the items. + #[must_use] + pub const fn keys(mut self, keys: craft_behavior::ReorderKeys) -> Self { + self.keys = keys; + self } /// Items may land inside the groups of a tree. @@ -229,6 +238,8 @@ pub struct CollectionProps { pub command_click: bool, /// The distance one wheel notch scrolls the rows; unset, the default notch. pub notch: Option, + /// What a middle press does: pan or latched auto-scroll. + pub middle_button: craft_behavior::MiddleButton, /// The axis the rows overflow along. A collection owns the scroll along it, so it sits only in a scrolling body /// that does not scroll along it too: a strip of tabs (`Axis::X`) sits in a page that scrolls vertically. pub overflow: Axis, @@ -320,6 +331,7 @@ impl CollectionProps { row_height: RowHeight::Control, command_click: false, notch: None, + middle_button: craft_behavior::MiddleButton::Pan, overflow: Axis::Y, pages: false, current: None, @@ -567,6 +579,13 @@ impl CollectionProps { self } + /// What a middle press does: pan, or latched auto-scroll (see [`CollectionProps::middle_button`]). + #[must_use] + pub const fn middle_button(mut self, button: craft_behavior::MiddleButton) -> Self { + self.middle_button = button; + self + } + /// The wheel distance of one notch, with a text line `line` points high: the set notch, else the default. pub fn wheel_notch(&self, line: f32) -> craft_behavior::WheelNotch { self.notch.map_or(craft_behavior::WheelNotch::DEFAULT, |notch| notch.wheel(line)) diff --git a/crates/ui-contract/src/contract/collection/response.rs b/crates/ui-contract/src/contract/collection/response.rs index da4ca07fe..4d0fae5ac 100644 --- a/crates/ui-contract/src/contract/collection/response.rs +++ b/crates/ui-contract/src/contract/collection/response.rs @@ -31,6 +31,8 @@ pub struct CollectionResponse { /// 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>, + /// The row under the pointer this pass; `None` during a drag. + pub hovered: Option, } /// The drop a release would make on a collection now. @@ -46,7 +48,7 @@ pub enum PendingDrop { impl CollectionResponse { pub(crate) fn new( response: Response, - ItemsOut { events, shown, activation_clicks, pending_drop }: ItemsOut, + ItemsOut { events, shown, activation_clicks, pending_drop, hovered }: ItemsOut, visible: Range, gestures: Gestures, ) -> Self { @@ -60,6 +62,7 @@ impl CollectionResponse { reorder: gestures.reorder, activation_clicks, pending_drop, + hovered, } } @@ -76,11 +79,12 @@ pub(crate) struct ItemsOut { pub(crate) shown: Vec>, pub(crate) activation_clicks: u8, pub(crate) pending_drop: Option>, + pub(crate) hovered: Option, } impl Default for ItemsOut { fn default() -> Self { - ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None } + ItemsOut { events: Vec::new(), shown: Vec::new(), activation_clicks: 0, pending_drop: None, hovered: None } } } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 7dc25b892..15adf9db8 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -184,6 +184,8 @@ pub enum LeastWidth { DialogSideButton, /// `size.rail.width` per column: a tool rail of this many columns, as wide as the shell slot that holds it. Rail(std::num::NonZeroU8), + /// `size.dock.column`: a fixed side pane is as wide as a dock column. + DockColumn, } impl LeastWidth { @@ -195,6 +197,7 @@ impl LeastWidth { LeastWidth::DialogButton => tokens.size.dialog.button, LeastWidth::DialogSideButton => tokens.size.dialog.side_button, LeastWidth::Rail(columns) => tokens.size.rail.width * f32::from(columns.get()), + LeastWidth::DockColumn => tokens.size.dock.column, } } } diff --git a/crates/ui-contract/src/contract/cx/pointer.rs b/crates/ui-contract/src/contract/cx/pointer.rs index f405877b2..623ae4e1f 100644 --- a/crates/ui-contract/src/contract/cx/pointer.rs +++ b/crates/ui-contract/src/contract/cx/pointer.rs @@ -7,7 +7,7 @@ use crate::runtime::drag::{self, DragPreview, DropTarget, DropZone, Typed, Windo use crate::runtime::egui::areas; use crate::runtime::{cursor, frame, pointer, wheel}; use craft_behavior::{Cursor, CursorPriority, DropOperation, PartKey, PartRef, PressCancel, PressState, Wheel}; -use egui::{Id, Pos2}; +use egui::{Id, Pos2, Vec2}; use std::any::{Any, TypeId}; use std::ops::Range; use std::sync::Arc; @@ -35,6 +35,14 @@ pub trait Pointer { fn activated_member(&self) -> Option; /// This pass's wheel share, once, with the pointer it came at (`Wheel::at`) in this component's egui layer space (8.3). fn take_wheel(&mut self) -> Option; + /// Marks the wheel gesture this component owns, while it runs, as moved (its view changed): later shares of the + /// gesture report `Wheel::moved`. + fn mark_wheel_moved(&mut self); + /// Feeds `pan`, the line pan this pass gave, to this component's wheel ease and returns the eased step for this + /// pass. `Vec2::ZERO` on a pass with no line pan lets owed motion keep paying. + fn ease_wheel(&mut self, pan: Vec2) -> Vec2; + /// Drops this component's wheel ease and the motion it owes. + fn stop_wheel_ease(&mut self); /// Requests `cursor` at `priority`; the highest priority of the pass wins. fn cursor(&mut self, cursor: impl Into, priority: CursorPriority); /// Ends every captured press of this viewport. @@ -107,6 +115,18 @@ impl Pointer for CxCore<'_> { Some(wheel) } + fn mark_wheel_moved(&mut self) { + wheel::mark_moved(&self.ctx, self.id); + } + + fn ease_wheel(&mut self, pan: Vec2) -> Vec2 { + wheel::ease(&self.ctx, self.id, pan) + } + + fn stop_wheel_ease(&mut self) { + wheel::stop_ease(&self.ctx, self.id); + } + fn cursor(&mut self, cursor: impl Into, priority: CursorPriority) { if self.cursor.as_ref().is_none_or(|(_, held)| priority > *held) { self.cursor = Some((cursor.into(), priority)); @@ -198,6 +218,18 @@ impl Pointer for Cx<'_, C> { self.core.take_wheel() } + fn mark_wheel_moved(&mut self) { + self.core.mark_wheel_moved(); + } + + fn ease_wheel(&mut self, pan: Vec2) -> Vec2 { + self.core.ease_wheel(pan) + } + + fn stop_wheel_ease(&mut self) { + self.core.stop_wheel_ease(); + } + fn cursor(&mut self, cursor: impl Into, priority: CursorPriority) { self.core.cursor(cursor, priority); } diff --git a/crates/ui-contract/src/contract/entry.rs b/crates/ui-contract/src/contract/entry.rs index 51bae9f28..91380c025 100644 --- a/crates/ui-contract/src/contract/entry.rs +++ b/crates/ui-contract/src/contract/entry.rs @@ -30,6 +30,8 @@ struct Item { icon: Option>, enabled: bool, reason: Option