Skip to content

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

Browser: the recover-unsaved-work card always shows Recover and Discard (#9472) (#9636)

rugbymaurib85d5a665c4e
diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs
index 9bc97ce83f..0917a0abba 100644
--- a/crates/ui-egui/src/ui_kit/panel.rs
+++ b/crates/ui-egui/src/ui_kit/panel.rs
@@ -1036,10 +1036,13 @@ impl<'a> Window<'a> {
if self.body_padding {
let height =
(dimension(ui.ctx().content_rect().height()) - t.form_header_height - t.form_footer_height - t.space_24 * 2.0).max(0.0);
+ // Offer the body all the room the screen leaves, not just the height the card
+ // had last frame: a card first laid out on a tiny page (a browser canvas not
+ // sized yet) would otherwise keep a body of no height, its buttons hidden (#9472).
egui::ScrollArea::vertical()
.id_salt("window_body")
.max_height(height)
- .min_scrolled_height(0.0)
+ .min_scrolled_height(height)
.auto_shrink([false, true])
.show(ui, body);
} else {
diff --git a/crates/ui-egui/src/ui_kit/panel_tests.rs b/crates/ui-egui/src/ui_kit/panel_tests.rs
index e3a38ab24a..616c86d1b2 100644
--- a/crates/ui-egui/src/ui_kit/panel_tests.rs
+++ b/crates/ui-egui/src/ui_kit/panel_tests.rs
@@ -952,6 +952,58 @@ fn required_platform_window_keeps_recovery_pending_until_an_explicit_choice() {
assert!(scenario::rect_of("dialog:footer").is_none());
}
+/// #9472: a card first laid out while the page is still tiny (a browser canvas not sized yet)
+/// grows its body once the page has its size, so the choice stays visible on every page size and
+/// scale. The browser's recovery card and the desktop one (with a footer) share this body.
+#[test]
+fn window_body_buttons_stay_visible_after_the_page_grows_from_nothing() {
+ for desktop in [false, true] {
+ for ppp in [1.0, 1.5, 2.0] {
+ for size in [egui::vec2(2992.0, 1692.0), egui::vec2(1496.0, 846.0), egui::vec2(800.0, 600.0), egui::vec2(320.0, 200.0)] {
+ let ctx = crate::fonts::test_context();
+ let mut buttons = Vec::new();
+ for page in [egui::Vec2::ZERO, egui::vec2(1.0, 1.0), egui::vec2(300.0, 150.0), size, size, size, size] {
+ let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, page);
+ let viewport = egui::ViewportInfo { native_pixels_per_point: Some(ppp), ..Default::default() };
+ let input = egui::RawInput {
+ screen_rect: Some(screen),
+ focused: true,
+ viewports: std::iter::once((egui::ViewportId::ROOT, viewport)).collect(),
+ ..Default::default()
+ };
+ buttons.clear();
+ crate::test_support::frame(&ctx, input, |ui| {
+ let window = Window::new(egui::Id::new("sc_browser_recovery"), "restore", "Recover unsaved work?");
+ let body = |ui: &mut Ui| {
+ ui.label("“Bracket” had unsaved changes when this page last closed.");
+ ui.horizontal(|ui| {
+ for label in ["Recover", "Discard"] {
+ let rect = button(ui, label, Button::Normal).rect;
+ buttons.push((label, rect, ui.clip_rect()));
+ }
+ });
+ };
+ if desktop {
+ window.actions("", "Later", None).show_with_left(ui.ctx(), true, body, |_| {});
+ } else {
+ window.required().show_body(ui.ctx(), body);
+ }
+ });
+ }
+ let screen = ctx.content_rect();
+ assert_eq!(buttons.len(), 2, "desktop {desktop}, {size:?} at {ppp}");
+ for (label, rect, clip) in &buttons {
+ assert!(rect.height() > 0.0 && rect.width() > 0.0, "{label}: desktop {desktop}, {size:?} at {ppp}: {rect:?}");
+ assert!(
+ clip.contains_rect(*rect) && screen.contains_rect(*rect),
+ "{label} hidden: desktop {desktop}, {size:?} at {ppp}: {rect:?} clipped to {clip:?} on {screen:?}"
+ );
+ }
+ }
+ }
+ }
+}
+
#[test]
fn adjoining_compact_frames_share_one_stroke_and_only_exposed_corners_round() {
use crate::ui_kit::DockEdges;