1
1
use std:: fmt:: Formatter ;
2
2
3
3
use eframe:: {
4
- egui:: { pos2, Align2 , CentralPanel , Color32 , FontId , TopBottomPanel } ,
5
- epaint:: PathStroke ,
4
+ egui:: { pos2, vec2 , Align2 , CentralPanel , Color32 , FontId , Shape , TopBottomPanel } ,
5
+ epaint:: { PathStroke , QuadraticBezierShape } ,
6
6
App , CreationContext ,
7
7
} ;
8
8
@@ -60,9 +60,9 @@ impl App for DependencyInspector {
60
60
self . selected_node_index = None ;
61
61
}
62
62
} ) ;
63
+
63
64
CentralPanel :: default ( ) . show ( context, |ui| {
64
65
let cycler = self . cyclers . cyclers . get ( self . selected_cycler ) . unwrap ( ) ;
65
- ui. label ( format ! ( "{} {}" , cycler. name, cycler. cycle_nodes. len( ) ) ) ;
66
66
67
67
let nodes: Vec < _ > = cycler
68
68
. setup_nodes
@@ -77,17 +77,25 @@ impl App for DependencyInspector {
77
77
if label. clicked {
78
78
self . selected_node_index = Some ( index) ;
79
79
}
80
- node_points. push ( label. rect . right_center ( ) ) ;
80
+ node_points. push ( label. rect . right_center ( ) + vec2 ( 3.0 , 0.0 ) ) ;
81
81
ui. add_space ( 5.0 ) ;
82
82
}
83
83
84
+ let minimum_x = node_points
85
+ . iter ( )
86
+ . map ( |point| point. x )
87
+ . max_by ( f32:: total_cmp)
88
+ . unwrap_or ( 0.0 )
89
+ + 5.0 ;
90
+
84
91
let Some ( selected_node_index) = self . selected_node_index else {
85
92
return ;
86
93
} ;
87
94
let selected_node = nodes[ selected_node_index] ;
88
95
89
96
let mut cross_inputs = Vec :: new ( ) ;
90
97
let painter = ui. painter ( ) ;
98
+ let mut count = 0 ;
91
99
for field in & selected_node. contexts . cycle_context {
92
100
let path = match field {
93
101
Field :: Input {
@@ -119,7 +127,7 @@ impl App for DependencyInspector {
119
127
continue ;
120
128
}
121
129
} ;
122
- for ( node_index, node) in nodes. iter ( ) . enumerate ( ) {
130
+ for ( node_index, node) in nodes. iter ( ) . enumerate ( ) . rev ( ) {
123
131
if let Some ( output) =
124
132
node. contexts
125
133
. main_outputs
@@ -133,16 +141,26 @@ impl App for DependencyInspector {
133
141
_ => None ,
134
142
} )
135
143
{
136
- let a = node_points[ selected_node_index] ;
144
+ let a = pos2 (
145
+ minimum_x + count as f32 * 10.0 ,
146
+ node_points[ selected_node_index] . y ,
147
+ ) ;
137
148
let b = node_points[ node_index] ;
138
- painter. line_segment ( [ a, b] , PathStroke :: new ( 1.0 , Color32 :: RED ) ) ;
149
+ let curve = QuadraticBezierShape :: from_points_stroke (
150
+ [ a, pos2 ( a. x , b. y ) , b] ,
151
+ false ,
152
+ Color32 :: TRANSPARENT ,
153
+ PathStroke :: new ( 1.0 , Color32 :: RED ) ,
154
+ ) ;
139
155
painter. text (
140
- ( a + b . to_vec2 ( ) ) / 2.0 ,
156
+ curve . sample ( 0.9 ) + vec2 ( 5.0 , 0.0 ) ,
141
157
Align2 :: LEFT_CENTER ,
142
158
output,
143
159
FontId :: default ( ) ,
144
160
Color32 :: LIGHT_GRAY ,
145
161
) ;
162
+ painter. add ( Shape :: QuadraticBezier ( curve) ) ;
163
+ count += 1 ;
146
164
}
147
165
}
148
166
}
@@ -178,27 +196,48 @@ impl App for DependencyInspector {
178
196
} ;
179
197
( * name == path. segments . first ( ) . unwrap ( ) . name ) . then_some ( name)
180
198
} ) {
181
- let a = node_points[ selected_node_index] ;
199
+ let a = pos2 (
200
+ minimum_x + count as f32 * 10.0 ,
201
+ node_points[ selected_node_index] . y ,
202
+ ) ;
182
203
let b = node_points[ node_index] ;
183
- painter. line_segment ( [ a, b] , PathStroke :: new ( 1.0 , Color32 :: YELLOW ) ) ;
204
+ let curve = QuadraticBezierShape :: from_points_stroke (
205
+ [ a, pos2 ( a. x , b. y ) , b] ,
206
+ false ,
207
+ Color32 :: TRANSPARENT ,
208
+ PathStroke :: new ( 1.0 , Color32 :: YELLOW ) ,
209
+ ) ;
184
210
painter. text (
185
- ( a + b . to_vec2 ( ) ) / 2.0 ,
211
+ curve . sample ( 0.9 ) + vec2 ( 5.0 , 0.0 ) ,
186
212
Align2 :: LEFT_CENTER ,
187
213
output,
188
214
FontId :: default ( ) ,
189
215
Color32 :: LIGHT_GRAY ,
190
216
) ;
217
+ painter. add ( Shape :: QuadraticBezier ( curve) ) ;
218
+ count += 1 ;
191
219
}
192
220
}
193
221
}
194
222
223
+ painter. line_segment (
224
+ [
225
+ node_points[ selected_node_index] ,
226
+ pos2 (
227
+ minimum_x + count as f32 * 10.0 - 10.0 ,
228
+ node_points[ selected_node_index] . y ,
229
+ ) ,
230
+ ] ,
231
+ PathStroke :: new ( 1.0 , Color32 :: GREEN ) ,
232
+ ) ;
233
+
195
234
for ( input_index, ( cycler_instance, input) ) in cross_inputs. iter ( ) . enumerate ( ) {
196
235
let a = node_points[ selected_node_index] ;
197
236
let b = painter
198
237
. text (
199
238
pos2 (
200
239
ui. clip_rect ( ) . right ( ) ,
201
- a. y + -( cross_inputs. len ( ) as isize / 2 - input_index as isize ) as f32
240
+ a. y + -( cross_inputs. len ( ) as f32 / 2.0 - input_index as f32 - 0.5 )
202
241
* FontId :: default ( ) . size
203
242
* 1.5 ,
204
243
) ,
0 commit comments