From d86a6015a8daf81095d7af35b61228dd4c49531f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 09:35:13 -0500 Subject: [PATCH] red round 4 (fw-widgets, Opus): fixes for fw-run-5 (runs/fw-run-5/fw-widgets.md); committed by the lead Co-Authored-By: Claude Opus 5.5 --- .../ui-contract/src/runtime/commands/board.rs | 16 +++ .../ui-contract/src/runtime/commands/mod.rs | 2 + crates/ui-contract/src/runtime/overlay.rs | 11 ++ crates/ui-contract/src/runtime/wheel.rs | 15 +- crates/ui-contract/src/testing/fixture.rs | 5 +- crates/ui-contract/src/testing/story.rs | 11 +- .../src/testing/suite/activation.rs | 16 ++- .../ui-contract/src/testing/suite/pointer.rs | 2 +- .../ui-contract/src/testing/suite/variants.rs | 6 +- crates/ui-widgets/src/buttons/button.rs | 97 ++----------- .../ui-widgets/src/buttons/command_search.rs | 131 ++++++++++++++++++ crates/ui-widgets/src/buttons/icon_button.rs | 6 +- crates/ui-widgets/src/buttons/mod.rs | 6 +- crates/ui-widgets/src/buttons/stories.rs | 29 ++-- crates/ui-widgets/tests/it/popover/popup.rs | 18 ++- .../ui-widgets/tests/it/text/rtl_paragraph.rs | 10 +- 16 files changed, 238 insertions(+), 143 deletions(-) create mode 100644 crates/ui-widgets/src/buttons/command_search.rs diff --git a/crates/ui-contract/src/runtime/commands/board.rs b/crates/ui-contract/src/runtime/commands/board.rs index 65207fb9b..38e31ac6e 100644 --- a/crates/ui-contract/src/runtime/commands/board.rs +++ b/crates/ui-contract/src/runtime/commands/board.rs @@ -112,6 +112,9 @@ pub(crate) struct Board { shown: ShownMap, /// The scope each child scope is declared inside: an instance of the child is also an instance of the parent. parents: HashMap<&'static str, &'static str>, + /// The commands fired since the testing kit last took them (`observe_fired`); `None` until it first does. + #[cfg(feature = "testing")] + observed: Option>, } /// What `set_input` changed for the readers of command states, which each pass of the frame notes before any component @@ -679,6 +682,13 @@ pub(crate) fn take_fired(ctx: &Context) -> Vec { with(ctx, |board| std::mem::take(&mut board.out)) } +/// The commands fired since the last call, whatever they were routed to, and from now on records them: the testing +/// kit's story observer takes them around each pass of a story. Nothing is recorded before the first call. +#[cfg(feature = "testing")] +pub(crate) fn observe_fired(ctx: &Context) -> Vec { + with(ctx, |board| board.observed.replace(Vec::new()).unwrap_or_default()) +} + /// The app-scope commands a key press fired while only the app's own command state disabled them, since the last /// call. pub(crate) fn take_declined(ctx: &Context) -> Vec { @@ -940,6 +950,12 @@ pub(crate) fn resolve_scoped(ctx: &Context, chain: &CommandChain, command: &Comm } fn queue(ctx: &Context, fired: Fired) { + #[cfg(feature = "testing")] + with(ctx, |board| { + if let Some(observed) = &mut board.observed { + observed.push(fired.command.clone()); + } + }); // An edit command goes to the focused component that lists it; otherwise it goes to the instance that declared // it or, with none, stays an app command. if fired.phase != FirePhase::Release diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index e3e665570..21a58a0c5 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -22,6 +22,8 @@ pub use board::focus_within; #[cfg(feature = "testing")] #[doc(hidden)] pub use board::keymap_builds; +#[cfg(feature = "testing")] +pub(crate) use board::observe_fired; pub(crate) use board::publish as publish_for; pub(crate) use board::take as take_for_instance; pub(crate) use board::{ diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index 1553099a3..fc034f858 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -207,6 +207,8 @@ pub(crate) struct Pass { last: Vec, /// The layers whose bodies are running and the tier each shows in, innermost last. drawing: Vec<(Id, Tier)>, + /// Whether each body of `drawing` is that of a layer fading out, in the same order. + exiting: Vec, /// The side of its anchor each anchored layer was placed on this pass, set before its body runs. sides: Vec<(Id, Side)>, /// The map from its parent's layer space to screen space of each layer container shown this pass, set by its host @@ -273,6 +275,7 @@ fn with_pass(ctx: &Context, f: impl FnOnce(&mut Pass) -> R) -> R { pass.last.clear(); } pass.drawing.clear(); + pass.exiting.clear(); pass.sides.clear(); pass.spaces.clear(); pass.activated.clear(); @@ -473,6 +476,7 @@ pub(crate) fn begin_layer(ctx: &Context, id: Id, tier: Tier, exiting: bool, side let reopened = reopened(ctx, id, exiting); with_pass(ctx, |pass| { pass.drawing.push((id, tier)); + pass.exiting.push(exiting); if let Some(side) = side { pass.sides.push((id, side)); } @@ -556,9 +560,16 @@ pub(crate) fn released_inside(ctx: &Context, rect: Rect) -> bool { pub(crate) fn end_layer(ctx: &Context) { with_pass(ctx, |pass| { pass.drawing.pop(); + pass.exiting.pop(); }); } +/// Whether the running code is inside the body of a layer that fades out, which takes no input: nor does any layer +/// opened inside it. +pub(crate) fn drawing_exiting(ctx: &Context) -> bool { + with_pass(ctx, |pass| pass.exiting.iter().any(|exiting| *exiting)) +} + /// Records that the component `id` was activated: the innermost layer whose body is running around it, other than the /// one `id` is the container of, and the menus the walk out of that layer crosses (`focus::menus_closed_from`) may /// close on it (`Dismiss.on_activate`). An activation in a popup opened from a field inside a menu leaves that menu diff --git a/crates/ui-contract/src/runtime/wheel.rs b/crates/ui-contract/src/runtime/wheel.rs index 33678cc50..3e5df225b 100644 --- a/crates/ui-contract/src/runtime/wheel.rs +++ b/crates/ui-contract/src/runtime/wheel.rs @@ -145,8 +145,12 @@ impl State { } } -/// Registers a taker for next pass's split. +/// Registers a taker for next pass's split. A layer that fades out takes no input, so a taker in its body registers +/// none: it would hold the wheel over what already shows through it. pub(crate) fn register(ctx: &Context, taker: WheelTaker) { + if crate::runtime::overlay::drawing_exiting(ctx) { + return; + } crate::runtime::replay::journal(ctx, || move |ctx: &Context| register(ctx, taker)); PerViewport::::with(ctx, pass::current_viewport(ctx), |state| state.this.push(taker)); } @@ -195,7 +199,6 @@ pub(crate) fn begin(ctx: &Context) { .map(|at| pointer::press_winner(ctx, at, pass_pointer.press_targets).map(|(winner, _)| winner.owner)); // A modal layer holds the wheel, except over the canvas it keeps open and inside its own family. let blocked = hover.is_some_and(|at| !sampler::wheel_allowed(ctx, at)); - let had_wheel = wheel_in.is_some(); let wake = PerViewport::::with(ctx, viewport, |state| { state.last = std::mem::take(&mut state.this); state.shares.clear(); @@ -276,14 +279,6 @@ pub(crate) fn begin(ctx: &Context) { } // A value control that owns the running gesture hears its end without a timer of its own: a pass at the gap. // An owed ease pays in the passes that follow. - if had_wheel { - eprintln!( - "DIAG popover::popup::the_wheel_over_an_open_popup_list_scrolls_the_list_and_not_the_surface_below: wheel hover {hover:?} blocked {blocked} by_position {by_position} gesture owner {:?} shares {:?} under {:?}", - state.gesture.owner, - state.shares.iter().map(|(owner, share)| (*owner, share.scroll)).collect::>(), - state.last.iter().filter(|taker| hover.is_some_and(|at| taker.rect.contains(at))).collect::>() - ); - } state.wake(now) }); if let Some(seconds) = wake { diff --git a/crates/ui-contract/src/testing/fixture.rs b/crates/ui-contract/src/testing/fixture.rs index 79cd3eb21..ff5f5d032 100644 --- a/crates/ui-contract/src/testing/fixture.rs +++ b/crates/ui-contract/src/testing/fixture.rs @@ -189,11 +189,14 @@ impl Fixture { let mut fixture = Fixture::new(move |ui| { let number = shared_pass.get() + 1; shared_pass.set(number); - let output = if shared_probed.get() { + // What fired before the story's code ran (a shortcut the input hook took) is not the story's. + crate::runtime::commands::observe_fired(ui.ctx()); + let mut output = if shared_probed.get() { probed_pass(ui, number, scope, show, &shared_data, &shared_delivers, &shared_impure) } else { shown(ui, scope, show, &shared_data) }; + output.fired = crate::runtime::commands::observe_fired(ui.ctx()); shared_root.set(output.id); shared_outputs.borrow_mut().push(output); }); diff --git a/crates/ui-contract/src/testing/story.rs b/crates/ui-contract/src/testing/story.rs index d58471713..66d0c5432 100644 --- a/crates/ui-contract/src/testing/story.rs +++ b/crates/ui-contract/src/testing/story.rs @@ -2,7 +2,7 @@ use super::Fixture; use crate::contract::{CollectionEvent, Inner, Outcome, TooltipSpec}; -use crate::runtime::commands::CommandInput; +use crate::runtime::commands::{CommandInput, CommandRef}; use craft_behavior::{EditEvent, EditEvents, PartKey, PartRef, Value}; use egui::{Id, Response, Ui, Vec2}; use std::any::{Any, TypeId}; @@ -507,6 +507,9 @@ pub struct StoryOutput { pub edits: Vec, /// The pass reported a click, by pointer or by keyboard activation. pub clicked: bool, + /// The commands the story's pass fired, in order; the fixture that shows the story fills it in. A component bound + /// to a command reports its activation as the command it fires, not as a click. + pub fired: Vec, /// The collection events' kinds, in drawing order. pub collection: Vec, /// The positions a collection showed. @@ -526,6 +529,12 @@ impl StoryOutput { self } + /// Whether the pass activated what the story shows: it reported a click, or it fired a command, as a component + /// bound to one does in place of the click. + pub fn activated(&self) -> bool { + self.clicked || !self.fired.is_empty() + } + pub(crate) fn from_response(response: &Response) -> Self { StoryOutput { id: Some(response.id), clicked: super::contract::clicked(response), ..StoryOutput::default() } } diff --git a/crates/ui-contract/src/testing/suite/activation.rs b/crates/ui-contract/src/testing/suite/activation.rs index 82ed6bd1b..1922c7d30 100644 --- a/crates/ui-contract/src/testing/suite/activation.rs +++ b/crates/ui-contract/src/testing/suite/activation.rs @@ -41,7 +41,7 @@ fn each_activation_clicks_once(subject: &Subject) -> Result<(), String> { let mut fixture = input_fixture(story); fixture.take_outputs(); run(&mut fixture, plan, variant); - let clicks = fixture.take_outputs().iter().filter(|output| output.clicked).count(); + let clicks = fixture.take_outputs().iter().filter(|output| output.activated()).count(); if clicks != 1 { return Err(format!("{}: {} gave {clicks} clicks", story.name, variant_name(plan, variant))); } @@ -97,7 +97,7 @@ fn each_part_activates_once(subject: &Subject) -> Result<(), String> { } } fixture.settle(); - let clicks = fixture.take_outputs().iter().filter(|output| output.clicked).count(); + let clicks = fixture.take_outputs().iter().filter(|output| output.activated()).count(); if clicks != 1 { return Err(format!("{}: {name} on the part {part:?} gave {clicks} clicks", story.name)); } @@ -145,7 +145,7 @@ fn declared_actions_are_handled(subject: &Subject) -> Result<(), String> { fixture.access(kind, &target); fixture.settle(); let outputs = fixture.take_outputs(); - let acted = outputs.iter().any(|output| output.clicked || !output.edits.is_empty()) + let acted = outputs.iter().any(|output| output.activated() || !output.edits.is_empty()) || signature(fixture.tree()) != before || fixture.focused() != focus; if !acted { @@ -219,7 +219,7 @@ fn every_intent_has_a_declared_action(subject: &Subject) -> Result<(), String> { _ => by_key, }); let could_step = step.is_some_and(|step| if step == Declared::Increment { steps_before.0 } else { steps_before.1 }); - let clicked = fixture.take_outputs().iter().any(|output| output.clicked); + let clicked = fixture.take_outputs().iter().any(|output| output.activated()); let changed = !lent && !fixture.data().changed_since(&before).is_empty(); let radios = fixture.tree().with_role(Role::RADIO_BUTTON); let tree = fixture.tree(); @@ -305,7 +305,7 @@ fn escape_and_blur_cancel_a_press(subject: &Subject) -> Result<(), String> { fixture.settle(); let outputs = fixture.take_outputs(); let ended = outputs.iter().flat_map(|output| output.edits.iter()).any(|kind| matches!(kind, EditKind::Commit | EditKind::Set)); - if outputs.iter().any(|output| output.clicked) || ended || !fixture.data().changed_since(&before).is_empty() { + if outputs.iter().any(|output| output.activated()) || ended || !fixture.data().changed_since(&before).is_empty() { return Err(format!("{}: a press cancelled by {} still acted", story.name, if escape { "Escape" } else { "blur" })); } } @@ -332,7 +332,9 @@ fn removal_cancels_a_press(subject: &Subject) -> Result<(), String> { if shared_hidden.get() { return; } - let output = show(ui, &mut shared_data.borrow_mut()); + crate::runtime::commands::observe_fired(ui.ctx()); + let mut output = show(ui, &mut shared_data.borrow_mut()); + output.fired = crate::runtime::commands::observe_fired(ui.ctx()); shared_id.set(output.id); shared_outputs.borrow_mut().push(output); }); @@ -352,7 +354,7 @@ fn removal_cancels_a_press(subject: &Subject) -> Result<(), String> { fixture.settle(); let outputs = std::mem::take(&mut *outputs.borrow_mut()); let ended = outputs.iter().flat_map(|output| output.edits.iter()).any(|kind| matches!(kind, EditKind::Commit | EditKind::Set)); - if outputs.iter().any(|output| output.clicked) || ended || !data.borrow().changed_since(&before).is_empty() { + if outputs.iter().any(|output| output.activated()) || ended || !data.borrow().changed_since(&before).is_empty() { return Err(format!("{}: a press whose component was not shown for a pass still acted on release", story.name)); } } diff --git a/crates/ui-contract/src/testing/suite/pointer.rs b/crates/ui-contract/src/testing/suite/pointer.rs index 3f0fcc4ca..20c396516 100644 --- a/crates/ui-contract/src/testing/suite/pointer.rs +++ b/crates/ui-contract/src/testing/suite/pointer.rs @@ -47,7 +47,7 @@ fn slop_separates_click_from_drag(subject: &Subject) -> Result<(), String> { let target = target(&fixture); fixture.take_outputs(); gesture(&mut fixture, &target, by); - let clicks = fixture.take_outputs().iter().filter(|output| output.clicked).count(); + let clicks = fixture.take_outputs().iter().filter(|output| output.activated()).count(); if clicks != expected { return Err(format!("{}: a press moved {by} points (slop {slop}) gave {clicks} clicks, expected {expected}", story.name)); } diff --git a/crates/ui-contract/src/testing/suite/variants.rs b/crates/ui-contract/src/testing/suite/variants.rs index 98fe66ce3..6ae8a71a4 100644 --- a/crates/ui-contract/src/testing/suite/variants.rs +++ b/crates/ui-contract/src/testing/suite/variants.rs @@ -22,17 +22,17 @@ pub(super) const CASES: &[Case] = &[ Case::new("language", ANY, a_language_change_keeps_the_ids), ]; -/// Whether the drive changed a value, reported an edit or reported a click. +/// Whether the drive changed a value, reported an edit or activated the story: a click or a fired command. fn acted(fixture: &mut Fixture, before: &crate::testing::story::StorySnapshot) -> bool { let changed = !fixture.data().changed_since(before).is_empty(); let outputs = fixture.take_outputs(); - changed || outputs.iter().any(|output| output.clicked || !output.edits.is_empty()) + changed || outputs.iter().any(|output| output.activated() || !output.edits.is_empty()) } /// A disabled component changes no value, fires no command and takes no focus unless it explains itself: a node /// with a description stands for the tooltip of `disabled_text`, and then its tooltip shows on focus. A description /// also comes from an invalid state, so a disabled story that takes no focus is not read as lacking `disabled_text`. -/// A story with `disabled_text` is reached by Tab and shows that reason. A story binds no command, so a fired command is read as the pass's click, which a bound command follows. +/// A story with `disabled_text` is reached by Tab and shows that reason. fn disabled_changes_nothing(subject: &Subject) -> Result<(), String> { for story in &subject.stories { let plan = subject.base(story).plan; diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index 925fb455c..b27b0b46c 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -2,16 +2,15 @@ use super::face::{self, FaceLook, FaceSpec}; use crate::contract::{Common, Component, Cx, LeastWidth, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props, Role, Styled as _}; -use crate::display::{Kbd, Spinner}; +use crate::display::Spinner; use crate::primitives::{HAlign, IconSpec, PaintShape}; use crate::runtime::commands::CommandRef; use crate::runtime::env::Label; use crate::style::{ComponentStyle, DataColor, FocusLook, IconLook, StyleColor, StyleCx, SurfaceLook, TextLook, TypeRole}; -use crate::text::FieldStyle; -use craft_behavior::{Flow, IconId, Metrics, PartKey, PressPhase, Sense}; +use craft_behavior::{Metrics, PartKey, PressPhase, Sense}; use craft_keymap::Mods; use craft_theme::{ - Rgba, Stateful, States, Variant, + Rgba, Stateful, Variant, variant::{Emphasis, Tone}, }; use egui::{Color32, Rect, Response, Vec2}; @@ -19,19 +18,6 @@ use std::ops::Deref; /// The part a loading button shows its spinner in. const SPINNER: PartKey = PartKey::new("spinner"); -/// The part the Search face shows its command's chord in. -const CHORD: PartKey = PartKey::new("chord"); - -/// The form of a button's face. -#[non_exhaustive] -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -pub enum ButtonForm { - /// The ordinary push button. - #[default] - Push, - /// The command-search opener: a text field's face with the search glyph, the placeholder and the command's chord. - Search, -} /// The style of a push button. #[derive(Clone, Debug, PartialEq, ComponentStyle)] @@ -70,24 +56,6 @@ impl ButtonStyle { } } - /// The style of the command-search opener: a text field's surface, padding and glyph, and the label in the - /// colour a field's placeholder takes. - fn search(cx: &StyleCx<'_>) -> ButtonStyle { - let field = FieldStyle::at(cx); - let text = &cx.tokens.color.text; - let (faint, off) = (cx.color(text.faint), cx.color(text.disabled)); - ButtonStyle { - // A button carries no value, so it is never invalid: the well without the field's failure edge. - surface: cx.text_well(), - metrics: field.metrics(), - focus: face::focus(cx), - text: TextLook::new(TypeRole::Body, Stateful::new(faint).off(States::new(faint, faint, faint, off))), - icon: field.glyph().clone(), - face: FaceLook::of(cx), - overlay: cx.state_layer(), - } - } - /// The style of a button whose face is filled with `tint`: the label and icons read on it. fn tinted(cx: &StyleCx<'_>, tint: Rgba) -> ButtonStyle { let mut style = ButtonStyle::of(cx); @@ -184,12 +152,6 @@ pub struct Button<'a> { /// that names an item at the reading start). #[prop] align: HAlign, - /// The face: a push button, or the command-search opener. - #[style_key] - #[prop] - form: ButtonForm, - /// The command whose chord the Search face shows at its end. - chord: Option, } impl<'a> Button<'a> { @@ -204,39 +166,20 @@ impl<'a> Button<'a> { tint: None, least_width: None, align: HAlign::Center, - form: ButtonForm::Push, - chord: None, } .label(label) } - /// The command-search opener: a search field's face showing `placeholder` and the chord of `command`. The - /// placeholder is the button's name; cut to fit, it shows whole in the tooltip. A click, Enter or Space fires - /// `command`. - pub fn search(command: impl Into, placeholder: impl Into