@@ -8,8 +8,20 @@ use super::*;
8
8
use egui:: epaint:: { CubicBezierShape , RectShape } ;
9
9
use egui:: * ;
10
10
11
+ /// Mapping from parameter id to positions of hooks it contains.
12
+ ///
13
+ /// Outputs and short inputs always only have one hook, so the value is
14
+ /// just `vec![port_position]`. Wide inputs may have multiple hooks.
11
15
pub type PortLocations = std:: collections:: HashMap < AnyParameterId , Vec < Pos2 > > ;
12
- pub type ConnLocations = std:: collections:: HashMap < ( InputId , usize ) , Pos2 > ;
16
+
17
+ /// Destination positions of connections made to a given input.
18
+ ///
19
+ /// This is not equivalent to [`PortLocations`] because connections may be moved
20
+ /// around (e.g. while an in-progress connection is hovered over a wide port),
21
+ /// while hooks within a port are strictly a function of the port.
22
+ pub type ConnLocations = std:: collections:: HashMap < InputId , Vec < Pos2 > > ;
23
+
24
+ /// Rectangle containing each node.
13
25
pub type NodeRects = std:: collections:: HashMap < NodeId , Rect > ;
14
26
15
27
const DISTANCE_TO_CONNECT : f32 = 10.0 ;
@@ -23,6 +35,9 @@ pub enum NodeResponse<UserResponse: UserResponseTrait, NodeData: NodeDataTrait>
23
35
ConnectEventEnded {
24
36
output : OutputId ,
25
37
input : InputId ,
38
+ /// Index of the connection in wide input ports.
39
+ ///
40
+ /// If the input isn't a wide port this is always 0 and may be ignored.
26
41
input_hook : usize ,
27
42
} ,
28
43
CreatedNode ( NodeId ) ,
@@ -310,7 +325,7 @@ where
310
325
let connection_color = port_type. data_type_color ( user_state) ;
311
326
// outputs can't be wide yet so this is fine.
312
327
let src_pos = port_locations[ & AnyParameterId :: Output ( output) ] [ 0 ] ;
313
- let dst_pos = conn_locations[ & ( input, hook_n) ] ;
328
+ let dst_pos = conn_locations[ & input] [ hook_n] ;
314
329
draw_connection ( ui. painter ( ) , src_pos, dst_pos, connection_color) ;
315
330
}
316
331
}
@@ -802,7 +817,7 @@ where
802
817
. iter ( )
803
818
. enumerate ( )
804
819
{
805
- conn_locations. insert ( ( input, k ) , * dst_pos) ;
820
+ conn_locations. entry ( input) . or_default ( ) . insert ( k , * dst_pos) ;
806
821
}
807
822
}
808
823
}
@@ -816,8 +831,8 @@ where
816
831
. and_then ( |( mouse_pos, input) | {
817
832
let hooks = 0 ..inner_ports;
818
833
hooks. min_by ( |& hook1, & hook2| {
819
- let out1_dist = conn_locations[ & ( input, hook1) ] . distance ( mouse_pos) ;
820
- let out2_dist = conn_locations[ & ( input, hook2) ] . distance ( mouse_pos) ;
834
+ let out1_dist = conn_locations[ & input] [ hook1] . distance ( mouse_pos) ;
835
+ let out2_dist = conn_locations[ & input] [ hook2] . distance ( mouse_pos) ;
821
836
822
837
out1_dist. partial_cmp ( & out2_dist) . unwrap ( )
823
838
} )
@@ -863,7 +878,7 @@ where
863
878
} else if wide_port && !port_full {
864
879
// move connections below the in-progress one to a lower position
865
880
for k in input_hook..graph. connections ( input) . len ( ) {
866
- conn_locations. get_mut ( & ( input, k ) ) . unwrap ( ) . y += 7.5 ;
881
+ conn_locations. get_mut ( & input) . unwrap ( ) [ k ] . y += 7.5 ;
867
882
}
868
883
}
869
884
}
0 commit comments