diff --git a/crates/ui-widgets/src/buttons/button.rs b/crates/ui-widgets/src/buttons/button.rs index 9b973a211d..e6a9e5e711 100644 --- a/crates/ui-widgets/src/buttons/button.rs +++ b/crates/ui-widgets/src/buttons/button.rs @@ -307,6 +307,7 @@ impl Component for Button<'_> { }; if key.arrangement == Arrangement::Stacked { style.metrics = face::stacked_metrics(cx, &cx.variant_look()); + style.surface = style.surface.radius(face::stacked_corners(cx)); } if let Some(least) = key.least_width { style.metrics.min_size.x = style.metrics.min_size.x.max(least.points(cx.tokens)); diff --git a/crates/ui-widgets/src/buttons/face.rs b/crates/ui-widgets/src/buttons/face.rs index ba81dec238..8f76b692ec 100644 --- a/crates/ui-widgets/src/buttons/face.rs +++ b/crates/ui-widgets/src/buttons/face.rs @@ -392,6 +392,12 @@ pub(super) fn on_surface(cx: &StyleCx<'_>, off: &VariantParts, on: &VariantParts look } +/// The corners of a stacked face's surface: the control corners. A capsule is the shape of a one-line control; over a +/// face as tall as an icon over two label lines it would stretch into an oval. +pub(super) fn stacked_corners(cx: &StyleCx<'_>) -> egui::CornerRadius { + UiTokens::corner(cx.tokens.shape.radius.control) +} + /// The look of a button that shows only its icon: an icon button, or a toggle button that is `icon_only`. pub(crate) struct IconFace { pub surface: SurfaceLook, diff --git a/crates/ui-widgets/src/buttons/toggle_button.rs b/crates/ui-widgets/src/buttons/toggle_button.rs index ac5664c217..6f07b79c3f 100644 --- a/crates/ui-widgets/src/buttons/toggle_button.rs +++ b/crates/ui-widgets/src/buttons/toggle_button.rs @@ -152,7 +152,9 @@ impl Component for ToggleButton<'_> { (face.surface, face.metrics) } else { icon.color = icon.color.on(on.text.off); - (face::on_surface(cx, &off, &on), face::metrics_of(cx, &off, key.arrangement)) + let surface = face::on_surface(cx, &off, &on); + let surface = if key.arrangement == Arrangement::Stacked { surface.radius(face::stacked_corners(cx)) } else { surface }; + (surface, face::metrics_of(cx, &off, key.arrangement)) }; // A mixed value shows the off look, as Photoshop's style toggles do; the access state tells it from off. surface.fill = surface.fill.when(Flags::MIXED, off.fill.off.rest); diff --git a/crates/ui-widgets/tests/it/buttons.rs b/crates/ui-widgets/tests/it/buttons.rs index 0db053892a..f9798c3141 100644 --- a/crates/ui-widgets/tests/it/buttons.rs +++ b/crates/ui-widgets/tests/it/buttons.rs @@ -428,6 +428,33 @@ fn in_ribbon(ui: &mut Ui, show: impl FnOnce(&mut Ui)) { ); } +/// A stacked button or toggle takes the control corners: the capsule an inline button may take, stretched over an +/// icon and two label lines, drew a pressed ribbon pen as an oval. +#[trial] +fn a_stacked_buttons_surface_keeps_control_corners_and_never_turns_oval() { + let corner = |type_name: &'static str, stacked: bool| { + let arrangement = if stacked { Arrangement::Stacked } else { Arrangement::Inline }; + let mut fixture = Fixture::new(move |ui| { + in_ribbon(ui, |ui| { + let mut on = true; + let _ = ToggleButton::new("Red Pen", Bind::bound(&mut on)).icon(IconId::new("copy")).arrangement(arrangement).show(ui); + let _ = Button::new("Pictures").icon(IconId::new("copy")).arrangement(arrangement).show(ui); + }); + }); + fixture.settle(); + let style = fixture.styles_of(type_name).into_iter().next().expect("the control resolved its style"); + let surface = style.looks.surface.clone().expect("the control has a surface"); + let label = if type_name.contains("Toggle") { "Red Pen" } else { "Pictures" }; + (f32::from(surface.radius.nw), fixture.by_label(label).expect("the control").rect) + }; + for type_name in [std::any::type_name::>(), std::any::type_name::>()] { + let (radius, rect) = corner(type_name, true); + assert!(radius < rect.height() / 4.0, "{type_name}: a stacked face's corners stay small against its height {rect:?}: {radius}"); + let (inline, _) = corner(type_name, false); + assert!(radius <= inline, "{type_name}: a stacked face is never rounder than an inline one: {radius} against {inline}"); + } +} + /// In a ribbon a push or split button that asks for no variant is flat at rest: it draws the ghost surface, and its /// sides take the control's padding, so it is narrower than a ghost button elsewhere. Anywhere else a button keeps its /// outlined default, and in a ribbon a variant it asks for stays.