Path type brackets: 8 px reach, hover highlight, and the nearest of a bracket and a port takes the press

Squashed from #5332 onto main.
This commit is contained in:
ham9zah
2026-11-03 16:03:40 +07:00
committed by bflatastic
parent 2b6cbfda5d
commit 2bc284aa25
5 changed files with 197 additions and 36 deletions
+8 -2
View File
@@ -153,6 +153,8 @@ pub struct SelectionTool {
/// The text the pointer was loaded with when the button went down: a dropped press loads it
/// again.
loaded_at_press: Option<(NodeId, bool)>,
/// Where the pointer last hovered: the type on a path bracket under it draws thicker.
bracket_hover: Option<Point>,
}
/// What Distance Guides measure the selection to.
@@ -713,6 +715,7 @@ impl Tool for SelectionTool {
self.hover = None;
self.distance = None;
self.alt_hover = false;
self.bracket_hover = None;
}
fn wants_rehover(&self) -> bool {
@@ -735,6 +738,7 @@ impl Tool for SelectionTool {
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
self.note_loaded_at_press(ev.kind);
let hovering = ev.kind == PointerKind::Move && matches!(self.state, State::Idle);
self.bracket_hover = hovering.then_some(ev.pos);
self.alt_hover = hovering && ev.mods.alt;
self.distance = hovering.then(|| distance_target(cx, ev.pos, ev.mods)).flatten();
if let State::Loaded { from, before, press } = self.state
@@ -930,7 +934,9 @@ impl Tool for SelectionTool {
}
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
let mut o = pathtype::overlays(cx);
// Highlighted only where a press would take the bracket, not a nearer port.
let drag = if let State::Bracket(b) = &self.state { Some(b) } else { None };
let mut o = pathtype::overlays(cx, self.bracket_hover.filter(|p| over_bracket(cx, *p)), drag);
if let Some(source) = cx.isolation.and_then(|id| cx.doc.node(id)).filter(|n| n.name.as_deref() == Some(vectorcraft_doc::shaper::SOURCES)) {
for n in source.children().into_iter().flatten() {
if let Some(path) = n.path_data() {
@@ -1345,7 +1351,7 @@ impl SelectionTool {
fn press_widgets(&mut self, cx: &ToolContext, ev: &PointerEvent, p: Point) -> Option<Vec<Action>> {
// 0. A port of selected area type or type on a path: the pointer takes its text,
// to thread on from the out port or back from the in port.
if let Some((from, port)) = crate::text::port_at(cx, p) {
if let Some((from, port)) = crate::text::port_at(cx, p).filter(|_| !over_bracket(cx, p)) {
self.state = State::Loaded { from, before: port == crate::text::Port::In, press: None };
return Some(vec![]);
}