From 918f6c540fff5d7650fbe3505658f416eedd54ca Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 25 Jun 2026 18:55:20 +0300 Subject: [PATCH] fix(layout): centre the camera on the sheet when first opening a layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new drawing's layouts carry paper limits but no sheet viewport; it is created lazily on the first switch into the layout. That viewport kept Viewport::new's default view (target 0,0 / height 210), so camera_from_view aimed at the paper's bottom-left corner, and with no geometry yet the fit_all fallback was a no-op — the layout opened off-centre. Give the freshly created sheet viewport a view that frames the page: view_target at the paper centre and view_height a little taller than the sheet. The first switch now opens centred on the page, and the view persists. Co-Authored-By: Claude Opus 4.8 --- src/scene/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 6673e0f26..bde913929 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -1346,6 +1346,19 @@ impl Scene { ); vp.width = pw; vp.height = ph; + // Frame the new layout on the whole sheet: look straight down at the + // paper centre with the visible height a touch taller than the page. + // Without this the viewport keeps `Viewport::new`'s default view + // (target 0,0 / height 210), so the first time a fresh drawing's + // layout is opened the camera sits on the paper's bottom-left corner + // instead of centring the sheet. + vp.view_target = acadrust::types::Vector3::new( + (min_lim.0 + max_lim.0) / 2.0, + (min_lim.1 + max_lim.1) / 2.0, + 0.0, + ); + vp.view_center = acadrust::types::Vector3::ZERO; + vp.view_height = ph * 1.1; if let Ok(handle) = self.document .add_entity_to_layout(EntityType::Viewport(vp), layout_name)