From 74379e51c0aaf557eaceac232695e13b4b908cab Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 16:07:17 +0000 Subject: [PATCH 1/2] fwstub-2: a right-to-left measure with no room limit along x gives the body a scrolling region's width, not an unbounded one, so its left edge is never -inf and a scrolling body's region never NaN (regions); trial: a vertically scrolling container in an RTL row that does not fit Co-Authored-By: Claude Opus 5.5 --- .../ui-contract/src/contract/body/regions.rs | 5 ++++ crates/ui-contract/tests/it/layout/body.rs | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index f2d28b2bc..db356df4f 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -400,6 +400,11 @@ impl<'b> BodyHooks<'b> { } else { inner.width() }; + // A measure with no room limit along x offers an unbounded width. Left to right the body runs from its start + // edge to +inf as egui allows; right to left its start edge is the right one, and an unbounded width would put + // its left edge at -inf and every rect laid out from it at NaN. It is as wide as a scrolling region there, as + // the measuring rect is (`measure_run`). + let width = if rtl && !width.is_finite() { crate::contract::MAX_EXTENT } else { width }; let (left, right) = if rtl { (inner.max.x - width, inner.max.x) } else { (inner.min.x, inner.min.x + width) }; let band = |top: f32, bottom: f32| Rect::from_min_max(Pos2::new(left, top), Pos2::new(right, bottom.max(top))); let header_top = inner.min.y + self.rules.above; diff --git a/crates/ui-contract/tests/it/layout/body.rs b/crates/ui-contract/tests/it/layout/body.rs index 7857a3ef7..779c7c8c6 100644 --- a/crates/ui-contract/tests/it/layout/body.rs +++ b/crates/ui-contract/tests/it/layout/body.rs @@ -243,3 +243,32 @@ fn the_end_region_shares_the_members_line() { let (member, end) = (member.borrow().rect, end.borrow().rect); assert!((end.center().y - member.center().y).abs() < SLACK, "the end region's probe {end:?} is off the members' line {member:?}"); } + +/// A Row in right-to-left holding a vertically scrolling container (content-sized, then filling its height) beside a +/// probe: the container, the probe inside it and the probe beside it are finite, and the container lies in the row. +#[trial] +fn a_scrolling_container_in_a_right_to_left_row_measures_and_shows_finite() { + use craft_ui::contract::Scroll; + use craft_ui_test_kit::body::Slab; + for (sizing, wide) in [(Sizing::Content, 40.0), (Sizing::FillHeight, 40.0), (Sizing::Content, 2000.0), (Sizing::FillHeight, 2000.0)] { + let (inside, beside) = (RefCell::new(Seen::default()), RefCell::new(Seen::default())); + let (region, rects) = lay_out(Some(Direction::Rtl), |ui| { + let row = Panel::new().layout(BodyLayout::row()).sizing(Sizing::FillWidth).id_salt("row").show(ui, |ui, _| { + let props = ContainerProps::new().scroll(Scroll::vertical()).sizing(sizing); + let panel = Slab::new(props).id_salt("settings").show(ui, |ui, _| { + Probe::new(&inside).size(Vec2::new(120.0, 400.0)).id_salt("inside").show(ui); + }); + Probe::new(&beside).size(Vec2::new(wide, 10.0)).sizing(Sizing::FillWidth).id_salt("beside").show(ui); + panel.output.rect + }); + vec![row.output.rect, row.inner.unwrap_or(Rect::NOTHING)] + }); + let (inside, beside) = (inside.into_inner().rect, beside.into_inner().rect); + let finite = |rect: Rect| rect.min.is_finite() && rect.max.is_finite(); + let (row, panel) = (rects[0], rects[1]); + let dump = format!("{sizing:?}: region {region:?}, row {row:?}, panel {panel:?}, inside {inside:?}, beside {beside:?}"); + assert!(finite(row) && finite(panel) && finite(inside) && finite(beside), "every rect is finite: {dump}"); + assert!(panel.width() > 100.0 && panel.max.x <= region.max.x + SLACK, "the container shows in the row: {dump}"); + assert!(panel.min.x > beside.max.x - SLACK, "under RTL the container is right of the probe after it: {dump}"); + } +} From 34abe425fa9483f3ccbf9bdd80b6a159d3949945 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 16:12:42 +0000 Subject: [PATCH 2/2] fwstub-2: in a ribbon the font picker's name field measures the short field length (size.length.short) whichever family it shows, its least, about the old ribbon's font name: a ribbon row short of room no longer narrows the box to its menu arrow; story doc; trial Co-Authored-By: Claude Opus 5.5 --- crates/font-manager/src/picker.rs | 9 ++++-- crates/font-manager/src/picker/stories.rs | 3 +- crates/font-manager/tests/it/picker.rs | 36 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index 713d252fd..15f6e002c 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -601,12 +601,15 @@ impl Component for FontPicker<'_> { } /// The width of the longest family names in common use, so the field keeps its size whichever family is picked. - /// In a ribbon the style alone sets its width (`FieldStyle::shortest`): a longer name scrolls - /// in the field, as in a word processor's font box. + /// In a ribbon the name field is the short field length (`size.length.short`) wide whichever family it shows, a + /// longer name scrolling in it as in a word processor's font box: that is its least, about the old ribbon's font + /// name, so a row short of room never narrows the box to its menu arrow; where the room allows the style holds + /// the box at the small field length (`FieldStyle::held_at`). fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { let current = cx.value().map_or("", String::as_str); let widest = [NAME_SAMPLE, current].into_iter().map(|text| cx.field_text(&TextRun::new(text))).fold(Vec2::ZERO, Vec2::max); - let widest = if cx.env.get::() == ControlPlace::Ribbon { Vec2::new(0.0, widest.y) } else { widest }; + let ribbon = cx.env.get::() == ControlPlace::Ribbon; + let widest = if ribbon { Vec2::new(cx.tokens.size.length.short, widest.y) } else { widest }; let name = cx.words::().list.clone(); let note = self.missing_note(current, &cx.words::()); Vec2::new(widest.x + reserve(cx.style, &[], &Self::trailing(name, note.is_some())), widest.y) diff --git a/crates/font-manager/src/picker/stories.rs b/crates/font-manager/src/picker/stories.rs index e16debc9a..a5d5e1e00 100644 --- a/crates/font-manager/src/picker/stories.rs +++ b/crates/font-manager/src/picker/stories.rs @@ -89,7 +89,8 @@ fn font_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { } /// The plain font box in a ribbon group's place (`ControlPlace::Ribbon`): held at the small field length whichever -/// family it shows, as a word processor's ribbon font box is. +/// family it shows, as a word processor's ribbon font box is; a row short of room narrows it no further than a name +/// field the short field length wide and its arrow. #[story(FontPicker<'static>, covers = [], title = "In a ribbon")] fn font_picker_in_ribbon(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let extras = Extras { kind: FontPickerKind::Plain, ..Extras::default() }; diff --git a/crates/font-manager/tests/it/picker.rs b/crates/font-manager/tests/it/picker.rs index 69804c1f3..1fc97f54f 100644 --- a/crates/font-manager/tests/it/picker.rs +++ b/crates/font-manager/tests/it/picker.rs @@ -325,3 +325,39 @@ fn a_ribbons_font_box_is_short_and_keeps_its_width() { assert!((long - ribbon).abs() < 0.5, "a long family name leaves its width: {long} against {ribbon}"); } +/// The width of a plain picker over "Inter" in a ribbon group's place, in a row beside a block that leaves it 60 pt of +/// the window, so the row shrinks it to its least. +fn squeezed_ribbon_picker_width() -> f32 { + use craft_ui::contract::ShowContainer as _; + let catalog = catalog_of(&[INTER_REGULAR]); + let mut fx = Fixture::new(move |ui| { + let mut family = "Inter".to_owned(); + with_env( + ui, + |overrides| { + overrides.values.set(ControlPlace::Ribbon); + }, + |ui| { + let rest = ui.available_width() - 60.0; + craft_ui::layout_components::Row::new().show(ui, |ui, _| { + let _ = FontPicker::new("Font family", Bind::bound(&mut family), &catalog).kind(FontPickerKind::Plain).show(ui); + craft_ui::testing::layout::Block::new(egui::Vec2::new(rest, 20.0)).show(ui); + }); + }, + ); + }); + fx.in_room(Room::Window); + fx.settle(); + fx.by_label("Font family").expect("the picker").rect.width() +} + +/// A ribbon row that lacks room narrows its font box no further than its least: a name field the short field length +/// (`size.length.short`) wide, about the old ribbon's font name, plus its menu arrow; never to an arrow alone. +#[trial] +fn a_squeezed_ribbon_font_box_keeps_a_short_fields_name() { + let squeezed = squeezed_ribbon_picker_width(); + let short = craft_ui::testing::style::tokens(craft_theme::Mode::Light, craft_theme::Contrast::Standard).size.length.short; + assert!(squeezed > short, "the squeezed font box keeps a name field {short} wide and its arrow: {squeezed}"); + assert!(squeezed <= picker_width("Inter", true) + 0.5, "and is no wider than where the room allows"); +} +