Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Truncate long app file names on the Make screen (#869)

NetterSilverffea6b7420cf
diff --git a/crates/ui-egui/src/make.rs b/crates/ui-egui/src/make.rs
index 721a31d9..9dd1ab77 100644
--- a/crates/ui-egui/src/make.rs
+++ b/crates/ui-egui/src/make.rs
@@ -365,8 +365,10 @@ fn choose_target(app: &mut CraftApp, ui: &mut Ui) {
ui.add_space(14.0);
ui.horizontal(|ui| {
ui.label(RichText::new(tr("You chose:")).size(theme::BODY).color(t.text_dim));
- ui.label(RichText::new(m.target.label()).font(theme::semibold(theme::BODY)));
- ui.label(RichText::new(crate::short_path(&path)).color(t.text_faint).size(theme::SMALL));
+ // A long name (an APK from a mirror) is cut short, whole on hover, so the row never widens the page.
+ let name = m.target.label();
+ ui.add(egui::Label::new(RichText::new(name.clone()).font(theme::semibold(theme::BODY))).truncate()).on_hover_text(name);
+ ui.add(egui::Label::new(RichText::new(crate::short_path(&path)).color(t.text_faint).size(theme::SMALL)).truncate());
});
} else if website {
ui.add_space(16.0);
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index 1f490f0c..038f428a 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -2771,3 +2771,21 @@ fn a_long_status_note_in_the_work_rows_stays_in_the_window() {
assert!(r.min.x >= 0.0 && r.max.x <= 1280.0, "the header leaves the window: {r:?}");
}
}
+
+#[test]
+fn a_very_long_app_file_name_keeps_start_inside_the_window() {
+ use craft_anything_engine::workspace::TargetRef;
+ let name = format!("{}.apk", "com.example.some-very-long-apkmirror-name-".repeat(5));
+ let path = std::path::PathBuf::from(name);
+ let mut h = harness(move || {
+ let mut a = demo::app(demo::engine(Mode::Beginner, true));
+ demo::fill_projects(&mut a);
+ a.state.make.target = TargetRef::Local { path };
+ a.state.make.game = false;
+ a
+ });
+ h.run_steps(4);
+ let content = h.ctx.content_rect();
+ let start = h.get_by_label("Start").rect();
+ assert!(start.left() >= 0.0 && start.right() <= content.right(), "Start ({start:?}) stays inside the window ({content:?})");
+}