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