From 3c509c622706d9e8bcb3dfeeee9aa0c81dec97c0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 01:46:34 +0000 Subject: [PATCH] Contract stubs: craft-ui-macros, craft-ui-widgets, craft-ui-panels --- crates/behavior/src/press.rs | 9 +- crates/ui-contract/src/contract/cx/edit.rs | 20 ++++- crates/ui-contract/src/contract/props.rs | 2 +- crates/ui-contract/src/primitives/draw.rs | 2 +- crates/ui-contract/src/runtime/pointer.rs | 6 +- crates/ui-macros/src/lib.rs | 13 ++- crates/ui-panels/src/dialog/alert.rs | 18 +++- crates/ui-panels/src/dialog/host.rs | 22 +++++ crates/ui-panels/src/dialog/mod.rs | 4 +- crates/ui-panels/src/dialog/prompt.rs | 17 +++- crates/ui-panels/src/dialog/prompts.rs | 17 ++++ crates/ui-panels/src/dialog/serde_fields.rs | 17 ++++ crates/ui-panels/src/docking/config.rs | 10 +++ crates/ui-panels/src/docking/floating.rs | 11 ++- crates/ui-panels/src/docking/flyout.rs | 24 +++-- crates/ui-panels/src/docking/iconic.rs | 18 +++- crates/ui-panels/src/docking/mod.rs | 6 +- crates/ui-panels/src/docking/rail.rs | 17 ++++ crates/ui-panels/src/rails/flyout.rs | 12 ++- crates/ui-panels/src/rails/tool.rs | 9 ++ crates/ui-panels/src/sections/footer.rs | 12 ++- crates/ui-widgets/src/bars/align.rs | 7 ++ crates/ui-widgets/src/bars/status.rs | 33 ++++++- crates/ui-widgets/src/bars/status_readout.rs | 4 +- crates/ui-widgets/src/list/row/output.rs | 3 + crates/ui-widgets/src/list/row/show.rs | 2 +- crates/ui-widgets/src/list/view.rs | 12 ++- crates/ui-widgets/src/menu/bar.rs | 4 +- crates/ui-widgets/src/menu/item.rs | 6 +- crates/ui-widgets/src/menu/level.rs | 20 ++--- crates/ui-widgets/src/notices/center.rs | 3 + crates/ui-widgets/src/pickers/select.rs | 18 ++-- crates/ui-widgets/src/table/view.rs | 14 ++- crates/ui-widgets/src/tabs/document.rs | 70 ++++++++++++++- crates/ui-widgets/src/tabs/rules.rs | 10 +++ crates/ui-widgets/src/tabs/strip.rs | 17 +++- crates/ui-widgets/src/text/mod.rs | 4 +- crates/ui-widgets/src/text/number.rs | 12 ++- crates/ui-widgets/src/text/number/rule.rs | 10 ++- crates/ui-widgets/src/text/number/value.rs | 47 +++++++++- crates/ui-widgets/src/text/text_field.rs | 6 +- crates/ui-widgets/src/text/words.rs | 3 + crates/ui-widgets/src/text/zoom_field.rs | 92 ++++++++++++++++++++ 43 files changed, 581 insertions(+), 82 deletions(-) create mode 100644 crates/ui-panels/src/dialog/serde_fields.rs create mode 100644 crates/ui-panels/src/docking/rail.rs create mode 100644 crates/ui-widgets/src/text/zoom_field.rs diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index c956a8920..dc9adf03d 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -314,11 +314,12 @@ impl Default for PressState { /// The longest gap between presses that still count as one multi-click, in seconds. pub const MULTI_CLICK_TIME: f64 = 0.3; -/// The click count of a press at `pos` and `time`, given the previous press `(pos, time, clicks)`: one more when -/// it follows within [`MULTI_CLICK_TIME`] and `slop` of the previous one, else 1. -pub fn count_clicks(previous: Option<(Pos2, f64, u32)>, pos: Pos2, time: f64, slop: f32) -> u32 { +/// The click count of a press at `pos` and `time` with `mods` held, given the previous press `(pos, time, clicks, +/// mods)`: one more when it follows within [`MULTI_CLICK_TIME`] and `slop` of the previous one with the same +/// modifiers, else 1. +pub fn count_clicks(previous: Option<(Pos2, f64, u32, Mods)>, pos: Pos2, time: f64, mods: Mods, slop: f32) -> u32 { match previous { - Some((place, when, count)) if time - when <= MULTI_CLICK_TIME && place.distance(pos) <= slop => count + 1, + Some((place, when, count, held)) if held == mods && time - when <= MULTI_CLICK_TIME && place.distance(pos) <= slop => count + 1, _ => 1, } } diff --git a/crates/ui-contract/src/contract/cx/edit.rs b/crates/ui-contract/src/contract/cx/edit.rs index 8b15d4456..ddd19c722 100644 --- a/crates/ui-contract/src/contract/cx/edit.rs +++ b/crates/ui-contract/src/contract/cx/edit.rs @@ -3,7 +3,9 @@ use super::context::{Cx, CxCore}; use crate::contract::{Component, EditResponse, Pointer as _, Validity, ValueOf}; use crate::primitives::Adopted; -use craft_behavior::{CancelReason, EditEvent, Gesture, GesturePhase, Mixed, PartRef, PointerButton, PressCancel, PressPhase, Sense, Value}; +use craft_behavior::{ + CancelReason, EditEvent, Gesture, GesturePhase, Mixed, PartRef, PointerButton, PressCancel, PressPhase, Sense, Value, WheelPhase, +}; use egui::{Id, Pos2}; use std::sync::Arc; @@ -334,3 +336,19 @@ impl Cx<'_, C> { } } } + +impl Cx<'_, C> { + /// Advances the component's wheel run, one edit gesture through the gesture slot: a `WheelPhase::End` share commits + /// a running run, any other notch with `Some(next)` proposes it. + #[allow(dead_code)] // P3(panels-w4): pn.C23 + pub fn wheel_run(&mut self, phase: WheelPhase, next: Option>) { + let _ = (phase, next); + todo!("pn.C23") + } + + /// Whether the running gesture is a wheel run. + #[allow(dead_code)] // P3(panels-w4): pn.C23 + pub fn in_wheel_run(&self) -> bool { + todo!("pn.C23") + } +} diff --git a/crates/ui-contract/src/contract/props.rs b/crates/ui-contract/src/contract/props.rs index 3ee025b5e..77c1252ff 100644 --- a/crates/ui-contract/src/contract/props.rs +++ b/crates/ui-contract/src/contract/props.rs @@ -233,7 +233,7 @@ pub struct Resolved<'p> { /// The padding the shape's props add on every side, over the style's: a collection's `ContainerProps::pad`. pub(crate) pad: f32, /// `Common.description`. - pub(crate) description: Option<&'p str>, + pub description: Option<&'p str>, /// `Common.tooltip`. #[doc(hidden)] pub tooltip: Option<&'p Tooltip>, diff --git a/crates/ui-contract/src/primitives/draw.rs b/crates/ui-contract/src/primitives/draw.rs index fc1b7f1aa..47c324bbb 100644 --- a/crates/ui-contract/src/primitives/draw.rs +++ b/crates/ui-contract/src/primitives/draw.rs @@ -271,7 +271,7 @@ impl<'a> Draw<'a> { /// Where `layout` of `run` starts in `rect`'s width: the free room shared out by the run's alignment, the reading /// start being the right edge in a right-to-left paragraph. - fn text_x(&self, rect: Rect, run: &TextRun<'_>, layout: &TextLayout) -> f32 { + pub fn text_x(&self, rect: Rect, run: &TextRun<'_>, layout: &TextLayout) -> f32 { let rtl = self.text_direction == Direction::Rtl && !run.ltr; rect.left() + (rect.width() - layout.size().x).max(0.0) * super::text::free_room_before(run.align, rtl) } diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 59805e8b4..e9e1eac81 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -84,7 +84,7 @@ pub struct PassPointer { #[derive(Default)] pub(crate) struct Memory { - last_press: Option<(Pos2, f64, u32)>, + last_press: Option<(Pos2, f64, u32, craft_keymap::Mods)>, press_targets: PressTargets, /// A cancel a service requested for the running pass. requested: Option<(u64, PressCancel)>, @@ -128,8 +128,8 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { let mut events = read.events.clone(); for event in &mut events { if let PointerEvent::Pressed { button: PointerButton::Primary, pos, time, clicks, .. } = event { - *clicks = count_clicks(memory.last_press, *pos, *time, hit.slop); - memory.last_press = Some((*pos, *time, *clicks)); + *clicks = count_clicks(memory.last_press, *pos, *time, latched, hit.slop); // P3(top-w2): pn.C14 + memory.last_press = Some((*pos, *time, *clicks, latched)); } } if read.primary_pressed || other_pressed { diff --git a/crates/ui-macros/src/lib.rs b/crates/ui-macros/src/lib.rs index 8b2f79886..5af192fee 100644 --- a/crates/ui-macros/src/lib.rs +++ b/crates/ui-macros/src/lib.rs @@ -151,12 +151,13 @@ struct StoryArgs { disabled_text: Option, title: Option, group: Option, + commands: Option, } impl Parse for StoryArgs { fn parse(input: ParseStream<'_>) -> syn::Result { let ty: Type = input.parse()?; - let (mut covers, mut drive, mut disabled_text, mut title, mut group) = (Vec::new(), None, None, None, None); + let (mut covers, mut drive, mut disabled_text, mut title, mut group, mut commands) = (Vec::new(), None, None, None, None, None); while input.peek(Token![,]) { input.parse::()?; if input.is_empty() { @@ -176,14 +177,16 @@ impl Parse for StoryArgs { title = Some(input.parse::()?); } else if key == "group" { group = Some(input.parse::()?); + } else if key == "commands" { + commands = Some(input.parse::()?); } else { return Err(syn::Error::new( key.span(), - "`story` takes `covers = [..]`, `drive = ..`, `disabled_text = ..`, `title = ..` and `group = ..`", + "`story` takes `covers = [..]`, `drive = ..`, `disabled_text = ..`, `title = ..`, `group = ..` and `commands = ..`", )); } } - Ok(StoryArgs { ty, covers, drive, disabled_text, title, group }) + Ok(StoryArgs { ty, covers, drive, disabled_text, title, group, commands }) } } @@ -192,6 +195,7 @@ impl Parse for StoryArgs { /// reason to show while disabled, which the story takes from `StoryData::tooltip`. `title = ".."` is the caption a /// viewer shows over the story. `group = ".."` puts the story in a named group with the type's other stories that /// name it, in declaration order; a viewer shows a group together, each story under its caption. +/// `commands = ` names a `fn(CommandInput) -> CommandInput` that sets the command states the story runs under. /// The type's registration and the story meet by the type's registered name. #[proc_macro_attribute] pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { @@ -205,6 +209,7 @@ pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { let disabled_text = args.disabled_text.as_ref().map(|text| quote!(.disabled_text(#text))); let title = args.title.as_ref().map(|title| quote!(.title(#title))); let group = args.group.as_ref().map(|group| quote!(.group(#group))); + let commands = args.commands.as_ref().map(|commands| quote!(.commands(#commands))); quote! { #func @@ -213,7 +218,7 @@ pub fn story(attr: TokenStream, item: TokenStream) -> TokenStream { env!("CARGO_PKG_NAME"), env!("CARGO_CRATE_NAME"), ::std::any::type_name::<#ty>, - ::craft_ui::testing::Story::new(#name, #ident).covers(&[#(::craft_ui::testing::Required::#covers),*]) #drive #disabled_text #title #group, + ::craft_ui::testing::Story::new(#name, #ident).covers(&[#(::craft_ui::testing::Required::#covers),*]) #drive #disabled_text #title #group #commands, ) .at(file!(), line!()) } diff --git a/crates/ui-panels/src/dialog/alert.rs b/crates/ui-panels/src/dialog/alert.rs index e0406aa70..2b59a3101 100644 --- a/crates/ui-panels/src/dialog/alert.rs +++ b/crates/ui-panels/src/dialog/alert.rs @@ -9,7 +9,8 @@ use crate::runtime::overlay::CloseReason; use crate::runtime::words::CommonWords; use crate::sections::DialogRole; use craft_theme::variant::Tone; -use egui::{Response, Ui}; +use egui::{Context, Response, Ui}; +use serde_json::Value; /// What an alert reports: its response and how it closed in this pass. #[derive(Debug)] @@ -69,6 +70,13 @@ impl<'a> Alert<'a> { self } + /// The alert that reports a typed value clamped to its range, worded by the text family's range sentences: the + /// whole-number one when `alert.whole`, the value one when it has a unit, else the number one. + pub fn range(title: impl Into