diff --git a/crates/ui-widgets/src/buttons/face.rs b/crates/ui-widgets/src/buttons/face.rs index 52a4908f2..0b3fa2c3c 100644 --- a/crates/ui-widgets/src/buttons/face.rs +++ b/crates/ui-widgets/src/buttons/face.rs @@ -283,7 +283,7 @@ pub(super) fn metrics(cx: &StyleCx<'_>, parts: &VariantParts) -> Metrics { // (`ControlPlace::Ribbon`): its sides take the control's padding, as a ribbon's controls sit close. let side = if super::flat_in_ribbon(cx) { control.pad_x } else { control.pad_x.max(round + control.gap) }; // A ribbon look's row height (`RibbonLook::row`) stands in for the control's. - Metrics::new().padding(Insets::horizontal(side)).min_size(Vec2::new(0.0, row_height(cx, control.height))).gap(control.gap) + Metrics::new().padding(Insets::horizontal(side)).min_size(Vec2::new(0.0, super::row_height(cx, control.height))).gap(control.gap) } /// The metrics of a stacked face: `metrics`, with the control's gap above and below the stack, so its height is the @@ -336,12 +336,6 @@ pub(super) fn on_surface(cx: &StyleCx<'_>, off: &VariantParts, on: &VariantParts look } -/// The height of a non-stacked button in `cx`: a ribbon look's row height (`RibbonLook::row`), else `height`. -pub(super) fn row_height(cx: &StyleCx<'_>, height: f32) -> f32 { - let look = cx.env::(); - if look.row > 0 && cx.env::() == ControlPlace::Ribbon { f32::from(look.row) } else { height } -} - /// The look of a button that shows only its icon: an icon button, or a toggle button that is `icon_only`. pub(super) struct IconFace { pub surface: SurfaceLook, @@ -369,7 +363,7 @@ pub(super) fn icon_face(cx: &StyleCx<'_>) -> IconFace { } IconFace { surface: on_surface(cx, &off, &on).radius(UiTokens::corner(cx.tokens.shape.radius.control)), - metrics: Metrics::new().min_size(Vec2::splat(row_height(cx, cx.control().height))), + metrics: Metrics::new().min_size(Vec2::splat(super::row_height(cx, cx.control().height))), glyph: IconLook::new(side, ink.on(on.text.off)), } } diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index 413f0f4ce..9e43682ae 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -121,6 +121,13 @@ impl RibbonLook { } } +/// The height of a one-line control in `cx` (a non-stacked button, a check box): a ribbon look's row height +/// (`RibbonLook::row`) in a ribbon, else `height`. +pub(crate) fn row_height(cx: &crate::style::StyleCx<'_>, height: f32) -> f32 { + let look = cx.env::(); + if look.row > 0 && cx.env::() == ControlPlace::Ribbon { f32::from(look.row) } else { height } +} + /// The side of a non-stacked button's icon or glyph in `cx`: the ribbon's small side where one is set, else `side`. pub(crate) fn small_icon(cx: &crate::style::StyleCx<'_>, side: f32) -> f32 { let small = cx.env::().small; diff --git a/crates/ui-widgets/src/choice/check.rs b/crates/ui-widgets/src/choice/check.rs index 2412a8bc1..be9bec8f0 100644 --- a/crates/ui-widgets/src/choice/check.rs +++ b/crates/ui-widgets/src/choice/check.rs @@ -49,7 +49,8 @@ impl Component for Checkbox<'_> { fn style(cx: &StyleCx<'_>, _: CheckboxStyleKey) -> CheckboxStyle { let control = cx.control(); CheckboxStyle { - metrics: Metrics::new().min_size(Vec2::new(0.0, control.height)), + // In a ribbon, the look's row height (`RibbonLook::row`), so check boxes stand at its buttons' pitch. + metrics: Metrics::new().min_size(Vec2::new(0.0, crate::buttons::row_height(cx, control.height))), focus: cx.focus_look(), well: super::indicator(cx, cx.surface(SurfaceKind::Well).radius), mark: super::mark(cx),