Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Font menu: hovering a font no longer grows its row and makes the list jump (#7406) (#7425)

Korg1ch9b4648e19527
diff --git a/crates/ui-egui/src/type_font_picker_tests.rs b/crates/ui-egui/src/type_font_picker_tests.rs
index 3dfe34ded..4aa25c750 100644
--- a/crates/ui-egui/src/type_font_picker_tests.rs
+++ b/crates/ui-egui/src/type_font_picker_tests.rs
@@ -83,6 +83,35 @@ fn hovering_a_font_row_sets_preview_and_leaving_clears_it() {
assert!(h.ctx.data(|d| d.get_temp::<String>(hover_id)).is_none());
}
+/// #7406: hovering a font highlights its row without moving anything: the other rows keep
+/// their place, the menu its width, and every row (the selected one too) takes one height.
+#[test]
+fn hovering_a_font_row_moves_no_other_row() {
+ let mut h = harness();
+ // The app's theme: its hovered and selected buttons draw a stroke (egui's default style
+ // would hide the jump).
+ crate::PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ h.run();
+ open(&mut h);
+ let rows = |h: &Harness<'static, State>| -> Vec<Rect> { (0..8).map(|i| h.get_by_label(&format!("Family {i:02}")).rect()).collect() };
+ let before = rows(&h);
+ let width = popup_rect(&h).expect("font menu open").width();
+ let tops: Vec<f32> = before.windows(2).map(|w| w[1].top() - w[0].top()).collect();
+ assert!(tops.windows(2).all(|t| (t[0] - t[1]).abs() < 0.01), "rows are evenly spaced, the selected Family 00 included: {tops:?}");
+ for hovered in [2, 5] {
+ h.hover_at(before[hovered].center());
+ h.run_steps(2);
+ let after = rows(&h);
+ for (i, (b, a)) in before.iter().zip(&after).enumerate() {
+ if i != hovered {
+ assert_eq!(b, a, "hovering Family {hovered:02} moved Family {i:02}");
+ }
+ }
+ assert_eq!(after[hovered].center(), before[hovered].center(), "the hovered row stays centred where it was");
+ assert_eq!(popup_rect(&h).map(|r| r.width()), Some(width), "the menu keeps its width");
+ }
+}
+
#[test]
fn clearing_the_query_restores_the_menu_height() {
let mut h = harness();
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rs
index d9a4ae992..29882cd7d 100644
--- a/crates/ui-egui/src/type_tool.rs
+++ b/crates/ui-egui/src/type_tool.rs
@@ -1517,7 +1517,11 @@ pub(crate) fn family_picker_in(
let mut hovered: Option<String> = None;
for (f, label) in rows {
- let mut button = egui::Button::selectable(f == current, label).truncate();
+ // Highlighted by its fill alone, as Photoshop's font menu is. A selectable button lays
+ // out its frame's stroke only once hovered or selected, so with the theme's stroke the
+ // row under the pointer (and the selected one) grew and pushed the rows below down:
+ // the list jumped as the pointer moved (#7406).
+ let mut button = egui::Button::selectable(f == current, label).truncate().stroke(egui::Stroke::NONE);
if let Some((size, [_, h])) = preview {
button =
button.right_text(egui::Atom::custom(ui.id().with(("font-sample", f)), egui::vec2(crate::font_preview::slot_width(ui.ctx(), f, size), h)));