diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index 15452da41e..713d252fd0 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -588,11 +588,11 @@ impl Component for FontPicker<'_> { type Style = craft_ui::text::FieldStyle; type Output = FontPickerOutput; - /// A field; in a ribbon (`ControlPlace::Ribbon`) at its shortest width (`size.length.short`), as a ribbon's font - /// box is. + /// A field; in a ribbon (`ControlPlace::Ribbon`) held at the small field length (`size.length.field.sm`), as a + /// ribbon's font box is: wide enough for a family name and its menu arrow, the same width whichever it shows. fn style(cx: &craft_ui::style::StyleCx<'_>, _: FontPickerStyleKey) -> craft_ui::text::FieldStyle { let field = craft_ui::text::FieldStyle::at(cx); - if cx.env::() == ControlPlace::Ribbon { field.shortest() } else { field } + if cx.env::() == ControlPlace::Ribbon { field.held_at(cx.tokens.size.length.field.sm) } else { field } } /// The wheel steps the family through the list. diff --git a/crates/font-manager/src/picker/stories.rs b/crates/font-manager/src/picker/stories.rs index b80aee5e58..e16debc9a3 100644 --- a/crates/font-manager/src/picker/stories.rs +++ b/crates/font-manager/src/picker/stories.rs @@ -88,6 +88,20 @@ fn font_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { show_picker(ui, data, demo("Ubuntu", FontPickerSettings::default(), FontFilters::default())) } +/// 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. +#[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() }; + craft_ui::runtime::env::with_env( + ui, + |overrides| { + overrides.values.set(craft_ui::buttons::ControlPlace::Ribbon); + }, + |ui| show_with(ui, data, demo("Ubuntu", FontPickerSettings::default(), FontFilters::default()), &catalog(), &extras), + ) +} + /// Focuses the field and types the start of a name, which opens the list on the matches. fn type_query(fixture: &mut Fixture) { fixture.key(Key::Tab, Modifiers::NONE); diff --git a/crates/font-manager/tests/it/picker.rs b/crates/font-manager/tests/it/picker.rs index ef4bb711d6..69804c1f35 100644 --- a/crates/font-manager/tests/it/picker.rs +++ b/crates/font-manager/tests/it/picker.rs @@ -313,11 +313,14 @@ fn picker_width(family: &'static str, ribbon: bool) -> f32 { fx.by_label("Font family").expect("the picker").rect.width() } -/// In a ribbon the font box is a short field, narrower than in a form, and keeps its width whichever family it shows. +/// In a ribbon the font box is held at the small field length, narrower than in a form, and keeps its width whichever +/// family it shows. #[trial] fn a_ribbons_font_box_is_short_and_keeps_its_width() { let (ribbon, standard) = (picker_width("Inter", true), picker_width("Inter", false)); assert!(ribbon < standard - 0.5, "the ribbon's font box is narrower: {ribbon} against {standard}"); + let length = craft_ui::testing::style::tokens(craft_theme::Mode::Light, craft_theme::Contrast::Standard).size.length.field.sm; + assert!((ribbon - length).abs() < 0.5, "the ribbon's font box is the small field length {length}: {ribbon}"); let long = picker_width("Source Sans Pro Semibold Condensed Extra", true); assert!((long - ribbon).abs() < 0.5, "a long family name leaves its width: {long} against {ribbon}"); } diff --git a/crates/ui-widgets/src/layout_components/stories.rs b/crates/ui-widgets/src/layout_components/stories.rs index c27e79b1af..90be485594 100644 --- a/crates/ui-widgets/src/layout_components/stories.rs +++ b/crates/ui-widgets/src/layout_components/stories.rs @@ -50,11 +50,13 @@ fn stack_fill_height(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { /// The two width roles of a content-sized stack: a side menu held at its least width with short items, and a column /// of settings whose paragraph breaks at the column's line length instead of widening it. The column also holds a /// dialog's least width, wider than its line length: where a paragraph's lines break moves with the text size, and the -/// least width keeps the story as wide in every density and text size, so it only grows as the text does. +/// least width keeps the story as wide in every density and text size, so it only grows as the text does. The two stand +/// one above the other: side by side they are wider than a trial's room, which then squeezes the column by as much as +/// a denser side menu grows, and its paragraph breaks narrower. #[story(Stack<'static>, covers = [], title = "Width roles")] fn stack_width_roles(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { outlined(ui, |ui| { - Row::new() + Stack::new() .gap(Gap::Section) .show(ui, |ui, _| { Stack::new().least_width(LeastWidth::SideMenu).gap(Gap::Tight).pad(Pad::Regular).show(ui, |ui, _| words(ui, 0..2)); diff --git a/crates/ui-widgets/src/text/mod.rs b/crates/ui-widgets/src/text/mod.rs index ceb3cd08b4..058b7a32ab 100644 --- a/crates/ui-widgets/src/text/mod.rs +++ b/crates/ui-widgets/src/text/mod.rs @@ -74,14 +74,24 @@ impl FieldStyle { self } - /// The style of a field with no field length to widen it past its shortest width (`size.length.short`): a - /// ribbon's font box, which keeps that width whichever family it shows, as a word processor's does. + /// The style of a field with no field length to widen it past its shortest width (`size.length.short`): a field + /// that keeps that width whatever it shows. #[must_use] pub fn shortest(mut self) -> FieldStyle { self.metrics = self.metrics.ideal_width(self.metrics.min_size.x); self } + /// The style of a field held at the length `width` (a `size.length` token), whatever value it shows: a ribbon's + /// font box at the small field length, as wide as a word processor's whichever family it shows. A row that lacks + /// room still narrows it to `size.length.short`. + #[must_use] + pub fn held_at(mut self, width: f32) -> FieldStyle { + let width = if width.is_finite() { width.max(self.metrics.min_size.x) } else { self.metrics.min_size.x }; + self.metrics = self.metrics.ideal_width(width); + self + } + /// The field's padding, gap and minimum size. pub fn metrics(&self) -> Metrics { self.metrics