From 80e46cf00e9a7bb53276cd7a0c2df3be5ae538c9 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 17:11:23 +0700 Subject: [PATCH] ui-widgets: IconButton::choice reads as a combo box named by its label, valued by the picked row, expanded while the container hung from it is open (contract::overlay::opened_from) --- crates/ui-contract/src/contract/overlay.rs | 2 +- .../src/contract/overlay/container_open.rs | 7 ++-- crates/ui-widgets/src/buttons/icon_button.rs | 34 ++++++++++++++++--- crates/ui-widgets/src/buttons/stories.rs | 28 +++++++++++++-- crates/ui-widgets/tests/it/buttons.rs | 27 ++++++++++++++- 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/crates/ui-contract/src/contract/overlay.rs b/crates/ui-contract/src/contract/overlay.rs index ae2654a2ad..5974d4d2c7 100644 --- a/crates/ui-contract/src/contract/overlay.rs +++ b/crates/ui-contract/src/contract/overlay.rs @@ -16,7 +16,7 @@ mod props; mod toggles; mod ui; -pub use container_open::Popup; +pub use container_open::{Popup, opened_from}; pub(crate) use container_open::{opener_open, set_opener_open}; pub use host::paint_frame_layers; pub(crate) use host::{Layer, forget_layer, host, host_window}; diff --git a/crates/ui-contract/src/contract/overlay/container_open.rs b/crates/ui-contract/src/contract/overlay/container_open.rs index c5223b1a9f..232ac6d6e5 100644 --- a/crates/ui-contract/src/contract/overlay/container_open.rs +++ b/crates/ui-contract/src/contract/overlay/container_open.rs @@ -61,8 +61,11 @@ pub(crate) fn opener_open(stage: &mut MemoryStage, first: &Opener) -> bool { open } -/// Whether the container hung from the opener `opener` (the id of its response) is open, as its slot holds it. -pub(crate) fn opened_from(ctx: &egui::Context, opener: Id) -> bool { +/// Whether the container hung from the opener `opener` (the id of its response, [`Overlay::opened_by`]) is open, as +/// its slot holds it: an opener reports its expanded state by it. +/// +/// [`Overlay::opened_by`]: super::Overlay::opened_by +pub fn opened_from(ctx: &egui::Context, opener: Id) -> bool { MemoryStage::peek_session::(ctx, sub(opener, "opens")).open } diff --git a/crates/ui-widgets/src/buttons/icon_button.rs b/crates/ui-widgets/src/buttons/icon_button.rs index 68c6455d44..903cfe2364 100644 --- a/crates/ui-widgets/src/buttons/icon_button.rs +++ b/crates/ui-widgets/src/buttons/icon_button.rs @@ -6,6 +6,7 @@ use crate::contract::{Access, Common, Component, Cx, MeasureCx, PaintUi, PopupKi use crate::controls::disclosure::DisclosureGlyph; use crate::primitives::{IconSpec, PaintShape, StrokeWidth}; use crate::runtime::commands::CommandRef; +use crate::runtime::env::Label; use crate::style::{ComponentStyle, FocusLook, IconLook, StyleColor, StyleCx, SurfaceLook}; use craft_behavior::{Metrics, Sense}; use craft_i18n::Direction; @@ -65,7 +66,9 @@ pub enum PopupMark { /// A square button showing only an icon. Its label is its accessible name; a tooltip is the caller's. A selected /// button (`selected(true)`) shows the on look: the host owns the state and a click is reported in the response. -/// [`ButtonOutput::held`] reports the press from its start to its end. +/// [`ButtonOutput::held`] reports the press from its start to its end. A button whose menu picks one of its rows (an +/// Align To button) gives the picked row as its [`choice`](Self::choice): it then reads as a combo box named by its +/// label, with the choice as its value. #[derive(crate::contract::Component, crate::contract::Props)] pub struct IconButton<'a> { #[common] @@ -82,15 +85,27 @@ pub struct IconButton<'a> { /// that opens a menu have one. #[prop] popup_mark: PopupMark, - /// Whether the popup the button opens is open, as the host knows it. + /// Whether the popup the button opens is open, as the host knows it. A button with a [`choice`](Self::choice) + /// reports, without it, whether the container hung from it is open. #[prop(into)] expanded: Option, + /// The row the menu it opens has picked, for a button that picks one of its menu's rows. + #[prop(into)] + choice: Option