mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
Merge branch 'red/fwstub-2' into area/ribbon-fw
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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() };
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user