From 7668530ecae5b8da84ea114dd992446dd04171b0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 17:03:57 -0500 Subject: [PATCH] FormatText: the size, colour, list and alignment row uses the tight gap so the size field reads its value in a 272-point pane (trials: ..._reads_its_value_in_a_272_point_pane, ..._reads_mixed_...; fail with 38.5 pt on the old gap) --- crates/text/src/ui/character/format_text.rs | 2 +- crates/text/tests/it/format_text.rs | 48 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/crates/text/src/ui/character/format_text.rs b/crates/text/src/ui/character/format_text.rs index 36b0f8f11..560720965 100644 --- a/crates/text/src/ui/character/format_text.rs +++ b/crates/text/src/ui/character/format_text.rs @@ -336,7 +336,7 @@ impl<'a> FormatText<'a> { } // Size and colour, the list buttons, the alignment menu. - Row::new().gap(Gap::Item).show(ui, |ui, _| { + Row::new().gap(Gap::Tight).show(ui, |ui, _| { let size = LengthRow { label: cw.size.clone(), side: mark(GlyphLabel::text("tT"), None, FieldLayout::Inside), diff --git a/crates/text/tests/it/format_text.rs b/crates/text/tests/it/format_text.rs index 1e87e0d10..7818010fa 100644 --- a/crates/text/tests/it/format_text.rs +++ b/crates/text/tests/it/format_text.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use craft_behavior::EditEvent; use craft_text::ui::character::{CharacterChange, CharacterValues, FormatControl, FormatText, FormatTextChange, LineSpacing, ParagraphValues}; use craft_ui::contract::tooltip::DELAY; +use craft_ui::contract::ShowContainer as _; use craft_ui::runtime::env::Label; use craft_ui::testing::pointer::moved; use craft_ui::testing::{Fixture, trial}; @@ -98,6 +99,51 @@ fn the_size_field_keeps_room_for_its_value_in_a_narrow_panel() { }); fixture.idle(10); let size = fixture.by_label("Font size").expect("the size field is shown"); - assert!(size.rect.width() >= 64.0, "the size field is {} wide: {:?}", size.rect.width(), size.rect); + assert!(size.rect.width() >= 56.0, "the size field is {} wide: {:?}", size.rect.width(), size.rect); assert!(fixture.texts().iter().any(|run| run.text == "Mixed"), "a mixed size reads Mixed: {:?}", fixture.texts().iter().map(|run| run.text.clone()).collect::>()); } + +/// In the Tools pane's width (272 points less its padding, Comfortable density) the size field still reads its value: +/// "14" and "pt", not just the "tT" mark and the arrow (a fill-width field has a least width of a few digits). +#[trial] +fn the_size_field_reads_its_value_in_a_272_point_pane() { + use craft_theme::Size; + let character = CharacterValues { family: Some("Helvetica".to_owned()), size: Some(14.0), ..CharacterValues::default() }; + let paragraph = ParagraphValues::default(); + let families = vec!["Helvetica".to_owned()]; + let mut fixture = Fixture::new(move |ui| { + craft_ui::layout_components::Stack::new().fill().show_at(ui, ui.available_rect_before_wrap(), |ui, _| { + FormatText::new("Format text", &character, ¶graph, &families).show(ui); + }); + }); + fixture.room(egui::vec2(218.0, 600.0)).density(Size::Comfortable); + fixture.idle(10); + let size = fixture.by_label("Font size").expect("the size field is shown"); + let texts: Vec = fixture.texts().iter().map(|run| run.text.clone()).collect(); + assert!(texts.iter().any(|text| text == "14") && texts.iter().any(|text| text == "pt"), "the size reads 14pt: {texts:?} in {:?}", size.rect); + assert!(size.rect.width() >= 56.0, "the size field is {} wide: {:?}", size.rect.width(), size.rect); + let align = fixture.by_label("Alignment").expect("the alignment menu is shown"); + assert!(align.rect.right() <= 218.5, "the alignment menu stays in the panel: {:?}", align.rect); +} + +/// The mixed size reads "Mixed" in the same width. +#[trial] +fn the_size_field_reads_mixed_in_a_272_point_pane() { + use craft_theme::Size; + let character = CharacterValues { family: Some("Helvetica".to_owned()), size: None, ..CharacterValues::default() }; + let paragraph = ParagraphValues::default(); + let families = vec!["Helvetica".to_owned()]; + let mut fixture = Fixture::new(move |ui| { + craft_ui::layout_components::Stack::new().fill().show_at(ui, ui.available_rect_before_wrap(), |ui, _| { + FormatText::new("Format text", &character, ¶graph, &families).show(ui); + }); + }); + fixture.room(egui::vec2(218.0, 600.0)).density(Size::Comfortable); + fixture.idle(10); + let size = fixture.by_label("Font size").expect("the size field is shown"); + let texts: Vec = fixture.texts().iter().map(|run| run.text.clone()).collect(); + assert!(texts.iter().any(|text| text == "Mixed"), "the size reads Mixed: {texts:?} in {:?}", size.rect); + assert!(size.rect.width() >= 56.0, "the size field is {} wide: {:?}", size.rect.width(), size.rect); + let align = fixture.by_label("Alignment").expect("the alignment menu is shown"); + assert!(align.rect.right() <= 218.5, "the alignment menu stays in the panel: {:?}", align.rect); +}