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 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-04-24 12:02:33 +03:00
commit 6b4bc1b832
3 changed files with 4 additions and 36 deletions

View file

@ -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

View file

@ -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

View file

@ -68,9 +68,10 @@ impl<'a> canvas::Program<Message> 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;