Skip to content

Commit e039b46

Browse files
authored
Fix hover outline when panning (#673)
1 parent 9a0afa3 commit e039b46

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

editor/src/viewport_tools/tools/select_tool.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ impl Fsm for SelectToolFsmState {
337337
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
338338

339339
tool_data.path_outlines.update_selected(document.selected_visible_layers(), document, responses, font_cache);
340+
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
340341

341342
self
342343
}
@@ -552,21 +553,7 @@ impl Fsm for SelectToolFsmState {
552553

553554
// Generate the select outline (but not if the user is going to use the bound overlays)
554555
if cursor == MouseCursorIcon::Default {
555-
// Get the layer the user is hovering over
556-
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
557-
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
558-
let mut intersection = document.graphene_document.intersects_quad_root(quad, font_cache);
559-
560-
// If the user is hovering over a layer they have not already selected, then update outline
561-
if let Some(path) = intersection.pop() {
562-
if !document.selected_visible_layers().any(|visible| visible == path.as_slice()) {
563-
tool_data.path_outlines.update_hovered(path, document, responses, font_cache)
564-
} else {
565-
tool_data.path_outlines.clear_hovered(responses);
566-
}
567-
} else {
568-
tool_data.path_outlines.clear_hovered(responses);
569-
}
556+
tool_data.path_outlines.intersect_test_hovered(input, document, responses, font_cache);
570557
} else {
571558
tool_data.path_outlines.clear_hovered(responses);
572559
}

editor/src/viewport_tools/tools/shared/path_outline.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use crate::consts::{COLOR_ACCENT, PATH_OUTLINE_WEIGHT};
1+
use crate::consts::{COLOR_ACCENT, PATH_OUTLINE_WEIGHT, SELECTION_TOLERANCE};
22
use crate::document::DocumentMessageHandler;
3+
use crate::input::InputPreprocessorMessageHandler;
34
use crate::message_prelude::*;
45

6+
use graphene::intersection::Quad;
57
use graphene::layers::layer_info::LayerDataType;
68
use graphene::layers::style::{self, Fill, Stroke};
79
use graphene::layers::text_layer::FontCache;
810
use graphene::{LayerId, Operation};
911

10-
use glam::DAffine2;
12+
use glam::{DAffine2, DVec2};
1113
use kurbo::{BezPath, Shape};
1214
use std::collections::VecDeque;
1315

@@ -84,16 +86,29 @@ impl PathOutline {
8486
self.hovered_layer_path = None;
8587
}
8688

87-
/// Updates the overlay, generating a new one if necessary
88-
pub fn update_hovered(&mut self, new_layer_path: Vec<LayerId>, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) {
89-
// Check if we are hovering over a different layer than before
90-
if self.hovered_layer_path.as_ref().map_or(true, |old| &new_layer_path != old) {
91-
self.hovered_overlay_path = Self::create_outline(new_layer_path.clone(), self.hovered_overlay_path.take(), document, responses, font_cache);
92-
if self.hovered_overlay_path.is_none() {
89+
/// Performs an intersect test and generates a hovered overlay if necessary
90+
pub fn intersect_test_hovered(&mut self, input: &InputPreprocessorMessageHandler, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>, font_cache: &FontCache) {
91+
// Get the layer the user is hovering over
92+
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
93+
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
94+
let mut intersection = document.graphene_document.intersects_quad_root(quad, font_cache);
95+
96+
// If the user is hovering over a layer they have not already selected, then update outline
97+
if let Some(path) = intersection.pop() {
98+
if !document.selected_visible_layers().any(|visible| visible == path.as_slice()) {
99+
// Updates the overlay, generating a new one if necessary
100+
self.hovered_overlay_path = Self::create_outline(path.clone(), self.hovered_overlay_path.take(), document, responses, font_cache);
101+
if self.hovered_overlay_path.is_none() {
102+
self.clear_hovered(responses);
103+
}
104+
105+
self.hovered_layer_path = Some(path);
106+
} else {
93107
self.clear_hovered(responses);
94108
}
109+
} else {
110+
self.clear_hovered(responses);
95111
}
96-
self.hovered_layer_path = Some(new_layer_path);
97112
}
98113

99114
/// Clears overlays for the seleted paths and removes references

0 commit comments

Comments
 (0)