ribbon: one row height on every tab: the overflow bar takes no room, fields take the look's row height

A row wider than its room showed a horizontal bar that took 6 px under the groups, so a tab that overflows
(every group whole under RibbonFit::Scroll) stood taller than one that fits; the edge chevrons show the overflow,
so the bar is the overlay bar. Under a look that sets RibbonLook::row, fields take that row height as buttons
and check boxes do, so three stacked fields fill the same body as three buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-28 23:01:14 +00:00
1 parent 74cd72a551
commit 5fbbf790f2
4 files changed
+55 -7

No files matched your search

+4 -2
View File
@@ -352,9 +352,11 @@ fn show_row<T: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
let _ = Region::slide(lead)
.show(ui, |ui, _| {
// The row's line is as high as its tallest group, at least the body's least height over a title line:
// every group fills the line, so the titles at the groups' feet share one line.
// every group fills the line, so the titles at the groups' feet share one line. The edge chevrons
// show the overflow, so its bar takes no room: a row that overflows stands as high as one that fits.
let owner = row_id(base, key);
let row = Row::new().id(owner).scroll(Scroll::horizontal()).fill_width().least_height(least + title_line).show(ui, |ui, _| {
let scroll = Scroll::horizontal().overlay();
let row = Row::new().id(owner).scroll(scroll).fill_width().least_height(least + title_line).show(ui, |ui, _| {
// The groups start a regular pad in from the row's start edge, as the old ribbon's did.
craft_ui::layout::place_in_flow(ui, Vec2::new(start, 0.0));
let mut row = RibbonRow { ui, base, groups: Vec::new(), title_line, launcher_side, icons, launcher: launcher.clone() };
+46
View File
@@ -14,6 +14,7 @@ use craft_ui::buttons::{Arrangement, Button, SplitButton};
use craft_ui::contract::{Bind, BodyCx, Entry, Props as _, Role, Show as _, ShowContainer as _, Sizing};
use craft_ui::layout_components::Stack;
use craft_ui::menu::MenuItem;
use craft_ui::text::NumberField;
use craft_ui::runtime::env::{Direction, Env, Label};
use craft_ui::runtime::inspect::{Element, Recorded};
use craft_ui::testing::access::Declared;
@@ -147,6 +148,51 @@ fn the_scrolling_fit_keeps_every_group_whole_and_scrolls() {
assert!(fixture.by_label("Scroll ribbon right").is_some(), "the end chevron reaches the groups past the room");
}
/// A row wider than its room stands as high as the same row in a room it fits: its overflow shows as the edge
/// chevrons, and no scroll bar takes height under the groups, so what follows the ribbon stays put on every tab.
#[trial]
fn an_overflowing_row_keeps_the_height_of_one_that_fits() {
let below = Rc::new(Cell::new(f32::NAN));
let seen = below.clone();
let mut fixture = Fixture::new(move |ui| {
let tabs = [RibbonTab::new(0_usize, "Home")];
let look = RibbonLook::default().fit(RibbonFit::Scroll);
let _ = Ribbon::new("Ribbon", &tabs, Bind::given(0_usize)).look(look).show(ui, |row, _| {
group(row, "wide", "Group", &WIDE);
});
seen.set(ui.cursor().top());
});
fixture.room(vec2(2000.0, 300.0));
fixture.settle();
assert!(fixture.by_label("Scroll ribbon right").is_none(), "the wide room fits the row");
let fits = below.get();
fixture.room(vec2(420.0, 300.0));
fixture.settle();
assert!(fixture.by_label("Scroll ribbon right").is_some(), "the narrow room overflows the row");
assert_eq!(below.get(), fits, "what follows the overflowing ribbon starts where it did when the row fit");
}
/// Under a look that sets the row height, a field in the ribbon stands as high as a one-line button, so a group of
/// fields stacked three high fills the same body as three buttons and keeps the ribbon one height.
#[trial]
fn a_ribbon_field_takes_the_looks_row_height() {
let mut fixture = Fixture::new(move |ui| {
let tabs = [RibbonTab::new(0_usize, "Home")];
let look = RibbonLook::default().row(22).fit(RibbonFit::Scroll);
let _ = Ribbon::new("Ribbon", &tabs, Bind::given(0_usize)).look(look).show(ui, |row, _| {
row.group(RibbonGroup::new("timing", "Timing", IconId::new("list").into()), |ui| {
Button::new("Start").show(ui);
NumberField::new("Duration", Bind::given(Some(0.5))).show(ui);
});
});
});
fixture.room(vec2(800.0, 300.0));
fixture.settle();
let button = fixture.by_label("Start").expect("the button shows").rect;
let field = fixture.by_label("Duration").expect("the field shows").rect;
assert_eq!(field.height(), button.height(), "the field takes the ribbon's row height, as the button does");
}
/// A collapsed group opens a popover; a menu opened from a split button inside it and a pick from that menu leave
/// the popover open, and a press outside closes it.
#[trial]
+4 -4
View File
@@ -183,8 +183,8 @@ pub struct RibbonLook {
/// 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.
/// The height of a one-line control (a non-stacked button, a check box, a field), 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,
/// Whether a ribbon strip's tabs rest in the normal text colour, as the old ribbon's did, not the muted one.
pub tab_ink: bool,
@@ -275,7 +275,7 @@ impl RibbonLook {
self
}
/// Non-stacked buttons `row` points high; 0 keeps the control's height.
/// One-line controls (non-stacked buttons, check boxes, fields) `row` points high; 0 keeps the control's height.
pub const fn row(mut self, row: u8) -> Self {
self.row = row;
self
@@ -288,7 +288,7 @@ impl RibbonLook {
}
}
/// The height of a one-line control in `cx` (a non-stacked button, a check box): a ribbon look's row height
/// The height of a one-line control in `cx` (a non-stacked button, a check box, a field): 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::<RibbonLook>();
+1 -1
View File
@@ -66,7 +66,7 @@ impl FieldStyle {
let metrics = Metrics::new()
.padding(Insets::horizontal(control.pad_x))
.gap(control.gap)
.min_size(Vec2::new(cx.tokens.size.length.short, control.height))
.min_size(Vec2::new(cx.tokens.size.length.short, crate::buttons::row_height(cx, control.height)))
.ideal_width(control.field)
// Where a row shrinks it, a field narrows to its padding and one glyph; what it shows there (an
// ellipsis, its adornments) its content measure adds.