mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 16:17:55 +00:00
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
This commit is contained in:
@@ -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<Item = FooterButton>) -> 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));
|
||||
|
||||
@@ -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<LeastWidth>,
|
||||
/// 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 {
|
||||
|
||||
Reference in New Issue
Block a user