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 <noreply@anthropic.com>
This commit is contained in:
Martin Ball
2026-11-19 16:12:42 +00:00
co-authored by Claude Opus 5.5
parent 74379e51c0
commit 34abe425fa
3 changed files with 44 additions and 4 deletions
+6 -3
View File
@@ -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>() == ControlPlace::Ribbon { Vec2::new(0.0, widest.y) } else { widest };
let ribbon = cx.env.get::<ControlPlace>() == ControlPlace::Ribbon;
let widest = if ribbon { Vec2::new(cx.tokens.size.length.short, widest.y) } else { widest };
let name = cx.words::<FontPickerWords>().list.clone();
let note = self.missing_note(current, &cx.words::<MissingFontsWords>());
Vec2::new(widest.x + reserve(cx.style, &[], &Self::trailing(name, note.is_some())), widest.y)
+2 -1
View File
@@ -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() };
+36
View File
@@ -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");
}