From eb43f0b0a595224b4ff2f61111dfbba196eac486 Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Thu, 12 May 2022 19:31:35 +0100 Subject: [PATCH] Restore the zoom to fit behaviour in new bounded documents (#641) * Restore the zoom to fit behaviour * cargo fmt Co-authored-by: Keavon Chambers --- editor/src/document/document_message_handler.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/editor/src/document/document_message_handler.rs b/editor/src/document/document_message_handler.rs index c359b88f5..0d21bfb24 100644 --- a/editor/src/document/document_message_handler.rs +++ b/editor/src/document/document_message_handler.rs @@ -460,10 +460,20 @@ impl DocumentMessageHandler { Ok(insert_index - layer_ids_above.iter().filter(|layer_id| layers.iter().any(|x| *x == [path, &[**layer_id]].concat())).count() as isize) } - pub fn document_bounds(&self) -> Option<[DVec2; 2]> { + /// Calculates the bounding box of all layers in the document + pub fn all_layer_bounds(&self) -> Option<[DVec2; 2]> { self.graphene_document.viewport_bounding_box(&[]).ok().flatten() } + /// Calculates the document bounds used for scrolling and centring (the layer bounds or the artboard (if applicable)) + pub fn document_bounds(&self) -> Option<[DVec2; 2]> { + if self.artboard_message_handler.is_infinite_canvas() { + self.all_layer_bounds() + } else { + self.artboard_message_handler.artboards_graphene_document.viewport_bounding_box(&[]).ok().flatten() + } + } + /// Calculate the path that new layers should be inserted to. /// Depends on the selected layers as well as their types (Folder/Non-Folder) pub fn get_path_for_new_layer(&self) -> Vec { @@ -868,7 +878,7 @@ impl MessageHandler for Docum // Calculates the bounding box of the region to be exported let bbox = match bounds { - crate::frontend::utility_types::ExportBounds::AllArtwork => self.document_bounds(), + crate::frontend::utility_types::ExportBounds::AllArtwork => self.all_layer_bounds(), crate::frontend::utility_types::ExportBounds::Artboard(id) => self .artboard_message_handler .artboards_graphene_document