This commit is contained in:
Ashish Mohapatra 2025-12-22 21:36:00 +05:30 committed by GitHub
commit c792e02abb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 4 deletions

View file

@ -1024,7 +1024,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
let viewport_size = viewport.size().into_dvec2();
let viewport_mid = viewport.center_in_viewport_space().into_dvec2();
let [bounds1, bounds2] = if !self.graph_view_overlay_open {
self.metadata().document_bounds_viewport_space().unwrap_or([viewport_mid; 2])
self.network_interface.document_bounds_viewport_space(true).unwrap_or([viewport_mid; 2])
} else {
self.network_interface.graph_bounds_viewport_space(&self.breadcrumb_network_path).unwrap_or([viewport_mid; 2])
};

View file

@ -241,7 +241,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
}
let document_bounds = if !graph_view_overlay_open {
// TODO: Cache this in node graph coordinates and apply the transform to the rectangle to get viewport coordinates
network_interface.document_metadata().document_bounds_viewport_space()
network_interface.document_bounds_viewport_space(true)
} else {
network_interface.graph_bounds_viewport_space(breadcrumb_network_path)
};
@ -259,7 +259,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
NavigationMessage::CanvasZoomSet { zoom_factor } => {
let document_bounds = if !graph_view_overlay_open {
// TODO: Cache this in node graph coordinates and apply the transform to the rectangle to get viewport coordinates
network_interface.document_metadata().document_bounds_viewport_space()
network_interface.document_bounds_viewport_space(true)
} else {
network_interface.graph_bounds_viewport_space(breadcrumb_network_path)
};
@ -456,7 +456,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for Navigat
let document_bounds = if !graph_view_overlay_open {
// TODO: Cache this in node graph coordinates and apply the transform to the rectangle to get viewport coordinates
network_interface.document_metadata().document_bounds_viewport_space()
network_interface.document_bounds_viewport_space(true)
} else {
network_interface.graph_bounds_viewport_space(breadcrumb_network_path)
};

View file

@ -1193,6 +1193,13 @@ impl NodeNetworkInterface {
.reduce(Quad::combine_bounds)
}
pub fn document_bounds_viewport_space(&self, include_artboards: bool) -> Option<[DVec2; 2]> {
let [min, max] = self.document_bounds_document_space(include_artboards)?;
let quad = Quad::from_box([min, max]);
let transformed = self.document_metadata.document_to_viewport * quad;
Some(transformed.bounding_box())
}
/// Calculates the selected layer bounds in document space
pub fn selected_bounds_document_space(&self, include_artboards: bool, network_path: &[NodeId]) -> Option<[DVec2; 2]> {
let Some(selected_nodes) = self.selected_nodes_in_nested_network(network_path) else {