From 8b3cd4db7fd836720f5ecbef33248a2e168a34ff Mon Sep 17 00:00:00 2001 From: Agapenordev <120006055+Agapenordev@users.noreply.github.com> Date: Mon, 2 Nov 2026 01:50:07 +0100 Subject: [PATCH] Toasts fit the window; a sticky one can always be dismissed Review: the text wrapped at the full width with the dismiss button after it, so on a narrow window the toast spilled past the screen edge, and a long notice could grow taller than the window and clip its button. Toasts are now at most the window's width (and 360 points), the text wraps in the width the button leaves and scrolls past a share of the window's height, and long texture set names are shortened in the GPU memory notice. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 19 ++++++++++++++++--- crates/ui-egui/src/viewport.rs | 8 +++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 6b89dbb6..a4c368da 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -483,6 +483,11 @@ fn toasts(app: &mut TextureCraftApp, ctx: &egui::Context) { } let tk = theme::Tokens::get(ctx); let mut dismissed = None; + // Toasts fit the window: at most 360 points wide and, for their text, a part of its height + // (longer text scrolls), so a sticky toast's dismiss button always stays on screen. + let screen = ctx.content_rect().size(); + let max_width = (screen.x - 52.0).clamp(120.0, 360.0); + let max_text_height = (screen.y * 0.35).clamp(48.0, 220.0); egui::Area::new(egui::Id::unique("toasts")).anchor(egui::Align2::RIGHT_BOTTOM, egui::vec2(-16.0, -36.0)).show(ctx, |ui| { for (i, t) in app.toasts.iter().enumerate() { egui::Frame::NONE @@ -492,10 +497,18 @@ fn toasts(app: &mut TextureCraftApp, ctx: &egui::Context) { .shadow(ui.visuals().popup_shadow) .inner_margin(egui::Margin::symmetric(10, 6)) .show(ui, |ui| { - ui.set_max_width(360.0); + ui.set_max_width(max_width); + let sticky = t.until.is_infinite(); ui.horizontal_top(|ui| { - ui.add(egui::Label::new(egui::RichText::new(&t.text).color(tk.text_strong)).wrap()); - if t.until.is_infinite() && widgets::icon_button(ui, egui_phosphor::regular::X, i18n::tr("Dismiss"), false, 18.0).clicked() { + // The text wraps in the width the dismiss button leaves. + let width = if sticky { max_width - 28.0 } else { max_width }; + ui.allocate_ui_with_layout(egui::vec2(width, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| { + egui::ScrollArea::vertical().id_salt(("toast", i)).max_height(max_text_height).show(ui, |ui| { + ui.set_max_width(width); + ui.add(egui::Label::new(egui::RichText::new(&t.text).color(tk.text_strong)).wrap()); + }); + }); + if sticky && widgets::icon_button(ui, egui_phosphor::regular::X, i18n::tr("Dismiss"), false, 18.0).clicked() { dismissed = Some(i); } }); diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index cd5f288c..3535965d 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -118,7 +118,11 @@ fn gpu_report_toasts(app: &mut TextureCraftApp, reports: crate::gpu::GpuReports) &[("name", one)], ), many => { - let mut list = many.iter().take(MAX_NAMED_SETS).map(|n| format!("\"{n}\"")).collect::>().join(", "); + let short = |n: &String| match n.char_indices().nth(MAX_NAME_CHARS) { + Some((cut, _)) => format!("\"{}...\"", &n[..cut]), + None => format!("\"{n}\""), + }; + let mut list = many.iter().take(MAX_NAMED_SETS).map(short).collect::>().join(", "); if many.len() > MAX_NAMED_SETS { list.push_str(", ..."); } @@ -141,6 +145,8 @@ fn gpu_report_toasts(app: &mut TextureCraftApp, reports: crate::gpu::GpuReports) /// Texture sets a GPU memory notice names before "...". const MAX_NAMED_SETS: usize = 5; +/// Characters of a set name in that notice (long names are cut, with "..."). +const MAX_NAME_CHARS: usize = 32; /// This frame's scene sync (compositing and GPU uploads), run by the first view drawn, after /// that view handled its input: a stroke shows in the frame it is painted, not the next.