Skip to content

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

Viewport: a docked Assistant beside an inverted view area no longer crashes (#9492) (#9499)

rugbymauri98bfe1af9ce0
diff --git a/crates/ui-egui/src/shell_tests.rs b/crates/ui-egui/src/shell_tests.rs
index 6a5b5064ce..d78e478e0a 100644
--- a/crates/ui-egui/src/shell_tests.rs
+++ b/crates/ui-egui/src/shell_tests.rs
@@ -1229,3 +1229,20 @@ fn a_larger_interface_scale_in_a_narrow_window_keeps_drawing() {
h.frames(3);
assert!(h.app.viewport.rect.unwrap().is_positive());
}
+
+#[test]
+fn docked_assistant_beside_an_inverted_view_area_does_not_panic() {
+ // A surface reconfigure can leave the view area inside out, its left past its right (#9492).
+ for side in ["right", "left"] {
+ let mut h = Harness::new();
+ h.app.home.open = false;
+ h.call("ui.set", json!({"layout":"floating"}));
+ h.call("ui.agent_chat", json!({"open":true,"side":side,"width":380,"picker":false}));
+ h.frames(5);
+ assert!(h.app.agent_chat.panel_rect.is_some(), "{side}: docked Assistant");
+ h.app.viewport.rect = Some(Rect::from_min_max(pos2(264.1875, 30.0), pos2(159.0, 20.0)));
+ let ctx = h.ctx.clone();
+ crate::viewport::refresh_layout(&mut h.app, &ctx);
+ assert!(h.app.viewport.layout.is_some(), "{side}: a layout for the next frame");
+ }
+}
diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs
index 67138952c9..4c3d3a70c2 100644
--- a/crates/ui-egui/src/viewport.rs
+++ b/crates/ui-egui/src/viewport.rs
@@ -6326,7 +6326,7 @@ pub(crate) fn refresh_layout(app: &mut SolveApp, ctx: &egui::Context) {
// Focus releases dock reservations while keeping controls below the stage bar.
content = rect;
for card in &app.shell.cards {
- content.min.y = (card.bottom() + Tokens::get().space_8).clamp(content.top(), content.bottom());
+ content.min.y = crate::shell::within(card.bottom() + Tokens::get().space_8, content.top(), content.bottom());
}
}
// The full-height Assistant reserves control space, while rendering and picking
@@ -6339,9 +6339,9 @@ pub(crate) fn refresh_layout(app: &mut SolveApp, ctx: &egui::Context) {
&& let Some(chat) = app.agent_chat.panel_rect.filter(|r| r.is_finite() && r.is_positive())
{
if app.preferences.agent_chat_side == "left" {
- content.min.x = (chat.right() + crate::shell::SHELL_GAP).clamp(content.left(), content.right());
+ content.min.x = crate::shell::within(chat.right() + crate::shell::SHELL_GAP, content.left(), content.right());
} else {
- content.max.x = (chat.left() - crate::shell::SHELL_GAP).clamp(content.left(), content.right());
+ content.max.x = crate::shell::within(chat.left() - crate::shell::SHELL_GAP, content.left(), content.right());
}
}
// OK and Cancel in the view's corner (#6709) take the top right; the axis view goes below.