From 6b4bc1b832ab7603c5ed05f5779819e020059ce2 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Fri, 24 Apr 2026 12:02:33 +0300 Subject: [PATCH] fix: paper background no longer resizes when a viewport is added White paper fill was calculated from entity bounding boxes (paper_entity_extents), so adding a viewport caused the paper to visually shrink to the viewport's bounds. Now paper_limits() (layout min/max limits) is used directly, and the unused paper_entity_extents() function is removed. Co-Authored-By: Claude Sonnet 4.6 --- src/app/properties.rs | 1 - src/scene/mod.rs | 32 -------------------------------- src/scene/paper_canvas.rs | 7 ++++--- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/app/properties.rs b/src/app/properties.rs index 7c790071c..47fa0ed4b 100644 --- a/src/app/properties.rs +++ b/src/app/properties.rs @@ -312,7 +312,6 @@ impl H7CAD { .add_entity_to_layout(entity, &layout) { Ok(new_handle) => { - // Auto-fit the new viewport to show model-space content. self.tabs[i].scene.auto_fit_viewport(new_handle); } Err(e) => self diff --git a/src/scene/mod.rs b/src/scene/mod.rs index be31bff6b..2bffd9d1d 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -2246,38 +2246,6 @@ impl Scene { self.wires_for_block(layout_block) } - /// Bounding box (min_x, min_y), (max_x, max_y) of all DXF entities in the - /// current paper layout, in paper-space coordinates. Used by the 2-D canvas - /// to position the white paper fill so it aligns with the drawn entity borders. - /// Falls back to `paper_limits()` when the layout has no entities. - pub fn paper_entity_extents(&self) -> Option<((f32, f32), (f32, f32))> { - let layout_block = self.current_layout_block_handle(); - let wires = self.wires_for_block(layout_block); - - let mut min_x = f32::MAX; - let mut min_y = f32::MAX; - let mut max_x = f32::MIN; - let mut max_y = f32::MIN; - - for wire in &wires { - for &[x, y, _] in &wire.points { - if x.is_finite() && y.is_finite() { - min_x = min_x.min(x); - min_y = min_y.min(y); - max_x = max_x.max(x); - max_y = max_y.max(y); - } - } - } - - if min_x == f32::MAX { - // No entities — fall back to layout limits. - self.paper_limits() - .map(|((x0, y0), (x1, y1))| ((x0 as f32, y0 as f32), (x1 as f32, y1 as f32))) - } else { - Some(((min_x, min_y), (max_x, max_y))) - } - } /// Build a Camera oriented and scaled to match a paper-space Viewport entity. /// Used by `ViewportPane::Paper` to render model-space content through the diff --git a/src/scene/paper_canvas.rs b/src/scene/paper_canvas.rs index 8567d000c..7922a3f21 100644 --- a/src/scene/paper_canvas.rs +++ b/src/scene/paper_canvas.rs @@ -68,9 +68,10 @@ impl<'a> canvas::Program for PaperCanvas<'a> { const DESK: Color = Color { r: 0.22, g: 0.24, b: 0.28, a: 1.0 }; frame.fill_rectangle(Point::ORIGIN, bounds.size(), DESK); - // ── White paper area — use entity extents so the fill aligns with the - // drawn DXF entity borders (title block frame, viewport border, etc.). - if let Some(((px0, py0), (px1, py1))) = self.scene.paper_entity_extents() { + // ── White paper area — use layout paper limits (actual paper size). + if let Some(((px0, py0), (px1, py1))) = self.scene.paper_limits().map( + |((x0, y0), (x1, y1))| ((x0 as f32, y0 as f32), (x1 as f32, y1 as f32)), + ) { let tl = to_px(px0, py1); let br = to_px(px1, py0); let pw = br.x - tl.x;