Restore the zoom to fit behaviour in new bounded documents (#641)

* Restore the zoom to fit behaviour

* cargo fmt

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2022-05-12 19:31:35 +01:00 committed by Keavon Chambers
parent 3673490990
commit eb43f0b0a5

View file

@ -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<u64> {
@ -868,7 +878,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> 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