Skip to content

Commit 04208fc

Browse files
committed
Preview wire from pin
1 parent cde3301 commit 04208fc

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

src/app.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,14 +1297,11 @@ impl App {
12971297
}));
12981298
}
12991299
Drag::PinToWire {
1300-
source_pin: _,
1301-
wire_id,
1300+
source_pin,
1301+
start_pos: _,
13021302
} => {
1303-
// End of the new wire is hovered
1304-
return Some(Hover::Pin(Pin {
1305-
ins: wire_id,
1306-
index: 1,
1307-
}));
1303+
// Source pin is being dragged
1304+
return Some(Hover::Pin(source_pin));
13081305
}
13091306
Drag::BranchWire {
13101307
original_wire_id,

src/drag.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum Drag {
3636
},
3737
PinToWire {
3838
source_pin: Pin,
39-
wire_id: InstanceId,
39+
start_pos: Pos2,
4040
},
4141
BranchWire {
4242
original_wire_id: InstanceId,
@@ -86,12 +86,10 @@ impl App {
8686
return;
8787
}
8888
let pin_pos = self.db.pin_position(pin);
89-
let wire_id = self.db.new_wire(Wire::new(pin_pos, mouse));
9089
self.drag = Some(Drag::PinToWire {
9190
source_pin: pin,
92-
wire_id,
91+
start_pos: pin_pos,
9392
});
94-
self.current_dirty = true;
9593
}
9694
Hover::Instance(instance) => match self.db.ty(instance) {
9795
InstanceKind::Gate(_) => {
@@ -250,16 +248,30 @@ impl App {
250248
}
251249
Some(Drag::PinToWire {
252250
source_pin: _,
253-
wire_id,
251+
start_pos,
254252
}) => {
255-
let wire = self.db.get_wire_mut(wire_id);
256-
if wire.end != mouse {
257-
wire.end = mouse;
258-
self.drag_had_movement = true;
259-
}
253+
let drag_distance = (mouse - start_pos).length();
254+
255+
if drag_distance >= MIN_WIRE_SIZE {
256+
let wire = Wire::new(start_pos, mouse);
257+
let wire_id = self.db.new_wire(wire);
258+
259+
self.drag = Some(Drag::Resize {
260+
id: wire_id,
261+
start: false,
262+
});
260263

261-
if wire.end != mouse {
264+
self.drag_had_movement = true;
262265
self.connection_manager.mark_instance_dirty(wire_id);
266+
self.current_dirty = true;
267+
} else if drag_distance > 2.0 {
268+
ui.painter().line_segment(
269+
[
270+
start_pos - self.viewport_offset,
271+
mouse - self.viewport_offset,
272+
],
273+
Stroke::new(2.0, COLOR_HOVER_PIN_TO_WIRE),
274+
);
263275
}
264276
}
265277
Some(Drag::BranchWire {
@@ -375,10 +387,10 @@ impl App {
375387
}
376388
Drag::PinToWire {
377389
source_pin: _,
378-
wire_id,
390+
start_pos: _,
379391
} => {
380-
self.connection_manager.mark_instance_dirty(wire_id);
381-
self.connection_manager.rebuild_spatial_index(&self.db);
392+
// Wire was never created if drag distance was too short
393+
// Nothing to clean up
382394
}
383395
Drag::BranchWire {
384396
original_wire_id,

0 commit comments

Comments
 (0)