Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Home: a tile keeps its title in view when its caption wraps (#7483) (#7716)

DuBeartea8d775c12a10
diff --git a/crates/ui-egui/src/ui_kit/file_view.rs b/crates/ui-egui/src/ui_kit/file_view.rs
index efade47aba..a4cb28e770 100644
--- a/crates/ui-egui/src/ui_kit/file_view.rs
+++ b/crates/ui-egui/src/ui_kit/file_view.rs
@@ -262,7 +262,7 @@ impl FileView {
caption_job.wrap.max_rows = 2;
let caption = ui.fonts_mut(|fonts| fonts.layout_job(caption_job));
let group_height = title.size().y + t.space_2 + caption.size().y;
- let top = text_rect.center().y - group_height / 2.0;
+ let top = text_top(text_rect, group_height);
let painter = ui.painter().with_clip_rect(ui.clip_rect().intersect(text_rect));
painter.galley(pos2(text_rect.left(), top), title.clone(), ink);
painter.galley(pos2(text_rect.left(), top + title.size().y + t.space_2), caption, t.file_dim);
@@ -405,6 +405,13 @@ impl FileView {
}
}
+/// Where a tile's title and caption start: centred in `area`, or at its top when they are taller
+/// (a system font with tall lines, a wrapped translation, #7483), so the caption loses its end
+/// rather than the title its top.
+pub(crate) fn text_top(area: Rect, height: f32) -> f32 {
+ (area.center().y - height / 2.0).max(area.top())
+}
+
fn allocate(ui: &mut Ui, id: &str, width: f32, height: f32, label: &str) -> (Rect, Response) {
let (rect, _) = ui.allocate_exact_size(vec2(dimension(width).min(dimension(ui.available_width())), height), Sense::hover());
let response = ui.interact(rect, ui.make_persistent_id(id), Sense::click());
diff --git a/crates/ui-egui/src/ui_kit/metrics_tests.rs b/crates/ui-egui/src/ui_kit/metrics_tests.rs
index c424d1c222..82927abdec 100644
--- a/crates/ui-egui/src/ui_kit/metrics_tests.rs
+++ b/crates/ui-egui/src/ui_kit/metrics_tests.rs
@@ -156,3 +156,12 @@ fn sample_grid_stretches_each_row_without_clipping_long_descriptions() {
assert!(cards[1].rect.contains_rect(text_rect));
assert!(long.0.contains_rect(text_rect), "the complete description must fit its clip");
}
+
+#[test]
+fn a_tile_taller_than_its_text_area_keeps_the_title_at_the_top() {
+ // #7483: centring a title and a two-row caption taller than the tile put the title's top
+ // above the tile, where it was clipped.
+ let area = egui::Rect::from_min_max(egui::pos2(0.0, 16.0), egui::pos2(100.0, 68.0));
+ assert_eq!(crate::ui_kit::file_view::text_top(area, 40.0), 22.0, "a group that fits is centred");
+ assert_eq!(crate::ui_kit::file_view::text_top(area, 60.0), 16.0, "a taller group starts at the top");
+}