From 6fdd58dec69c48e0fc158aaa0a2b4c88993ae1cf Mon Sep 17 00:00:00 2001 From: jeromehzl <51324719+jeromehzl@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:58:16 +0000 Subject: [PATCH] Toasts: the corner stack keeps its full width just left of a pane at the right edge (#8804) (#8840) corner_free looked only in a fixed column at the view's right edge and took the largest free rect there by area. Next to a tall dialog docked at the right edge, or the Assistant in the Floating layout, the narrow strip beside the pane won: the toasts were squeezed into it, their text broke inside words, and with a wider pane they were not shown at all. It now tries that column first and then columns ending at each obstacle's left edge, nearest the corner first, and takes the first free rect that is TOAST_WIDTH wide and tall enough for a toast, as the frame-rate readout moves beside a right pane (#6755); failing that, a rect tall enough beats a wider one too short to show any toast. Without a pane the stack stays exactly where it was. --- crates/ui-egui/src/viewport.rs | 37 ++++++++- crates/ui-egui/src/viewport_overlays_tests.rs | 78 +++++++++++++++++++ 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 38dad4545..b03bb8832 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -5081,12 +5081,41 @@ pub(crate) const TOAST_WIDTH: f32 = 340.0; /// Where the corner stack may go: the largest free rect in a `TOAST_WIDTH` column at the right of /// `view`, clear of `obstacles` (the axis view and cube at the top, the view toolbar when a narrow -/// window brings it under the column, docked panels), less the usual margin. +/// window brings it under the column, docked panels), less the usual margin. A pane at the right +/// edge (an edge-docked dialog, the Assistant) moves the column, at full width, to its left edge +/// rather than leaving a strip beside it (#8804, as the frame-rate readout does, #6755). The first +/// candidate column that is `TOAST_WIDTH` wide and high enough wins, otherwise the best of the rest: +/// a tall enough place beats a flat one, then the wider. pub(crate) fn corner_free(view: Rect, obstacles: &[Rect]) -> Rect { let t = Tokens::get(); - let left = (view.right() - TOAST_WIDTH - 2.0 * t.space_8).max(view.left()); - let column = Rect::from_min_max(pos2(left, view.top()), view.max); - crate::viewport_layout::free_rect(column, obstacles).shrink(t.space_8) + let width = TOAST_WIDTH + 2.0 * t.space_8; + // The column's right edge: the view's, then each obstacle's left edge, nearest the corner first (at most 16). + let mut rights = vec![view.right()]; + let mut lefts: Vec = obstacles.iter().filter(|o| o.is_finite() && o.left() < view.right()).map(|o| o.left()).collect(); + lefts.sort_by(|a, b| b.total_cmp(a)); + rights.extend(lefts.into_iter().take(16)); + let min_height = 8.0 * t.space_8; // room for a one-line toast + let mut best = Rect::NOTHING; + let (mut best_fits, mut best_tall) = (false, false); + for right in rights { + let left = (right - width).max(view.left()); + let column = Rect::from_min_max(pos2(left, view.top()), pos2(right, view.bottom())); + let free = crate::viewport_layout::free_rect(column, obstacles).shrink(t.space_8); + // A strip of full width but a line high would hide the toast, so it does not fit. + let tall = free.height() >= min_height; + let fits = tall && free.width() >= TOAST_WIDTH - 0.5; + let better = + (fits, tall) > (best_fits, best_tall) || ((fits, tall) == (best_fits, best_tall) && (!best.is_positive() || free.width() > best.width())); + if better { + best = free; + best_fits = fits; + best_tall = tall; + } + if best_fits || left <= view.left() { + break; + } + } + best } /// What a toast's button is for, which sets its look and where it goes: the main action first diff --git a/crates/ui-egui/src/viewport_overlays_tests.rs b/crates/ui-egui/src/viewport_overlays_tests.rs index 1cb156d2e..a86e87469 100644 --- a/crates/ui-egui/src/viewport_overlays_tests.rs +++ b/crates/ui-egui/src/viewport_overlays_tests.rs @@ -932,6 +932,84 @@ fn corner_toasts_share_one_width_against_the_right_edge() { ToastPlace::Corner.publish(&ctx); } +/// A pane at the right edge (an edge-docked dialog, the Assistant) takes the corner column's +/// width with it: the stack moves, at full `TOAST_WIDTH`, to just left of the pane instead of +/// being squeezed into the strip beside it (#8804, as the frame-rate readout does, #6755). +#[test] +fn corner_toasts_move_left_of_a_pane_at_the_right_edge_at_full_width() { + let t = Tokens::get(); + let view = Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 1000.0)); + let axis = Rect::from_min_max(pos2(1600.0 - 8.0 - 110.0, 8.0), pos2(1592.0, 118.0)); + let alone = corner_free(view, &[axis]); + assert!((alone.right() - (view.right() - t.space_8)).abs() < 0.01, "no pane keeps the corner: {alone:?}"); + for width in [230.0, 280.0, 480.0, 760.0] { + let pane = Rect::from_min_max(pos2(1600.0 - 8.0 - width, 40.0), pos2(1592.0, 990.0)); + let free = corner_free(view, &[axis, pane]); + assert!(free.width() >= TOAST_WIDTH - 0.5, "{width}: squeezed to {free:?}"); + assert!(!free.intersects(pane), "{width}: {free:?} over {pane:?}"); + assert!(free.right() <= pane.left() - t.space_8 + 0.01, "{width}: {free:?} not left of {pane:?}"); + assert!(view.contains_rect(free), "{width}: {free:?} outside the view"); + } + // Nothing is wide enough: a tall place left of the pane beats a full-width strip a line high. + let small = Rect::from_min_size(Pos2::ZERO, vec2(1000.0, 1000.0)); + let axis = Rect::from_min_max(pos2(1000.0 - 8.0 - 110.0, 8.0), pos2(992.0, 118.0)); + let pane = Rect::from_min_max(pos2(1000.0 - 8.0 - 760.0, 40.0), pos2(992.0, 990.0)); + let free = corner_free(small, &[axis, pane]); + assert!(free.width() > 40.0 && free.height() >= 8.0 * t.space_8, "a strip too flat to show a toast: {free:?}"); + assert!(!free.intersects(pane), "{free:?} over {pane:?}"); + // Hostile input never panics or loops, and gives a finite rect or nothing. + let nan = Rect::from_min_max(pos2(f32::NAN, 0.0), pos2(10.0, f32::NAN)); + let inf = Rect::from_min_max(pos2(f32::NEG_INFINITY, f32::NEG_INFINITY), pos2(f32::INFINITY, f32::INFINITY)); + let many: Vec = (0..40).map(|i| Rect::from_min_max(pos2(i as f32 * 30.0, 0.0), pos2(i as f32 * 30.0 + 20.0, 1000.0))).collect(); + let cases: [(Rect, Vec); 5] = [ + (view, vec![nan, inf]), + (view, vec![view]), + (Rect::from_min_size(Pos2::ZERO, vec2(1.0, 1.0)), vec![axis]), + (view, many), + (Rect::NOTHING, vec![axis]), + ]; + for (v, obstacles) in &cases { + let free = corner_free(*v, obstacles); + assert!(!free.is_positive() || (free.is_finite() && v.contains_rect(free)), "{free:?} in {v:?}"); + } +} + +/// With a real dialog docked at the right edge, a long status toast stays `TOAST_WIDTH` wide left +/// of it, clear of everything covered, and goes back to the corner when the dialog closes (#8804). +#[test] +fn corner_toast_keeps_its_width_beside_a_docked_dialog() { + use crate::scenario::rect_of; + let t = Tokens::get(); + for mode in [LayoutMode::Floating, LayoutMode::Docked] { + let mut h = Harness::new(); + h.app.home.open = false; + h.call("ui.set", json!({"layout": mode})); + h.call("ui.resize", json!({"width":1600,"height":1000})); + let text = "Calibrating your 3D mouse fixes swapped or reversed axes and sets its speed and feel."; + h.app.start("parts.insert"); + h.app.status = Some((text.into(), crate::now_ms(), true)); + h.frames(3); + let dialog = h.app.viewport.dialog_rect.expect("the dialog is open"); + let layout = h.app.viewport.layout.as_ref().unwrap(); + let content = crate::shell::content_rect(&h.app, layout.viewport); + let toast = rect_of("toast").expect("the toast is drawn beside the dialog"); + assert!((toast.width() - TOAST_WIDTH).abs() < 0.5, "{mode:?}: {toast:?} beside {dialog:?}"); + assert!(!toast.intersects(dialog), "{mode:?}: {toast:?} over {dialog:?}"); + assert!(content.contains_rect(toast), "{mode:?}: {toast:?} outside {content:?}"); + for covered in crate::shell::covered_rects(&h.app) { + assert!(!toast.intersects(covered), "{mode:?}: {toast:?} under {covered:?}"); + } + h.app.dialog = None; + h.app.status = Some((text.into(), crate::now_ms(), true)); + h.frames(3); + let layout = h.app.viewport.layout.as_ref().unwrap(); + let content = crate::shell::content_rect(&h.app, layout.viewport); + let toast = rect_of("toast").expect("the toast is drawn"); + assert!((toast.right() - (content.right() - t.space_8)).abs() < 0.5, "{mode:?}: back in the corner: {toast:?} in {content:?}"); + assert!((toast.width() - TOAST_WIDTH).abs() < 0.5, "{mode:?}: {toast:?}"); + } +} + /// A dashed line reaching far off screen is cut to the view before it is dashed: epaint makes a /// shape per dash and steps along in f32, so one a trillion points long made billions of them, /// or never finished. A line in view is dashed exactly as before, and a cut one keeps its