diff --git a/crates/ui-contract/src/contract/body/presses.rs b/crates/ui-contract/src/contract/body/presses.rs index 6316b35a90..98296dceb0 100644 --- a/crates/ui-contract/src/contract/body/presses.rs +++ b/crates/ui-contract/src/contract/body/presses.rs @@ -19,6 +19,8 @@ struct BandDouble(bool); struct SurfacePress { pressed: bool, double: bool, + #[allow(dead_code)] // P3(chrome-w5): ch.K32 + clicked: bool, } impl BodyCx<'_> { @@ -53,6 +55,13 @@ impl BodyCx<'_> { !self.memory.is_peek() && self.memory.recall::(sub(self.id, "surface_press")).double } + /// Whether this pass's primary release ends a press that went down on the container's own surface, moved less + /// than `PointerFrame::slop` and was released inside. A drag, a cancel, a release elsewhere and a measuring run + /// give false. It takes no focus and is no Tab stop. + pub fn surface_clicked(&self) -> bool { + todo!("ch.K32") + } + /// Requests `cursor` at `priority` for this pass, in the cursor service the parts' and components' requests go /// to: the highest priority of the pass wins, the later request on a tie. A body that learns something only after /// its children ran (a drag its panes report as refused) sets the cursor in the same pass. A measuring run diff --git a/crates/ui-contract/src/contract/collection/props.rs b/crates/ui-contract/src/contract/collection/props.rs index 081ae575be..d72419ba44 100644 --- a/crates/ui-contract/src/contract/collection/props.rs +++ b/crates/ui-contract/src/contract/collection/props.rs @@ -2,7 +2,7 @@ use super::columns::{ColumnSort, ColumnSpec}; use super::events::ListDrag; -use crate::contract::Notch; +use crate::contract::{Notch, ScrollAnchor}; pub use crate::runtime::env::RowPressed; use crate::runtime::env::{Counted, Label}; use crate::style::StyleCx; @@ -241,6 +241,9 @@ pub struct CollectionProps { /// While a drag whose payload is neither the collection's own nor one of its drop kinds rests over an item that is /// not selected, the item becomes the lead and the selection in that pass. pub select_under_drag: bool, + /// Which end of the rows a collection that scrolls its own rows stays at while rows are added; `End` keeps the offset + /// at the end as long as the user left it there. + pub scroll_anchor: ScrollAnchor, } type Payload = Arc; @@ -324,6 +327,7 @@ impl CollectionProps { pages: false, current: None, select_under_drag: false, + scroll_anchor: ScrollAnchor::Start, } } diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index c996143d6d..1de376030f 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -786,6 +786,8 @@ pub struct ContainerProps { pub collection_body: bool, /// The labelled rows of the body share the widest label as one column. pub label_column: bool, + /// The rank by which a body unit of a shrinking row leaves whole; unranked units never leave by rank. + pub fit_rank: Option, /// How the labelled rows under the container show their labels; `None` keeps the scheme of the scope. pub labels: Option, /// The component whose memory holds the container's shown memory and its layer's bookkeeping, when it is another: @@ -868,6 +870,7 @@ impl ContainerProps { outer_edit: false, collection_body: false, label_column: false, + fit_rank: None, labels: None, owner: None, } @@ -1022,6 +1025,12 @@ impl ContainerProps { self } + /// Sets the rank by which the container leaves a shrinking row whole. + pub const fn fit_rank(mut self, rank: u8) -> Self { + self.fit_rank = Some(rank); + self + } + /// Makes the container an arena root. pub const fn arena(mut self, on: bool) -> Self { self.arena = on; diff --git a/crates/ui-contract/src/contract/cx/context.rs b/crates/ui-contract/src/contract/cx/context.rs index 3cc1dc3a81..bfa726920a 100644 --- a/crates/ui-contract/src/contract/cx/context.rs +++ b/crates/ui-contract/src/contract/cx/context.rs @@ -217,6 +217,11 @@ impl Cx<'_, C> { text.layout(&self.core.ctx, &Env::of_root(&self.core.ctx).tokens, craft_i18n::Direction::Ltr) } + /// Whether the control's link label was clicked in this pass. + pub fn link_activated(&self) -> bool { + todo!("wg.W08") + } + /// Asks the platform to open `url`, in a new tab where the platform has tabs and `new_tab` is set. pub fn open_url(&mut self, url: &str, new_tab: bool) { crate::runtime::egui::output::open_url(&self.core.ctx, url, new_tab); @@ -236,7 +241,8 @@ impl Cx<'_, C> { /// activation came from (`part_activated` gives it). Returns whether the command was queued. pub fn fire(&mut self, command: impl Into, source: FireSource) -> bool { let Some(resolved) = commands::resolve_scoped(&self.core.ctx, self.core.env.command_chain(), &command.into()) else { return false }; - commands::fire_resolved(&self.core.ctx, &resolved, source) + // P3(widgets-w3): ap.AP9 + commands::fire_resolved(&self.core.ctx, &resolved, source, craft_keymap::Mods::NONE) } /// Where an activation of `part` came from this pass: `Key` for a keyboard activation while `part` is the diff --git a/crates/ui-contract/src/contract/cx/item.rs b/crates/ui-contract/src/contract/cx/item.rs index 3d4ccfe7a5..a031d90d6e 100644 --- a/crates/ui-contract/src/contract/cx/item.rs +++ b/crates/ui-contract/src/contract/cx/item.rs @@ -75,6 +75,13 @@ impl<'r, K> ItemCx<'_, 'r, K> { self.tip = Some(Box::new(tip)); } + /// Shows `body` under the item, across the content width, in a child `Ui` with id `sub(item_id, "detail")`. It adds + /// its height to the item's slot, which keeps its last shown height out of view. + pub fn detail(&mut self, body: impl FnOnce(&mut Ui) + 'r) { + let _ = body; + todo!("ap.AP12") + } + /// The opener for the item's part `part`: after the collection is shown, `CollectionResponse::opener` gives the /// part's response (its click this pass and its rect), and a layer-5 menu opens from it with `opened_by`. pub fn part_opener(&mut self, part: impl Into) -> ItemOpener { diff --git a/crates/ui-contract/src/contract/cx/pointer.rs b/crates/ui-contract/src/contract/cx/pointer.rs index b7b0c4b2c8..b0c0c1dd49 100644 --- a/crates/ui-contract/src/contract/cx/pointer.rs +++ b/crates/ui-contract/src/contract/cx/pointer.rs @@ -6,7 +6,7 @@ use crate::primitives::PartResult; use crate::runtime::drag::{self, DragPreview, DropTarget, DropZone, Typed, WindowDropTarget}; use crate::runtime::egui::areas; use crate::runtime::{cursor, frame, pointer, wheel}; -use craft_behavior::{Cursor, CursorPriority, DropOperation, PartKey, PartRef, PressCancel, PressState, Wheel}; +use craft_behavior::{Cursor, CursorPriority, DropOperation, MultiTap, PartKey, PartRef, PressCancel, PressState, Wheel}; use egui::{Id, Pos2}; use std::any::{Any, TypeId}; use std::ops::Range; @@ -35,6 +35,9 @@ 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; + /// This pass's tap, once, when it lies in this component's rect and this component (an arena root with its members) + /// wins a press there. + fn take_multi_tap(&mut self) -> Option; /// 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 +110,10 @@ impl Pointer for CxCore<'_> { Some(wheel) } + fn take_multi_tap(&mut self) -> Option { + todo!("cv.F19") + } + 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 +205,10 @@ impl Pointer for Cx<'_, C> { self.core.take_wheel() } + fn take_multi_tap(&mut self) -> Option { + self.core.take_multi_tap() + } + fn cursor(&mut self, cursor: impl Into, priority: CursorPriority) { self.core.cursor(cursor, priority); } diff --git a/crates/ui-contract/src/contract/items/drag.rs b/crates/ui-contract/src/contract/items/drag.rs index 9a34cf3751..59587629fa 100644 --- a/crates/ui-contract/src/contract/items/drag.rs +++ b/crates/ui-contract/src/contract/items/drag.rs @@ -13,6 +13,7 @@ use crate::contract::collection::{ CollectionEvent, CollectionProps, ColumnKind, DropAt, DropPayload, DropPlace, ListDrag, PendingDrop, ReorderMove, ToggleColumn, ToggleEdit, }; use crate::contract::reorder; +use crate::contract::reorder::EDGE_ROWS_PER_SECOND; use crate::contract::{Collection, Cx, DragPreview, DropMark, DropTarget, Pointer as _}; use crate::runtime::drag; use crate::runtime::env::Label; @@ -23,9 +24,6 @@ use craft_behavior::{ use egui::{Pos2, Rect, Vec2}; use std::any::Any; -/// Rows per second the view scrolls at when the pointer is a full edge band beyond the view's edge. -pub(super) const EDGE_ROWS_PER_SECOND: f32 = 4.0; - /// A toggle sweep: the value it sets and the rows it has crossed. #[derive(Clone)] struct Sweep { @@ -57,6 +55,9 @@ pub enum SweepStep { Restore(ToggleEdit), /// Undo the `ShowOnly` of a cancelled Alt sweep: the cell has the value from before it. UndoShowOnly(ToggleEdit), + /// The first press held exactly one of the [`SweepApply::claims`] modifiers: it belongs to the host. It flips + /// nothing, and the cells its drag crosses give nothing. Reported once; its Cancel gives nothing. + Claimed(ToggleEdit), } /// The state a sweep needs between events: which gesture opened it and whether Alt was held. @@ -83,6 +84,8 @@ struct Run { pub struct SweepApply { run: Option, show_only: bool, + #[allow(dead_code)] // P3(appearance-w1): dp.C8 + claims: Vec, } /// A move of a collection's own items as they stand before the drop, and as the drop leaves them. @@ -96,7 +99,15 @@ impl SweepApply { /// A column where Alt plus the first press shows only that cell. pub fn show_only() -> Self { - SweepApply { run: None, show_only: true } + SweepApply { run: None, show_only: true, claims: Vec::new() } + } + + /// A first press with exactly `mods` held belongs to the host: it flips nothing, and the cells its drag crosses + /// give nothing (`SweepStep::Claimed`). Claims are checked before `show_only`'s Alt, and the method can be called + /// more than once. + pub fn claims(self, mods: craft_keymap::Mods) -> Self { + let _ = mods; + todo!("dp.C8") } /// Whether this is a [`SweepApply::show_only`] column, where Alt plus the first press shows only that cell. diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 8c583a7940..31dd318fc5 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -13,5 +13,5 @@ mod step; pub use leaf::colon_of; pub(crate) use place::{control_after, label_gap}; pub(crate) use props::inside; -pub use props::{CellWidth, FieldLayout, GlyphLabel, InsideLabel, LabelKind, LabelScheme, Scrub, SideLabel}; +pub use props::{CellWidth, FieldLayout, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, Scrub, SideLabel}; pub(crate) use step::{LabelIn, LeafLabel, Trailing, flow_leaf, in_column, leaf, leaf_under, report_after_reach, run, show_leaf_in_flow}; diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 5f80ba2a30..d77d880993 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -172,6 +172,18 @@ pub(crate) fn inside(env: EnvView<'_>, side: &SideLabel, enabled: bool) -> Optio /// The width of a caption's cell. pub type CellWidth = ColumnWidth; +/// What a click on a control's side label does. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum LabelPress { + /// A click focuses the control. + #[default] + Focus, + /// The label shows in the link look, and a click reports to the control's host and leaves focus alone. It is no + /// Tab stop of its own, and a drag still scrubs when `scrub` is on. + Link, +} + /// What `ContainerProps.label` holds: how the label is shown and what it does. The text is `Common.label`. #[derive(Clone, Debug, Default, PartialEq)] #[non_exhaustive] @@ -192,6 +204,8 @@ pub struct SideLabel { pub detail: Option