Skip to content

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

Sketch pane: stays still at 125 % display scaling (#9457) (#9598)

rugbymauric755e067f525
diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rs
index 9700911306..5d3df95b9a 100644
--- a/crates/ui-egui/src/agent_chat/panel.rs
+++ b/crates/ui-egui/src/agent_chat/panel.rs
@@ -211,7 +211,7 @@ fn floating(app: &mut SolveApp, ui: &mut egui::Ui) {
let frame = ui_kit::Panel::feature_frame(&ctx, app.ui.layout, side);
let inner = (vec2(width, height) - frame.total_margin().sum()).max(egui::Vec2::ZERO);
let panel = ui_kit::Panel::new(tr("ui.assistant"), Id::new("sc_agent_chat_floating"), anchor, available, side, frame).width(width);
- if let Some(card) = panel.window(&ctx).fixed_size(inner).show(&ctx, |ui| {
+ if let Some(card) = panel.fixed_window(&ctx, inner).show(&ctx, |ui| {
ui.set_min_size(inner);
ui.set_max_size(inner);
ui.set_clip_rect(ui.clip_rect().intersect(Rect::from_min_size(ui.max_rect().min, inner)));
diff --git a/crates/ui-egui/src/sketch_palette.rs b/crates/ui-egui/src/sketch_palette.rs
index 2596dee079..146d76d5eb 100644
--- a/crates/ui-egui/src/sketch_palette.rs
+++ b/crates/ui-egui/src/sketch_palette.rs
@@ -701,6 +701,33 @@ mod tests {
}
}
+ /// The pane is placed from the viewport's right edge. At a fractional display scale (Windows
+ /// at 125 %) it hopped a physical pixel back and forth on every repaint the pointer caused,
+ /// most visibly docked against the window's edge (#9457).
+ #[test]
+ fn pane_stays_still_while_the_pointer_moves_at_fractional_scale() {
+ for layout in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] {
+ for (scale, width, height) in [(1.0, 1600.0, 1000.0), (1.25, 1536.0, 921.6), (1.25, 1522.4, 904.8), (1.5, 1280.0, 800.0)] {
+ let mut h = crate::scenario::Harness::new();
+ h.app.ui.layout = layout;
+ h.call("ui.resize", json!({"width":width,"height":height}));
+ h.call("ui.prefs", json!({"ui_scale":scale}));
+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
+ h.app.run("sketch.line", json!({"points":[[0,0],[30,0],[30,20]],"closed":false})).unwrap();
+ h.app.start("sketch.line");
+ h.settle();
+ let mut seen = Vec::new();
+ for i in 0..8 {
+ h.app.synthetic.push(egui::Event::PointerMoved(egui::pos2(400.0 + i as f32 * 7.3, 400.0 + i as f32 * 3.1)));
+ h.frame();
+ let pane = h.app.viewport.palette_rect.expect("the pane is shown while sketching");
+ seen.push((pane, crate::scenario::rect_of("sketch_palette:finish")));
+ }
+ assert!(seen.windows(2).all(|w| w[0] == w[1]), "{layout:?} at scale {scale}, {width}x{height}: the pane moved: {seen:?}");
+ }
+ }
+ }
+
/// A command dialog opened while sketching used to hide the palette outright. The two now
/// share the viewport, the dialog at the left edge and the palette at the right, and a view
/// too narrow for both keeps the dialog alone.
diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs
index 0917a0abba..85870af5d1 100644
--- a/crates/ui-egui/src/ui_kit/panel.rs
+++ b/crates/ui-egui/src/ui_kit/panel.rs
@@ -671,6 +671,17 @@ impl<'a> Panel<'a> {
}
pub(crate) fn window(&self, ctx: &egui::Context) -> egui::Window<'a> {
+ self.window_placed(ctx, None)
+ }
+
+ /// The same window for contents the caller holds to `size` (egui's `fixed_size`); the card
+ /// is that plus its frame.
+ pub(crate) fn fixed_window(&self, ctx: &egui::Context, size: egui::Vec2) -> egui::Window<'a> {
+ let outer = size.x + self.positioned_frame(ctx).total_margin().sum().x;
+ self.window_placed(ctx, Some(outer)).fixed_size(size)
+ }
+
+ fn window_placed(&self, ctx: &egui::Context, outer_width: Option<f32>) -> egui::Window<'a> {
let gap = super::Container::new(ctx, super::Surface::Feature).gap();
let viewport = self.viewport;
let anchor = self.bounded_anchor(ctx);
@@ -680,17 +691,22 @@ impl<'a> Panel<'a> {
let width = self.width.min(viewport.width().max(0.0));
let inner_width = (width - margin.sum().x).max(0.0);
let height = (viewport.bottom() - anchor.y - gap).max(0.0);
+ // Place the card by its left edge, worked out from the outer width the window is held to.
+ // Pivoting on the right edge subtracts the size egui measured last frame, and at a
+ // fractional display scale rounding the left edge to a physical pixel changes the next
+ // measured width by one, so the card hopped a pixel back and forth on every repaint (#9457).
+ let left_top = match side {
+ crate::frame::Side::Right => egui::pos2(anchor.x - outer_width.unwrap_or(inner_width), anchor.y),
+ crate::frame::Side::Left => anchor,
+ };
// Keep drawing safe when even the header/footer cannot fit. egui clips the contents to
// the remaining viewport; the normal small-height case still keeps both actions visible.
super::Container::new(ctx, super::Surface::Feature)
.window(self.title)
.id(self.id)
.title_bar(false)
- .pivot(match side {
- crate::frame::Side::Right => egui::Align2::RIGHT_TOP,
- crate::frame::Side::Left => egui::Align2::LEFT_TOP,
- })
- .fixed_pos(anchor)
+ .pivot(egui::Align2::LEFT_TOP)
+ .fixed_pos(left_top)
.constrain(false)
.collapsible(false)
.resizable(false)