Implement ruler bounds visualization for the AABB of selected layers (#4090)

* Implement ruler bounds visualization for the AABB of selected layers

* Code review fixes
This commit is contained in:
Keavon Chambers
2026-05-01 18:23:51 -07:00
committed by GitHub
parent eddd742f9b
commit 42f4c1396b
5 changed files with 127 additions and 37 deletions
@@ -246,6 +246,8 @@ pub enum FrontendMessage {
visible: bool,
tilt: f64,
flip: bool,
#[serde(rename = "selectionQuad")]
selection_quad: Option<[(f64, f64); 4]>,
},
UpdateDocumentScrollbars {
position: (f64, f64),
@@ -838,6 +838,23 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
let ruler_spacing = ruler_interval * ruler_scale;
// Compute the selection bounding box as 4 viewport-space corners preserving orientation
let selection_quad = if !self.graph_view_overlay_open {
self.network_interface
.selected_nodes()
.0
.iter()
.filter(|node| self.network_interface.is_layer(node, &[]))
.filter_map(|layer| self.metadata().bounding_box_document(LayerNodeIdentifier::new(*layer, &self.network_interface)))
.reduce(Quad::combine_bounds)
.map(|[min, max]| {
let corners = [DVec2::new(min.x, min.y), DVec2::new(max.x, min.y), DVec2::new(max.x, max.y), DVec2::new(min.x, max.y)];
corners.map(|c| document_to_viewport.transform_point2(c).into())
})
} else {
None
};
responses.add(FrontendMessage::UpdateDocumentRulers {
origin: ruler_origin.into(),
spacing: ruler_spacing,
@@ -845,6 +862,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
visible: self.rulers_visible,
tilt: if self.graph_view_overlay_open { 0. } else { current_ptz.tilt() },
flip: !self.graph_view_overlay_open && current_ptz.flip,
selection_quad,
});
}
DocumentMessage::RenderScrollbars => {