From 9bd719e7176367394cd348ab7ff50b8c523667eb Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Fri, 20 Nov 2026 02:26:58 +0000 Subject: [PATCH] Ribbon look: RibbonLook (renamed from RibbonIcons) sets the small row height; the body least follows three rows a tight gap apart --- crates/menu/src/ribbon.rs | 24 +++++++------ crates/menu/src/ribbon/group.rs | 8 ++--- crates/menu/src/ribbon/stories.rs | 4 +-- crates/ui-widgets/src/buttons/face.rs | 35 +++++++++++-------- crates/ui-widgets/src/buttons/mod.rs | 17 ++++++--- crates/ui-widgets/src/buttons/split_button.rs | 4 +-- 6 files changed, 56 insertions(+), 36 deletions(-) diff --git a/crates/menu/src/ribbon.rs b/crates/menu/src/ribbon.rs index 931ecb635..bf666180c 100644 --- a/crates/menu/src/ribbon.rs +++ b/crates/menu/src/ribbon.rs @@ -29,7 +29,7 @@ use craft_ui::style::{ComponentStyle, StyleCx}; use craft_ui::tabs::{StripEnd, Tab, TabKind, TabRole, TabStrip, TabStripOutput}; use egui::{Id, Pos2, Rect, Response, Ui, Vec2, vec2}; -pub use craft_ui::buttons::{GroupLevel, RibbonIcons}; +pub use craft_ui::buttons::{GroupLevel, RibbonLook}; pub use gallery::{Gallery, GalleryFace, GalleryItem, GalleryMore, GalleryOutput}; use group::BodyHeight; pub use group::RibbonGroup; @@ -70,7 +70,7 @@ pub struct Ribbon<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> { /// The body of the context menu: the rows for the request that opened it. context_menu: Option>, /// The icon sides of the groups' buttons. - icons: RibbonIcons, + icons: RibbonLook, /// The icon of every group's dialog launcher. launcher: IconId, } @@ -85,7 +85,7 @@ impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> { trailing: &[], minimised: None, context_menu: None, - icons: RibbonIcons::default(), + icons: RibbonLook::default(), launcher: IconId::new("maximize_2"), } } @@ -112,10 +112,10 @@ impl<'a, T: Clone + Eq + Hash + Send + Sync + Debug + 'static> Ribbon<'a, T> { } /// The key of the tab shown: the binding's, else the first tab's. - /// The icon sides of the groups' buttons (`RibbonIcons`): an app whose ribbon icons are larger than its other - /// controls' sets them here. The framework's sides by default. - pub fn icons(mut self, icons: RibbonIcons) -> Self { - self.icons = icons; + /// How the groups' controls look (`RibbonLook`): an app whose ribbon icons, menu arrows or small rows differ + /// from its other controls sets them here. The framework's look by default. + pub fn look(mut self, look: RibbonLook) -> Self { + self.icons = look; self } @@ -279,7 +279,7 @@ fn show_row( base: Id, tabs: &[RibbonTab], key: &T, - (icons, launcher): (RibbonIcons, &IconId), + (icons, launcher): (RibbonLook, &IconId), body: &mut impl FnMut(&mut RibbonRow<'_>, &T), ) -> RegionOutput { let place = tabs.iter().position(|tab| tab.key == *key).unwrap_or(0) as f32; @@ -293,7 +293,11 @@ fn show_row( let distance = cx.style::().map_or(0.0, |style| style.slide); let lead = gap.clamp(-1.0, 1.0) * side * distance; let chevron = cx.style::().map_or(0.0, |style| style.chevron); - let least = cx.style::().map_or(0.0, |style| style.body); + // Rows a look sets stand a tight gap apart: three of them are the body's least height. + let least = match icons.row { + 0 => cx.style::().map_or(0.0, |style| style.body), + row => 3.0 * f32::from(row) + 2.0 * craft_ui::contract::Gap::Tight.points(ui), + }; let title_line = cx.style::().map_or(0.0, |style| style.title); let start = cx.style::().map_or(0.0, |style| style.start); // The row moves through the slide container's own offset, which places its body on a layer of its own. @@ -416,7 +420,7 @@ pub struct RibbonRow<'a> { /// The tallest open group content of this run, every level the row measured included. tallest: f32, /// The icon sides of the groups' buttons (`Ribbon::icons`). - icons: RibbonIcons, + icons: RibbonLook, /// The icon of every group's dialog launcher (`Ribbon::launcher_icon`). launcher: IconId, } diff --git a/crates/menu/src/ribbon/group.rs b/crates/menu/src/ribbon/group.rs index 5c5cb3d5b..20ed5ba18 100644 --- a/crates/menu/src/ribbon/group.rs +++ b/crates/menu/src/ribbon/group.rs @@ -17,7 +17,7 @@ use craft_ui::runtime::memory::{key_salt, with_session}; use craft_ui::style::TypeRole; use egui::{Id, Pos2, Rect, Ui, Vec2}; -use super::{GroupLevel, RibbonIcons, RibbonRow}; +use super::{GroupLevel, RibbonLook, RibbonRow}; craft_ui::words! { /// The words of a ribbon group. @@ -133,7 +133,7 @@ impl<'a> RibbonGroup<'a> { with_env( ui, |overrides| { - overrides.values.set(RibbonIcons::default()); + overrides.values.set(RibbonLook::default()); }, |ui| IconButton::command(icon, command.clone()).label(name).show_at(ui, at), ); @@ -144,7 +144,7 @@ impl<'a> RibbonGroup<'a> { /// One button with the group's icon and title; its popover holds the content at the full level. A press in a /// popup the content opens does not close the popover: the overlay family keeps it open. - fn collapsed(&self, ui: &mut Ui, add: &mut dyn FnMut(&mut Ui), icons: RibbonIcons) { + fn collapsed(&self, ui: &mut Ui, add: &mut dyn FnMut(&mut Ui), icons: RibbonLook) { let button = Button::new(self.title.clone()).icon(self.icon.clone()).arrangement(Arrangement::Stacked).show(ui); Popover::new(self.title.clone(), Bind::kept()).overlay(|overlay| overlay.opened_by(&button.response, Trigger::Click)).show(ui, |ui, _| { with_env( @@ -212,7 +212,7 @@ struct TitleRoom { body: f32, line: f32, /// The icon sides the group's buttons take. - icons: RibbonIcons, + icons: RibbonLook, /// The dialog launcher's icon (`Ribbon::launcher_icon`). launcher: IconId, } diff --git a/crates/menu/src/ribbon/stories.rs b/crates/menu/src/ribbon/stories.rs index 0faa8df73..63d1d48e7 100644 --- a/crates/menu/src/ribbon/stories.rs +++ b/crates/menu/src/ribbon/stories.rs @@ -10,7 +10,7 @@ use craft_ui::tabs::StripEnd; use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story}; use egui::{Event, Modifiers, PointerButton, Ui}; -use super::{Ribbon, RibbonGroup, RibbonIcons, RibbonMenuRequest, RibbonRow, RibbonTab}; +use super::{Ribbon, RibbonGroup, RibbonLook, RibbonMenuRequest, RibbonRow, RibbonTab}; /// The group titles of each tab. const GROUPS: [[&str; 4]; 3] = @@ -83,7 +83,7 @@ fn show(ui: &mut Ui, data: &mut StoryData, setup: Setup) -> StoryOutput { ribbon = ribbon.context_menu(&mut rows); } if setup.app_icons { - ribbon = ribbon.icons(RibbonIcons::new(32, 17)).launcher_icon(IconId::new("chevron_down")); + ribbon = ribbon.look(RibbonLook::new(32, 17)).launcher_icon(IconId::new("chevron_down")); } let direction = if setup.rtl { Direction::Rtl } else { Env::of(ui).direction }; let out = with_env( diff --git a/crates/ui-widgets/src/buttons/face.rs b/crates/ui-widgets/src/buttons/face.rs index 95fab548a..52a4908f2 100644 --- a/crates/ui-widgets/src/buttons/face.rs +++ b/crates/ui-widgets/src/buttons/face.rs @@ -1,7 +1,7 @@ //! What a push or toggle button shows: a leading icon (or spinner), a label and a trailing icon, centred in the //! button unless it aligns them to an edge, and the look parts the buttons share. -use super::{ControlPlace, GroupLevel, RibbonIcons}; +use super::{ControlPlace, GroupLevel, RibbonLook}; use crate::contract::{Component, Cx, MeasureCx, PaintUi, Styled as _}; use crate::list::ThumbAspect; use crate::primitives::{HAlign, IconSpec, TextLayout, TextRun}; @@ -24,7 +24,7 @@ pub(crate) struct FaceLook { pub divide_gap: f32, /// Whether a stacked face lays its block out from its top (`stacked_lines`): in a ribbon. pub stacked_top: bool, - /// The room of a trailing menu arrow where the ribbon sets one (`RibbonIcons::arrow`); else the icon side. + /// The room of a trailing menu arrow where the ribbon sets one (`RibbonLook::arrow`); else the icon side. pub arrow: Option, } @@ -34,10 +34,10 @@ impl FaceLook { let control = cx.control(); FaceLook { gap: control.gap, - stacked_icon: stacked_side(cx.tokens, control.icon, cx.env::(), cx.env::()), + stacked_icon: stacked_side(cx.tokens, control.icon, cx.env::(), cx.env::()), divide_gap: cx.tokens.space.gap.tight, stacked_top: stacked_lines(cx.env::()) > 0, - arrow: arrow_room(cx.env::(), cx.env::()), + arrow: arrow_room(cx.env::(), cx.env::()), } } } @@ -49,15 +49,15 @@ fn stacked_lines(place: ControlPlace) -> usize { if place == ControlPlace::Ribbon { 2 } else { 0 } } -/// The side of a stacked face's leading icon: the ribbon's large side where one is set (`RibbonIcons`), else the +/// The side of a stacked face's leading icon: the ribbon's large side where one is set (`RibbonLook`), else the /// large icon, or the control's own icon when that is larger. The style and the measure both take it from here, so /// the painted icon is the measured one. -pub(super) fn stacked_side(tokens: &UiTokens, control_icon: f32, place: ControlPlace, icons: RibbonIcons) -> f32 { +pub(super) fn stacked_side(tokens: &UiTokens, control_icon: f32, place: ControlPlace, icons: RibbonLook) -> f32 { if place == ControlPlace::Ribbon && icons.large > 0 { f32::from(icons.large) } else { tokens.size.icon.lg.max(control_icon) } } -/// The room a trailing menu arrow takes in a ribbon that sets one (`RibbonIcons::arrow`). -pub(crate) fn arrow_room(place: ControlPlace, icons: RibbonIcons) -> Option { +/// The room a trailing menu arrow takes in a ribbon that sets one (`RibbonLook::arrow`). +pub(crate) fn arrow_room(place: ControlPlace, icons: RibbonLook) -> Option { (place == ControlPlace::Ribbon && icons.arrow > 0).then_some(f32::from(icons.arrow)) } @@ -282,7 +282,8 @@ pub(super) fn metrics(cx: &StyleCx<'_>, parts: &VariantParts) -> Metrics { // The sides clear the corner round, so an edge never crosses the label. A ribbon's flat button has no edge at rest // (`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) }; - Metrics::new().padding(Insets::horizontal(side)).min_size(Vec2::new(0.0, control.height)).gap(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) } /// The metrics of a stacked face: `metrics`, with the control's gap above and below the stack, so its height is the @@ -335,6 +336,12 @@ 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, @@ -362,7 +369,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(cx.control().height)), + metrics: Metrics::new().min_size(Vec2::splat(row_height(cx, cx.control().height))), glyph: IconLook::new(side, ink.on(on.text.off)), } } @@ -385,7 +392,7 @@ pub(crate) fn focus(cx: &StyleCx<'_>) -> FocusLook { /// The side of a non-stacked icon as a measure takes it: the side the style paints (`small_icon`), the ribbon's small /// side where one is set, else the control's icon. pub(crate) fn measured_icon(cx: &MeasureCx<'_, C>) -> f32 { - let small = cx.env.get::().small; + let small = cx.env.get::().small; if small > 0 && cx.env.get::() == ControlPlace::Ribbon { f32::from(small) } else { cx.icon() } } @@ -396,8 +403,8 @@ pub(crate) fn measured_icon(cx: &MeasureCx<'_, C>) -> f32 { pub(crate) fn measure(cx: &MeasureCx<'_, C>, spec: &FaceSpec<'_>) -> Vec2 { let spec = &spec.at(cx.env.get::()); if spec.arrangement == Arrangement::Stacked { - let side = arrow_room(cx.env.get::(), cx.env.get::()).unwrap_or_else(|| measured_icon(cx)); - let lead_side = stacked_side(cx.tokens, cx.icon(), cx.env.get::(), cx.env.get::()); + let side = arrow_room(cx.env.get::(), cx.env.get::()).unwrap_or_else(|| measured_icon(cx)); + let lead_side = stacked_side(cx.tokens, cx.icon(), cx.env.get::(), cx.env.get::()); let lines = spec.lines(); let sizes = stacked_sizes(cx, spec, &lines, cx.room.unwrap_or(f32::INFINITY), side); let size = stack(spec, (lead_side, side), cx.gap(), &sizes, Rect::ZERO, false, false).size; @@ -411,7 +418,7 @@ pub(crate) fn measure(cx: &MeasureCx<'_, C>, spec: &FaceSpec<'_>) return Vec2::new(size.x, size.y.max(icon + keep as f32 * line.max(if spec.trail.is_some() { side } else { 0.0 }))); } let icon = measured_icon(cx); - let trail = arrow_room(cx.env.get::(), cx.env.get::()).unwrap_or(icon); + let trail = arrow_room(cx.env.get::(), cx.env.get::()).unwrap_or(icon); let fixed = spec.icons_width(icon, trail) + cx.gap() * spec.gaps() as f32; let text = if spec.label.is_empty() { Vec2::ZERO diff --git a/crates/ui-widgets/src/buttons/mod.rs b/crates/ui-widgets/src/buttons/mod.rs index e6040ee86..954516997 100644 --- a/crates/ui-widgets/src/buttons/mod.rs +++ b/crates/ui-widgets/src/buttons/mod.rs @@ -77,7 +77,7 @@ pub(crate) fn placed<'a>(cx: &crate::style::StyleCx<'a>) -> crate::style::StyleC /// (`Ribbon::icons`); outside a ribbon it changes nothing. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue)] #[env(style)] -pub struct RibbonIcons { +pub struct RibbonLook { /// A stacked button's leading icon. pub large: u8, /// Every other button's icon and glyph. @@ -85,12 +85,21 @@ pub struct RibbonIcons { /// The room a menu arrow after a label takes. Set, the ribbon's buttons draw that arrow as the small filled /// triangle right after their label, as the old ribbon drew it, in place of the stroked chevron. pub arrow: u8, + /// The height of a non-stacked button, so three of them, a tight gap apart, fill the ribbon's body (the old + /// ribbon's 22-point pitch); 0 keeps the control's height. + pub row: u8, } -impl RibbonIcons { +impl RibbonLook { /// Stacked icons `large` points square and the others `small`; 0 keeps the framework's side. pub const fn new(large: u8, small: u8) -> Self { - RibbonIcons { large, small, arrow: 0 } + RibbonLook { large, small, arrow: 0, row: 0 } + } + + /// Non-stacked buttons `row` points high; 0 keeps the control's height. + pub const fn row(mut self, row: u8) -> Self { + self.row = row; + self } /// Menu arrows as filled triangles in `arrow` points of room right after the label; 0 keeps the chevron. @@ -102,7 +111,7 @@ impl RibbonIcons { /// 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; + let small = cx.env::().small; if small > 0 && cx.env::() == ControlPlace::Ribbon { f32::from(small) } else { side } } diff --git a/crates/ui-widgets/src/buttons/split_button.rs b/crates/ui-widgets/src/buttons/split_button.rs index f87422c4d..686aeeefd 100644 --- a/crates/ui-widgets/src/buttons/split_button.rs +++ b/crates/ui-widgets/src/buttons/split_button.rs @@ -150,7 +150,7 @@ fn chevron(look: &FaceLook) -> IconSpec<'static> { if look.arrow.is_some() { IconSpec::glyph(&RIBBON_ARROW) } else { crate::controls::disclosure::DisclosureGlyph::menu_button() } } -/// The ribbon's menu arrow where it sets one (`RibbonIcons::arrow`): the small filled triangle, pointing down. +/// The ribbon's menu arrow where it sets one (`RibbonLook::arrow`): the small filled triangle, pointing down. const RIBBON_ARROW: crate::controls::disclosure::DisclosureGlyph = crate::controls::disclosure::DisclosureGlyph::new(1.0); impl Component for SplitButton<'_, T> { @@ -188,7 +188,7 @@ impl Component for SplitButton<'_, T> { /// Inline: the face and the arrow part, which sits in the end padding. Stacked: the face, whose chevron follows /// the label inside the arrow part. fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { - let arrow = face::arrow_room(cx.env.get::(), cx.env.get::()); + let arrow = face::arrow_room(cx.env.get::(), cx.env.get::()); let chevron = chevron(&FaceLook { arrow, ..cx.style.face.clone() }); let face = face::measure(cx, &self.spec(cx.resolved.label, &chevron)); match self.arrangement {