mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 00:54:06 +00:00
Shape tools: the Smart Guide label of a hover goes when the pointer leaves the canvas
With Smart Guides on, hovering a shape tool over another object's anchor or edge shows the "anchor" or "path" label where the new shape would start. When the pointer then left the canvas, went under a panel or menu, or a middle-button drag started panning, the label stayed on the canvas at the last hover point. The Rectangle, Rounded Rectangle, Ellipse, Polygon, Star and Line Segment tools now drop it when their hover ends, and so do the Arc, Spiral, Rectangular Grid and Polar Grid tools, as the Scissors tool already does.
This commit is contained in:
@@ -448,6 +448,10 @@ impl Tool for FamilyTool {
|
||||
_ => self.grid_skew_key(key).is_some(),
|
||||
}
|
||||
}
|
||||
/// The pointer left the canvas: the Smart Guide of the hover goes.
|
||||
fn hover_ended(&mut self, _cx: &ToolContext) {
|
||||
self.snap.clear();
|
||||
}
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let mut o = self.snap.guides().to_vec();
|
||||
if let Some(s) = self.start.filter(|_| self.began && cx.measurement_labels) {
|
||||
@@ -1254,6 +1258,23 @@ mod tests {
|
||||
assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "align")));
|
||||
}
|
||||
|
||||
/// The "anchor" label a hover shows goes when the pointer leaves the canvas.
|
||||
#[test]
|
||||
fn leaving_the_canvas_drops_the_hover_label() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let label = |o: &[Overlay]| o.iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "anchor"));
|
||||
for id in ["arc", "spiral", "rectangularGrid", "polarGrid"] {
|
||||
let mut t = FamilyTool::new(id);
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 98.0, 102.0));
|
||||
assert!(label(&t.overlays(&cx)), "{id}");
|
||||
t.hover_ended(&cx);
|
||||
assert!(!label(&t.overlays(&cx)), "{id}: {:?}", t.overlays(&cx));
|
||||
}
|
||||
}
|
||||
|
||||
/// A grid's Default Size and Reference Point are options for a click's dialog; the drag
|
||||
/// draws the box it is dragged to and leaves them out of its command.
|
||||
#[test]
|
||||
|
||||
@@ -973,9 +973,11 @@ impl Tool for ShapeTool {
|
||||
fn ends_on_escape(&self, _cx: &ToolContext) -> bool {
|
||||
!self.through.is_empty()
|
||||
}
|
||||
/// The pointer left the canvas: the circle's preview through it goes.
|
||||
/// The pointer left the canvas: the circle's preview through it and the Smart Guide of the
|
||||
/// hover go.
|
||||
fn hover_ended(&mut self, _cx: &ToolContext) {
|
||||
self.hover = None;
|
||||
self.snap.clear();
|
||||
}
|
||||
/// An edit, Undo or Redo made outside the tool, or another document, drops the points placed
|
||||
/// for a circle.
|
||||
|
||||
@@ -968,6 +968,23 @@ fn corners_snap_to_smart_guides() {
|
||||
assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text == &cx.segment_measure_label(from, to))));
|
||||
}
|
||||
|
||||
/// The "anchor" label a hover shows goes when the pointer leaves the canvas, for every shape tool.
|
||||
#[test]
|
||||
fn leaving_the_canvas_drops_the_hover_label() {
|
||||
let (d, _) = doc_with_rect();
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let cx = cx(&d, &s, &p);
|
||||
let label = |o: &[Overlay]| o.iter().any(|o| matches!(o, Overlay::Label { text, .. } if text == "anchor"));
|
||||
for id in ["rectangle", "roundedRectangle", "ellipse", "polygon", "star", "lineSegment"] {
|
||||
let mut t = ShapeTool::new(id);
|
||||
t.pointer(&cx, &PointerEvent::new(PointerKind::Move, 98.0, 102.0));
|
||||
assert!(label(&t.overlays(&cx)), "{id}");
|
||||
t.hover_ended(&cx);
|
||||
assert!(!label(&t.overlays(&cx)), "{id}: {:?}", t.overlays(&cx));
|
||||
}
|
||||
}
|
||||
|
||||
/// Line Segment Tool Options: Length and Angle are options (for a click's dialog), and Fill
|
||||
/// Line makes the drag's line take the current fill.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user