mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-14 15:28:28 +00:00
Do not snap incompatible ports
This takes care of the second half of #54, where ports snapped to incompatible colors even when the connection was not possible.
This commit is contained in:
parent
3eef3acb34
commit
c0ba6fe227
@ -178,7 +178,16 @@ where
|
|||||||
let start_pos = port_locations[locator];
|
let start_pos = port_locations[locator];
|
||||||
|
|
||||||
// Find a port to connect to
|
// Find a port to connect to
|
||||||
fn snap_to_ports<Key: slotmap::Key + Into<AnyParameterId>, Value>(
|
fn snap_to_ports<
|
||||||
|
NodeData,
|
||||||
|
UserState,
|
||||||
|
DataType: DataTypeTrait<UserState>,
|
||||||
|
ValueType,
|
||||||
|
Key: slotmap::Key + Into<AnyParameterId>,
|
||||||
|
Value,
|
||||||
|
>(
|
||||||
|
graph: &Graph<NodeData, DataType, ValueType>,
|
||||||
|
port_type: &DataType,
|
||||||
ports: &SlotMap<Key, Value>,
|
ports: &SlotMap<Key, Value>,
|
||||||
port_locations: &PortLocations,
|
port_locations: &PortLocations,
|
||||||
cursor_pos: Pos2,
|
cursor_pos: Pos2,
|
||||||
@ -186,23 +195,45 @@ where
|
|||||||
ports
|
ports
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|(port_id, _)| {
|
.find_map(|(port_id, _)| {
|
||||||
port_locations.get(&port_id.into()).and_then(|port_pos| {
|
let compatible_ports = graph
|
||||||
if port_pos.distance(cursor_pos) < DISTANCE_TO_CONNECT {
|
.any_param_type(port_id.into())
|
||||||
Some(*port_pos)
|
.map(|other| other == port_type)
|
||||||
} else {
|
.unwrap_or(false);
|
||||||
None
|
|
||||||
}
|
if compatible_ports {
|
||||||
})
|
port_locations.get(&port_id.into()).and_then(|port_pos| {
|
||||||
|
if port_pos.distance(cursor_pos) < DISTANCE_TO_CONNECT {
|
||||||
|
Some(*port_pos)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(cursor_pos)
|
.unwrap_or(cursor_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
let (src_pos, dst_pos) = match locator {
|
let (src_pos, dst_pos) = match locator {
|
||||||
AnyParameterId::Output(_) => (
|
AnyParameterId::Output(_) => (
|
||||||
start_pos,
|
start_pos,
|
||||||
snap_to_ports(&self.graph.inputs, &port_locations, cursor_pos),
|
snap_to_ports(
|
||||||
|
&self.graph,
|
||||||
|
port_type,
|
||||||
|
&self.graph.inputs,
|
||||||
|
&port_locations,
|
||||||
|
cursor_pos,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
AnyParameterId::Input(_) => (
|
AnyParameterId::Input(_) => (
|
||||||
snap_to_ports(&self.graph.outputs, &port_locations, cursor_pos),
|
snap_to_ports(
|
||||||
|
&self.graph,
|
||||||
|
port_type,
|
||||||
|
&self.graph.outputs,
|
||||||
|
&port_locations,
|
||||||
|
cursor_pos,
|
||||||
|
),
|
||||||
start_pos,
|
start_pos,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user