mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 19:47:53 +00:00
look-5: the width-roles Stack story stacks its two roles, so a denser side menu no longer squeezes the column inside the trial's room (Stack::reads text-size case); a ribbon's font box is held at the small field length (FieldStyle::held_at), as wide as the old ribbon's, with its story and trial
This commit is contained in:
@@ -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>() == ControlPlace::Ribbon { field.shortest() } else { field }
|
||||
if cx.env::<ControlPlace>() == ControlPlace::Ribbon { field.held_at(cx.tokens.size.length.field.sm) } else { field }
|
||||
}
|
||||
|
||||
/// The wheel steps the family through the list.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user