@@ -46,7 +46,33 @@ impl Constraint {
46
46
hp : egui:: Pos2 ,
47
47
vp : & crate :: Viewport ,
48
48
) -> Option < f32 > {
49
- None
49
+ use Constraint :: { Fixed , LineLength } ;
50
+ match self {
51
+ Fixed ( ..) => None ,
52
+ LineLength ( _, fk, _, ( ref_x, ref_y) ) => {
53
+ if let Some ( Feature :: LineSegment ( _, f1, f2) ) = drawing. features . get ( * fk) {
54
+ let ( a, b) = match (
55
+ drawing. features . get ( * f1) . unwrap ( ) ,
56
+ drawing. features . get ( * f2) . unwrap ( ) ,
57
+ ) {
58
+ ( Feature :: Point ( _, x1, y1) , Feature :: Point ( _, x2, y2) ) => {
59
+ ( egui:: Pos2 { x : * x1, y : * y1 } , egui:: Pos2 { x : * x2, y : * y2 } )
60
+ }
61
+ _ => panic ! ( "unexpected subkey types: {:?} & {:?}" , f1, f2) ,
62
+ } ;
63
+
64
+ let reference = egui:: Vec2 :: new ( * ref_x, * ref_y) ;
65
+ let t = ( a - b) . angle ( ) + reference. angle ( ) ;
66
+ let text_center = vp. translate_point ( a. lerp ( b, 0.5 ) )
67
+ + egui:: Vec2 :: angled ( t) * reference. length ( ) ;
68
+
69
+ let bounds = egui:: Rect :: from_center_size ( text_center, ( 60. , 15. ) . into ( ) ) ;
70
+ Some ( bounds. distance_sq_to_pos ( hp) )
71
+ } else {
72
+ None
73
+ }
74
+ }
75
+ }
50
76
}
51
77
52
78
pub fn paint (
@@ -60,12 +86,6 @@ impl Constraint {
60
86
match self {
61
87
Fixed ( _, k, _, _) => {
62
88
if let Some ( Feature :: Point ( _, x, y) ) = drawing. features . get ( * k) {
63
- let layout = painter. layout_no_wrap (
64
- "( )" . to_string ( ) ,
65
- egui:: FontId :: monospace ( 12. ) ,
66
- params. colors . text ,
67
- ) ;
68
-
69
89
let c = params. vp . translate_point ( egui:: Pos2 { x : * x, y : * y } ) ;
70
90
painter. circle_stroke (
71
91
c,
@@ -95,8 +115,10 @@ impl Constraint {
95
115
b,
96
116
val : d,
97
117
reference : egui:: Vec2 :: new ( * ref_x, * ref_y) ,
118
+ hovered : params. hovered ,
119
+ selected : params. selected ,
98
120
}
99
- . draw ( painter, & params. vp ) ;
121
+ . draw ( painter, params) ;
100
122
}
101
123
}
102
124
}
@@ -109,26 +131,37 @@ struct DimensionLengthOverlay<'a> {
109
131
a : egui:: Pos2 ,
110
132
b : egui:: Pos2 ,
111
133
reference : egui:: Vec2 ,
134
+ hovered : bool ,
135
+ selected : bool ,
112
136
}
113
137
114
138
impl < ' a > DimensionLengthOverlay < ' a > {
115
139
const LINE_STOP_OFFSET : f32 = 5.5 ;
116
140
117
- pub fn draw ( & self , painter : & egui:: Painter , vp : & crate :: Viewport ) {
141
+ pub fn draw ( & self , painter : & egui:: Painter , params : & crate :: PaintParams ) {
142
+ let vp = & params. vp ;
118
143
let t = ( self . a - self . b ) . angle ( ) + self . reference . angle ( ) ;
119
144
let ( sa, sb) = ( vp. translate_point ( self . a ) , vp. translate_point ( self . b ) ) ;
120
145
121
- self . draw_stop_lines ( t, sa, sb, painter, vp) ;
146
+ self . draw_stop_lines ( t, sa, sb, painter) ;
147
+
148
+ let color = if self . selected {
149
+ params. colors . selected
150
+ } else if self . hovered {
151
+ params. colors . hover
152
+ } else {
153
+ egui:: Color32 :: LIGHT_BLUE
154
+ } ;
122
155
123
156
let layout = painter. layout_no_wrap (
124
157
format ! ( "{:.3}" , self . val) . into ( ) ,
125
158
egui:: FontId :: monospace ( 10. ) ,
126
- egui :: Color32 :: LIGHT_BLUE ,
159
+ color ,
127
160
) ;
128
161
let text_pos = vp. translate_point ( self . a . lerp ( self . b , 0.5 ) )
129
162
+ egui:: Vec2 :: angled ( t) * self . reference . length ( ) ;
130
163
131
- self . draw_parallel_arrows ( t, sa, sb, text_pos, & layout. rect , painter , vp ) ;
164
+ self . draw_parallel_arrows ( t, sa, sb, text_pos, & layout. rect , color , painter ) ;
132
165
painter. galley (
133
166
text_pos
134
167
- egui:: Vec2 {
@@ -146,8 +179,8 @@ impl<'a> DimensionLengthOverlay<'a> {
146
179
sb : egui:: Pos2 ,
147
180
text_pos : egui:: Pos2 ,
148
181
text_bounds : & egui:: Rect ,
182
+ color : egui:: Color32 ,
149
183
painter : & egui:: Painter ,
150
- vp : & crate :: Viewport ,
151
184
) {
152
185
let v = egui:: Vec2 :: angled ( t) * self . reference . length ( ) ;
153
186
let text_offset = text_pos. to_vec2 ( )
@@ -163,14 +196,11 @@ impl<'a> DimensionLengthOverlay<'a> {
163
196
if let Some ( end) = arrow_line_1
164
197
. intersection_rect ( & text_bounds. expand2 ( ( 12. , 2. ) . into ( ) ) . translate ( text_offset) )
165
198
{
166
- if sa. distance_sq ( end) > 1890 . {
199
+ if sa. distance_sq ( end) > 1950 . {
167
200
painter. arrow (
168
201
end,
169
202
egui:: Vec2 :: angled ( ( sa - sb) . angle ( ) ) * 20. ,
170
- egui:: Stroke {
171
- width : 1. ,
172
- color : egui:: Color32 :: LIGHT_BLUE ,
173
- } ,
203
+ egui:: Stroke { width : 1. , color } ,
174
204
) ;
175
205
}
176
206
}
@@ -182,27 +212,17 @@ impl<'a> DimensionLengthOverlay<'a> {
182
212
if let Some ( end) = arrow_line_2
183
213
. intersection_rect ( & text_bounds. expand2 ( ( 12. , 2. ) . into ( ) ) . translate ( text_offset) )
184
214
{
185
- if sb. distance_sq ( end) > 1890 . {
215
+ if sb. distance_sq ( end) > 1950 . {
186
216
painter. arrow (
187
217
end,
188
218
egui:: Vec2 :: angled ( ( sb - sa) . angle ( ) ) * 20. ,
189
- egui:: Stroke {
190
- width : 1. ,
191
- color : egui:: Color32 :: LIGHT_BLUE ,
192
- } ,
219
+ egui:: Stroke { width : 1. , color } ,
193
220
) ;
194
221
}
195
222
}
196
223
}
197
224
198
- fn draw_stop_lines (
199
- & self ,
200
- t : f32 ,
201
- sa : egui:: Pos2 ,
202
- sb : egui:: Pos2 ,
203
- painter : & egui:: Painter ,
204
- vp : & crate :: Viewport ,
205
- ) {
225
+ fn draw_stop_lines ( & self , t : f32 , sa : egui:: Pos2 , sb : egui:: Pos2 , painter : & egui:: Painter ) {
206
226
let l = self . reference . length ( ) ;
207
227
208
228
painter. line_segment (
0 commit comments