Skip to content

Commit bfaae5e

Browse files
committed
Make hover stable while dragging
1 parent 7eff420 commit bfaae5e

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/app.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ impl App {
785785
self.handle_deletion(ui);
786786

787787
if let Some(mouse) = mouse_pos_world {
788+
let dragging = self.drag.is_some();
788789
let hovered_now = self.get_hovered(mouse);
789790

790791
if mouse_clicked {
@@ -793,8 +794,6 @@ impl App {
793794
self.handle_drag_start_canvas(mouse);
794795
}
795796

796-
let dragging = self.drag.is_some();
797-
798797
if dragging {
799798
self.handle_dragging(ui, mouse);
800799
} else {
@@ -1144,6 +1143,40 @@ impl App {
11441143
}
11451144

11461145
pub fn get_hovered(&self, mouse_pos: Pos2) -> Option<Hover> {
1146+
if let Some(v) = self.drag {
1147+
match v {
1148+
Drag::Canvas(canvas_drag) => match canvas_drag {
1149+
crate::drag::CanvasDrag::Single { id, offset: _ } => {
1150+
return Some(Hover::Instance(id));
1151+
}
1152+
crate::drag::CanvasDrag::Selected { .. } => {}
1153+
},
1154+
Drag::Resize { id, start } => {
1155+
return Some(Hover::Pin(Pin {
1156+
ins: id,
1157+
index: u32::from(!start),
1158+
}));
1159+
}
1160+
Drag::PinToWire {
1161+
source_pin: _,
1162+
wire_id,
1163+
} => {
1164+
// End of the new wire is hovered
1165+
return Some(Hover::Pin(Pin {
1166+
ins: wire_id,
1167+
index: 1,
1168+
}));
1169+
}
1170+
Drag::BranchWire {
1171+
original_wire_id,
1172+
split_point: _,
1173+
start_mouse_pos: _,
1174+
} => {
1175+
return Some(Hover::Instance(original_wire_id));
1176+
}
1177+
Drag::Panel { .. } | Drag::Selecting { .. } => {}
1178+
}
1179+
}
11471180
for selected in &self.selected {
11481181
match self.db.ty(*selected) {
11491182
InstanceKind::Wire => {

src/drag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum CanvasDrag {
2020
},
2121
}
2222

23-
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
23+
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, Copy)]
2424
pub enum Drag {
2525
Panel {
2626
pos: Pos2,

0 commit comments

Comments
 (0)