From 9eae2cef5f894a9489d6d8c1aaf3480559de8f48 Mon Sep 17 00:00:00 2001 From: seabeeberry Date: Fri, 1 Aug 2025 20:46:59 +0200 Subject: [PATCH 1/2] Show selection measurement overlay in document space, not viewport space --- .../tool/tool_messages/select_tool.rs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index 31bd2c3a4b..db024e5f49 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -689,8 +689,8 @@ impl Fsm for SelectToolFsmState { // Measure with Alt held down // TODO: Don't use `Key::Alt` directly, instead take it as a variable from the input mappings list like in all other places if overlay_context.visibility_settings.quick_measurement() && !matches!(self, Self::ResizingBounds { .. }) && input.keyboard.get(Key::Alt as usize) { - // Get all selected layers and compute their viewport-aligned AABB - let selected_bounds_viewport = document + // Get all selected layers and compute their document-aligned AABB + let selected_bounds_document = document .network_interface .selected_nodes() .selected_visible_and_unlocked_layers(&document.network_interface) @@ -698,23 +698,24 @@ impl Fsm for SelectToolFsmState { .filter_map(|layer| { // Get the layer's bounding box in its local space let local_bounds = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY)?; - // Transform the bounds directly to viewport space - let viewport_quad = document.metadata().transform_to_viewport(layer) * Quad::from_box(local_bounds); - // Convert the quad to an AABB in viewport space - Some(Rect::from_box(viewport_quad.bounding_box())) + // Transform the bounds directly to document space + let document_quad = document.metadata().transform_to_document(layer) * Quad::from_box(local_bounds); + // Convert the quad to an AABB in document space + Some(Rect::from_box(document_quad.bounding_box())) }) .reduce(Rect::combine_bounds); - // Get the hovered layer's viewport-aligned AABB - let hovered_bounds_viewport = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).map(|bounds| { - let viewport_quad = document.metadata().transform_to_viewport(layer) * Quad::from_box(bounds); - Rect::from_box(viewport_quad.bounding_box()) + // Get the hovered layer's document-aligned AABB + let hovered_bounds_document = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).map(|bounds| { + let document_quad = document.metadata().transform_to_document(layer) * Quad::from_box(bounds); + Rect::from_box(document_quad.bounding_box()) }); - // Use the viewport-aligned AABBs for measurement - if let (Some(selected_bounds), Some(hovered_bounds)) = (selected_bounds_viewport, hovered_bounds_viewport) { - // Since we're already in viewport space, use identity transform - measure::overlay(selected_bounds, hovered_bounds, DAffine2::IDENTITY, DAffine2::IDENTITY, &mut overlay_context); + // Use the document-aligned AABBs for measurement + if let (Some(selected_bounds), Some(hovered_bounds)) = (selected_bounds_document, hovered_bounds_document) { + // Pass document-to-viewport transform so overlay draws in correct screen position + let document_to_viewport = document.metadata().document_to_viewport; + measure::overlay(selected_bounds, hovered_bounds, document_to_viewport, document_to_viewport, &mut overlay_context); } } } From a72eb114f7158e98d803b1f4feeb2a244430d125 Mon Sep 17 00:00:00 2001 From: seabeeberry Date: Fri, 1 Aug 2025 21:56:28 +0200 Subject: [PATCH 2/2] Revert "Show selection measurement overlay in document space, not viewport space" This introduced a new bug, so a different implementation is needed. --- .../tool/tool_messages/select_tool.rs | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/editor/src/messages/tool/tool_messages/select_tool.rs b/editor/src/messages/tool/tool_messages/select_tool.rs index db024e5f49..31bd2c3a4b 100644 --- a/editor/src/messages/tool/tool_messages/select_tool.rs +++ b/editor/src/messages/tool/tool_messages/select_tool.rs @@ -689,8 +689,8 @@ impl Fsm for SelectToolFsmState { // Measure with Alt held down // TODO: Don't use `Key::Alt` directly, instead take it as a variable from the input mappings list like in all other places if overlay_context.visibility_settings.quick_measurement() && !matches!(self, Self::ResizingBounds { .. }) && input.keyboard.get(Key::Alt as usize) { - // Get all selected layers and compute their document-aligned AABB - let selected_bounds_document = document + // Get all selected layers and compute their viewport-aligned AABB + let selected_bounds_viewport = document .network_interface .selected_nodes() .selected_visible_and_unlocked_layers(&document.network_interface) @@ -698,24 +698,23 @@ impl Fsm for SelectToolFsmState { .filter_map(|layer| { // Get the layer's bounding box in its local space let local_bounds = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY)?; - // Transform the bounds directly to document space - let document_quad = document.metadata().transform_to_document(layer) * Quad::from_box(local_bounds); - // Convert the quad to an AABB in document space - Some(Rect::from_box(document_quad.bounding_box())) + // Transform the bounds directly to viewport space + let viewport_quad = document.metadata().transform_to_viewport(layer) * Quad::from_box(local_bounds); + // Convert the quad to an AABB in viewport space + Some(Rect::from_box(viewport_quad.bounding_box())) }) .reduce(Rect::combine_bounds); - // Get the hovered layer's document-aligned AABB - let hovered_bounds_document = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).map(|bounds| { - let document_quad = document.metadata().transform_to_document(layer) * Quad::from_box(bounds); - Rect::from_box(document_quad.bounding_box()) + // Get the hovered layer's viewport-aligned AABB + let hovered_bounds_viewport = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).map(|bounds| { + let viewport_quad = document.metadata().transform_to_viewport(layer) * Quad::from_box(bounds); + Rect::from_box(viewport_quad.bounding_box()) }); - // Use the document-aligned AABBs for measurement - if let (Some(selected_bounds), Some(hovered_bounds)) = (selected_bounds_document, hovered_bounds_document) { - // Pass document-to-viewport transform so overlay draws in correct screen position - let document_to_viewport = document.metadata().document_to_viewport; - measure::overlay(selected_bounds, hovered_bounds, document_to_viewport, document_to_viewport, &mut overlay_context); + // Use the viewport-aligned AABBs for measurement + if let (Some(selected_bounds), Some(hovered_bounds)) = (selected_bounds_viewport, hovered_bounds_viewport) { + // Since we're already in viewport space, use identity transform + measure::overlay(selected_bounds, hovered_bounds, DAffine2::IDENTITY, DAffine2::IDENTITY, &mut overlay_context); } } }