From 2e9fc2ab8c53ff211b481a812f6c2163b7172cc8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 13:06:53 +0000 Subject: [PATCH] Footer button width: dialog buttons are at least size.dialog.button wide, size.dialog.side_button in a column beside the body, through a Button least_width role --- crates/ui-panels/src/sections/footer.rs | 17 +++++++++++------ crates/ui-widgets/src/buttons/button.rs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/ui-panels/src/sections/footer.rs b/crates/ui-panels/src/sections/footer.rs index c5c2d14b4..bb1526dd5 100644 --- a/crates/ui-panels/src/sections/footer.rs +++ b/crates/ui-panels/src/sections/footer.rs @@ -3,8 +3,8 @@ use super::words::SectionWords; use crate::buttons::{Button, IconButton}; use crate::contract::{ - Access, BodyLayout, Common, Component, Container, ContainerProps, Cx, DropMark, DropOperation, DropTarget, NoValue, Outcome, Pad, PaintUi, - Pointer as _, PopupKind, Props as _, Role, RowAlign, Show as _, ShowContainer as _, Sizing, TooltipSpec, WordSetCx as _, + Access, BodyLayout, Common, Component, Container, ContainerProps, Cx, DropMark, DropOperation, DropTarget, LeastWidth, NoValue, Outcome, Pad, + PaintUi, Pointer as _, PopupKind, Props as _, Role, RowAlign, Show as _, ShowContainer as _, Sizing, TooltipSpec, WordSetCx as _, }; use crate::layout_components::Row; use crate::primitives::IconSpec; @@ -582,8 +582,8 @@ impl FooterBar { self } - /// A footer bar of dialog buttons, in the order of the platform's dialog convention. Show it with - /// `show_footer`. + /// A footer bar of dialog buttons, in the order of the platform's dialog convention, each at least + /// `size.dialog.button` wide (`size.dialog.side_button` in a column). Show it with `show_footer`. pub fn buttons(buttons: impl IntoIterator) -> Self { FooterBar { content: Content::Buttons(buttons.into_iter().collect()), ..FooterBar::body() } } @@ -620,6 +620,7 @@ impl FooterBar { let labels = accelerator_labels(&lettering, crate::runtime::windows::os_of(&ctx)); // Initial focus lands on the first enabled Accept button on every OS. let default_at = buttons.iter().position(|button| button.role == DialogRole::Accept && button.enabled); + let least = if column { LeastWidth::DialogSideButton } else { LeastWidth::DialogButton }; for at in display_order(&roles, crate::runtime::windows::os_of(ui.ctx()) == Os::Windows, column) { let button = &buttons[at]; let variant = match button.role { @@ -627,8 +628,12 @@ impl FooterBar { DialogRole::Destructive => Variant::DANGER, DialogRole::Cancel | DialogRole::Other => Variant::SECONDARY, }; - let mut widget = - Button::new(button.label.clone()).painted(labels[at].clone()).variant(variant).enabled(button.enabled).fill_width(column); + let mut widget = Button::new(button.label.clone()) + .painted(labels[at].clone()) + .variant(variant) + .enabled(button.enabled) + .fill_width(column) + .least_width(least); let tip = if button.enabled { button.tooltip.clone() } else { button.disabled_reason.clone().or_else(|| button.tooltip.clone()) }; if let Some(tip) = tip { widget = widget.tooltip(TooltipSpec::new(tip.clone()).disabled_text(tip)); diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index cccacc26d..eadc63458 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -1,7 +1,7 @@ //! `Button`: a push button with an optional leading and trailing icon and a busy state. use super::face::{self, FaceLook, FaceSpec}; -use crate::contract::{Common, Component, Cx, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props, Role, Styled as _}; +use crate::contract::{Common, Component, Cx, LeastWidth, MeasureCx, NoValue, Outcome, PaintUi, PartsCx, Pointer as _, Props, Role, Styled as _}; use crate::display::Spinner; use crate::primitives::{HAlign, IconSpec, PaintShape}; use crate::runtime::commands::CommandRef; @@ -148,6 +148,10 @@ pub struct Button<'a> { /// column of buttons shares one width. #[prop] fill_width: bool, + /// The least width, from a size role (a dialog's footer buttons); a longer label is wider. + #[style_key] + #[prop] + least_width: Option, /// Where the icons and the label sit in a button wider than they are: centred unless set (a full-width button /// that names an item at the reading start). #[prop] @@ -165,6 +169,7 @@ impl<'a> Button<'a> { painted: None, tint: None, fill_width: false, + least_width: None, align: HAlign::Center, } .label(label) @@ -196,10 +201,14 @@ impl Component for Button<'_> { type Output = ButtonOutput; fn style(cx: &StyleCx<'_>, key: ButtonStyleKey) -> ButtonStyle { - match key.tint { + let mut style = match key.tint { Some(tint) => ButtonStyle::tinted(cx, tint), None => ButtonStyle::of(cx), + }; + if let Some(least) = key.least_width { + style.metrics.min_size.x = style.metrics.min_size.x.max(least.points(cx.tokens)); } + style } fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {