From acf7c9531891776a07cc28694aec0035d2655972 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Fri, 13 Nov 2026 03:07:08 -0500 Subject: [PATCH 1/2] M8: the rename and font name fields keep long text inside them (#2318) The theme gives an editor at least a field's height, taller than the one-line rename rows and frame labels, so the typed name hung below the row; the font menu's search box put its hint and text along the top. Rename editors are now centred on their row, and the search box is centred in its box through a shared widgets::search_edit. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- .../ui-egui/src/panels/typography/picker.rs | 3 +- crates/ui-egui/src/select_all_tests.rs | 56 +++++++++++++++++++ crates/ui-egui/src/widgets.rs | 19 ++++++- 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/typography/picker.rs b/crates/ui-egui/src/panels/typography/picker.rs index 1dc884569..8c0773ac4 100644 --- a/crates/ui-egui/src/panels/typography/picker.rs +++ b/crates/ui-egui/src/panels/typography/picker.rs @@ -96,8 +96,7 @@ pub(crate) fn font_picker( i.count_and_consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown) as i64 - i.count_and_consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp) as i64 }); - let search = - ui.add(egui::TextEdit::singleline(&mut q).hint_text(tr("Search fonts")).desired_width(ui.available_width()).font(regular(11.5))); + let search = widgets::search_edit(ui, &mut q, tr("Search fonts"), regular(11.5)); crate::widgets::select_all_on_focus(ui, &search, &q); if just_opened { search.request_focus(); diff --git a/crates/ui-egui/src/select_all_tests.rs b/crates/ui-egui/src/select_all_tests.rs index d86de12df..2679c94f3 100644 --- a/crates/ui-egui/src/select_all_tests.rs +++ b/crates/ui-egui/src/select_all_tests.rs @@ -140,3 +140,59 @@ fn a_field_left_mid_edit_selects_all_on_the_next_click() { assert!(ctx.memory(|m| m.has_focus(id.with("te")))); assert_eq!(selection(&ctx, id.with("te")), Some((0, 6))); } + +/// The vertical middle of the first painted text that contains `needle`, from one frame's shapes. +fn text_mid_y(shapes: &[egui::epaint::ClippedShape], needle: &str) -> Option { + fn find(s: &egui::Shape, needle: &str) -> Option { + match s { + egui::Shape::Text(t) if t.galley.text().contains(needle) => Some(t.pos.y + t.galley.rect.center().y), + egui::Shape::Vec(v) => v.iter().find_map(|s| find(s, needle)), + _ => None, + } + } + shapes.iter().find_map(|c| find(&c.shape, needle)) +} + +/// Runs one more quiet frame of `f` and returns its shapes. +fn shapes_of(ctx: &egui::Context, f: &mut impl FnMut(&mut Ui)) -> Vec { + let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0))), ..Default::default() }; + let mut out = ctx.run_ui(input, |ui| { + let mut child = ui.new_child(UiBuilder::new().max_rect(FIELD)); + f(&mut child); + }); + out.textures_delta.clear(); + out.shapes +} + +/// A rename in a row one line tall (the Layers panel's rows, a frame's name label): the typed text +/// sits in the middle of the row, not hanging below it (#2318). The theme's least height for an +/// editor is more than that row, which pushed the text down by the difference. +#[test] +fn a_rename_field_in_a_short_row_centres_its_text() { + let ctx = egui::Context::default(); + let id = Id::unique("short_rename"); + let row = Rect::from_min_size(pos2(20.0, 20.0), vec2(120.0, 16.0)); + let mut f = |ui: &mut Ui| { + widgets::rename_field(ui, id, "Frame 1", row, egui::FontId::proportional(11.0), false); + }; + click(&ctx, pos2(60.0, 28.0), None, &mut f); + assert!(ctx.memory(|m| m.has_focus(id.with("te")))); + let mid = text_mid_y(&shapes_of(&ctx, &mut f), "Frame 1").expect("the text is painted"); + assert!((mid - row.center().y).abs() <= 1.0, "text centre {mid} vs row centre {}", row.center().y); +} + +/// The font menu's search box shows its hint (and what is typed) in the middle of the box, not +/// along its top edge (#2318). +#[test] +fn the_font_search_box_centres_its_hint() { + let ctx = egui::Context::default(); + let mut q = String::new(); + let mut mid_box = 0.0; + let mut f = |ui: &mut Ui| { + let r = widgets::search_edit(ui, &mut q, "Search fonts", egui::FontId::proportional(11.5)); + mid_box = r.rect.center().y; + }; + let shapes = shapes_of(&ctx, &mut f); + let mid = text_mid_y(&shapes, "Search fonts").expect("the hint is painted"); + assert!((mid - mid_box).abs() <= 1.0, "hint centre {mid} vs box centre {mid_box}"); +} diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 8bd0b47c8..84a98bc21 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -1381,7 +1381,10 @@ pub fn text_field_inline(ui: &mut Ui, id: Id, value: &str, rect: Rect, font: egu Some(mut text) => { ui.painter().rect_filled(rect.expand(2.0), CornerRadius::same(4), t.panel); ui.painter().rect_stroke(rect.expand(2.0), CornerRadius::same(4), Stroke::new(1.0, crate::theme::ACCENT), StrokeKind::Inside); - let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect)); + // The editor is at least the theme's field height; centred on a shorter row it + // keeps its text on the row's middle line instead of hanging below it (#2318). + let edit = Rect::from_center_size(rect.center(), vec2(rect.width(), rect.height().max(FIELD_H))); + let mut child = ui.new_child(egui::UiBuilder::new().max_rect(edit)); let r = crate::bidi::single_line(&mut child, te_id, &mut text, font, rect.width()); a11y::own_focus(&r); keep_focus(&r, started); @@ -1472,3 +1475,17 @@ pub fn sublabels(ui: &mut Ui, a: &str, b: Option<&str>) { pub fn col_width(w: f32) -> f32 { ((w - PAD - PAD_RIGHT - GUTTER * 2.0 - 24.0) / 2.0).max(40.0) } + +/// The search box of a menu (the font list's): one line, as wide as the menu, its hint and text +/// centred in the box. [`egui::TextEdit`] puts the text at the top of a box taller than a line +/// unless told otherwise (#2318). +pub(crate) fn search_edit(ui: &mut Ui, text: &mut String, hint: &str, font: egui::FontId) -> Response { + ui.add( + egui::TextEdit::singleline(text) + .hint_text(hint) + .desired_width(ui.available_width()) + .font(font) + .align(Align2::LEFT_CENTER) + .min_size(vec2(0.0, FIELD_H)), + ) +} From 0d7328733e24d6012d9b39c1f2128390f97214c8 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Fri, 13 Nov 2026 12:54:54 -0500 Subject: [PATCH 2/2] M8: the font menu's search uses the shared search box (#2318) The font menu allocates a FIELD_H rect at the menu's width and calls widgets::search_box there, so it gets the same magnifier and field look as the other search boxes (field_editor selects all on focus and centres its text). widgets::search_edit is gone; the hint-centring test points at search_box, a new test checks the hint sits after the magnifier, and the font-menu regrow test's width threshold allows for the box's margin and magnifier. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/font_menu_regrow_tests.rs | 4 +-- .../ui-egui/src/panels/typography/picker.rs | 5 ++-- crates/ui-egui/src/select_all_tests.rs | 28 +++++++++++++++++-- crates/ui-egui/src/widgets.rs | 14 ---------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/font_menu_regrow_tests.rs b/crates/ui-egui/src/font_menu_regrow_tests.rs index b4a9d8804..5e095f394 100644 --- a/crates/ui-egui/src/font_menu_regrow_tests.rs +++ b/crates/ui-egui/src/font_menu_regrow_tests.rs @@ -75,13 +75,13 @@ fn centre(n: &Node) -> Pos2 { Pos2::new(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32) } -/// The top of the search field: the text input as wide as `menu` (the panel's own fields are narrower). +/// The top of the search field: the text input nearly as wide as `menu`, less the search box's margin and magnifier (the panel's own fields are narrower). fn search_top(nodes: &[Node], menu: Rect) -> f32 { let field = nodes .iter() .filter(|n| n.role() == Role::TextInput) .filter_map(|n| n.bounds()) - .find(|b| menu.contains(Pos2::new(b.x0 as f32 + 1.0, b.y0 as f32 + 1.0)) && b.x1 - b.x0 > f64::from(menu.width()) - 40.0) + .find(|b| menu.contains(Pos2::new(b.x0 as f32 + 1.0, b.y0 as f32 + 1.0)) && b.x1 - b.x0 > f64::from(menu.width()) - 60.0) .expect("the menu has a search field"); field.y0 as f32 } diff --git a/crates/ui-egui/src/panels/typography/picker.rs b/crates/ui-egui/src/panels/typography/picker.rs index 8c0773ac4..11c040805 100644 --- a/crates/ui-egui/src/panels/typography/picker.rs +++ b/crates/ui-egui/src/panels/typography/picker.rs @@ -75,6 +75,7 @@ pub(crate) fn font_picker( let just_opened = anchor.clicked(); let hi_id = Id::unique("font_highlight"); let q_id = Id::unique("font_query"); + let search_id = Id::unique("font_search"); craft_ui::combo::Menu::new(ui, anchor) .height(MENU_HEIGHT) .close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside) @@ -96,8 +97,8 @@ pub(crate) fn font_picker( i.count_and_consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown) as i64 - i.count_and_consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp) as i64 }); - let search = widgets::search_edit(ui, &mut q, tr("Search fonts"), regular(11.5)); - crate::widgets::select_all_on_focus(ui, &search, &q); + let (field, _) = ui.allocate_exact_size(vec2(ui.available_width(), widgets::FIELD_H), egui::Sense::hover()); + let search = widgets::search_box(ui, field, search_id, &mut q, tr("Search fonts")); if just_opened { search.request_focus(); } diff --git a/crates/ui-egui/src/select_all_tests.rs b/crates/ui-egui/src/select_all_tests.rs index 2679c94f3..ecb77001a 100644 --- a/crates/ui-egui/src/select_all_tests.rs +++ b/crates/ui-egui/src/select_all_tests.rs @@ -187,12 +187,36 @@ fn a_rename_field_in_a_short_row_centres_its_text() { fn the_font_search_box_centres_its_hint() { let ctx = egui::Context::default(); let mut q = String::new(); + let id = Id::unique("font_search"); let mut mid_box = 0.0; let mut f = |ui: &mut Ui| { - let r = widgets::search_edit(ui, &mut q, "Search fonts", egui::FontId::proportional(11.5)); - mid_box = r.rect.center().y; + let (field, _) = ui.allocate_exact_size(vec2(120.0, widgets::FIELD_H), egui::Sense::hover()); + widgets::search_box(ui, field, id, &mut q, "Search fonts"); + mid_box = field.center().y; }; let shapes = shapes_of(&ctx, &mut f); let mid = text_mid_y(&shapes, "Search fonts").expect("the hint is painted"); assert!((mid - mid_box).abs() <= 1.0, "hint centre {mid} vs box centre {mid_box}"); } + +/// The font menu's search field is the shared search box: its text starts after the magnifier, +/// not at the field's left edge as a bare editor's would (#2318). +#[test] +fn the_font_search_box_leaves_room_for_the_magnifier() { + fn left(s: &egui::Shape) -> Option { + match s { + egui::Shape::Text(t) if t.galley.text().contains("Search fonts") => Some(t.pos.x), + egui::Shape::Vec(v) => v.iter().find_map(left), + _ => None, + } + } + let ctx = egui::Context::default(); + let mut q = String::new(); + let id = Id::unique("font_search_icon"); + let mut f = |ui: &mut Ui| { + let (field, _) = ui.allocate_exact_size(vec2(120.0, widgets::FIELD_H), egui::Sense::hover()); + widgets::search_box(ui, field, id, &mut q, "Search fonts"); + }; + let x = shapes_of(&ctx, &mut f).iter().find_map(|c| left(&c.shape)).expect("the hint is painted"); + assert!(x >= FIELD.min.x + 20.0, "hint starts at {x}, field at {}", FIELD.min.x); +} diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 84a98bc21..ee2e7d794 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -1475,17 +1475,3 @@ pub fn sublabels(ui: &mut Ui, a: &str, b: Option<&str>) { pub fn col_width(w: f32) -> f32 { ((w - PAD - PAD_RIGHT - GUTTER * 2.0 - 24.0) / 2.0).max(40.0) } - -/// The search box of a menu (the font list's): one line, as wide as the menu, its hint and text -/// centred in the box. [`egui::TextEdit`] puts the text at the top of a box taller than a line -/// unless told otherwise (#2318). -pub(crate) fn search_edit(ui: &mut Ui, text: &mut String, hint: &str, font: egui::FontId) -> Response { - ui.add( - egui::TextEdit::singleline(text) - .hint_text(hint) - .desired_width(ui.available_width()) - .font(font) - .align(Align2::LEFT_CENTER) - .min_size(vec2(0.0, FIELD_H)), - ) -}