1- use crate :: { graph:: DijkstraGraph , Mode , VERSION } ;
1+ use crate :: { graph:: DijkstraGraph , Mode , VERSION , AUTHORS , UI_SPACE } ;
2+
23use egui_macroquad:: {
3- egui:: { epaint:: Shadow , Align2 , Rounding , Slider , Vec2 , Visuals , Window , Response , Ui , Sense , WidgetInfo , WidgetType , lerp , pos2 , vec2 , Widget } ,
4+ egui:: { epaint:: Shadow , Align2 , Rounding , Slider , Vec2 , Visuals , Window , Color32 , Stroke } ,
45 ui,
56} ;
6- use macroquad :: time :: get_fps ;
7+
78
89// TODO: edit colour with hex values
910// TODO: make colours editable
@@ -22,7 +23,6 @@ pub(crate) fn paint_ui(
2223)
2324{
2425 ui ( |egui_context| {
25- // Disabling all shadows
2626 egui_context. set_visuals ( Visuals
2727 {
2828 window_shadow : Shadow :: NONE ,
@@ -33,19 +33,30 @@ pub(crate) fn paint_ui(
3333 sw : 10. ,
3434 se : 0. ,
3535 } ,
36+ window_fill : Color32 :: from_rgb ( 32 , 0 , 64 ) ,
37+ window_stroke : Stroke :: new ( 2. , Color32 :: from_rgb ( 0 , 192 , 192 ) ) ,
38+ override_text_color : Some ( Color32 :: from_rgb ( 216 , 167 , 215 ) ) ,
39+ // widgets: Widgets::style(&self, response),
3640 ..Default :: default ( )
3741 } ) ;
3842
3943 // egui ❤ macroquad
4044 Window :: new ( "Rust Graph Visualiser" )
41- . anchor ( Align2 :: RIGHT_TOP , Vec2 :: new ( 0. , 10. ) )
45+ . anchor ( Align2 :: RIGHT_TOP , Vec2 :: new ( - 1.5 , 10. ) )
4246 . constrain ( true )
4347 . collapsible ( false )
4448 . movable ( false )
4549 . resizable ( false )
4650 . fixed_size ( Vec2 :: new ( 200. , 0. ) )
4751 . show ( egui_context, |ui|
4852 {
53+ ui. style_mut ( ) . visuals . widgets . inactive . weak_bg_fill = Color32 :: from_rgb ( 0 , 64 , 64 ) ;
54+ ui. style_mut ( ) . visuals . widgets . inactive . bg_fill = Color32 :: from_rgb ( 0 , 64 , 64 ) ;
55+ ui. style_mut ( ) . visuals . widgets . hovered . weak_bg_fill = Color32 :: from_rgb ( 0 , 128 , 128 ) ;
56+ ui. style_mut ( ) . visuals . widgets . hovered . bg_fill = Color32 :: from_rgb ( 0 , 128 , 128 ) ;
57+ ui. style_mut ( ) . visuals . widgets . active . weak_bg_fill = Color32 :: from_rgb ( 0 , 192 , 192 ) ;
58+ ui. style_mut ( ) . visuals . widgets . active . bg_fill = Color32 :: from_rgb ( 0 , 192 , 192 ) ;
59+
4960 ui. label ( "Select a mode:" ) ;
5061 ui. horizontal ( |ui|
5162 {
@@ -78,10 +89,15 @@ pub(crate) fn paint_ui(
7889 Mode :: Path =>
7990 {
8091 ui. separator ( ) ;
81- ui. add_enabled_ui ( graph . start ( ) . is_some ( ) && graph . end ( ) . is_some ( ) , |ui|
92+ ui. horizontal ( |ui|
8293 {
83- if ui. button ( "Find shortest path" ) . clicked ( )
84- { graph. find_shortest_path ( ) ; }
94+ ui. add_enabled_ui ( graph. start ( ) . is_some ( ) && graph. end ( ) . is_some ( ) , |ui|
95+ {
96+ if ui. button ( "Find shortest path" ) . clicked ( )
97+ { graph. find_shortest_path ( ) ; }
98+ } ) ;
99+ if ui. button ( "Clear path" ) . clicked ( )
100+ { graph. clear_path ( ) ; }
85101 } ) ;
86102 /*
87103 ui.horizontal(|ui|
@@ -98,11 +114,11 @@ pub(crate) fn paint_ui(
98114
99115 ui. add_space ( match ( & mode, selected_point_id)
100116 {
101- ( Mode :: Move , _) => 215. ,
102- ( Mode :: Line , None ) => 182 .,
103- ( Mode :: Line , Some ( _) ) => 140 .,
104- ( Mode :: Point , _) => 201 .,
105- ( Mode :: Path , _) => 136 .
117+ ( Mode :: Move , _) => UI_SPACE ,
118+ ( Mode :: Line , None ) => UI_SPACE - 33 .,
119+ ( Mode :: Line , Some ( _) ) => UI_SPACE - 75 .,
120+ ( Mode :: Point , _) => UI_SPACE - 14 .,
121+ ( Mode :: Path , _) => UI_SPACE - 58 .
106122 } ) ;
107123
108124 ui. separator ( ) ;
@@ -126,6 +142,7 @@ pub(crate) fn paint_ui(
126142
127143 ui. horizontal ( |ui|
128144 {
145+ // TODO: print angle as plain text
129146 ui. label ( "Angle:" ) ;
130147 ui. add_enabled_ui ( false , |ui|
131148 { ui. drag_angle ( angle) ; } ) ;
@@ -169,11 +186,7 @@ pub(crate) fn paint_ui(
169186
170187 ui. separator ( ) ;
171188
172- ui. horizontal ( |ui|
173- {
174- ui. label ( "Hexagons:" ) ;
175- ui. add ( toggle ( hexagons) ) ;
176- } ) ;
189+ ui. checkbox ( hexagons, "Hexagons" ) ;
177190
178191 /*
179192 ui.separator();
@@ -199,48 +212,14 @@ pub(crate) fn paint_ui(
199212
200213 ui. separator ( ) ;
201214
215+ // --- CREDITS (!important) ---
202216 ui. horizontal ( |ui|
203217 {
204218 ui. label ( format ! ( "v{}" , VERSION . unwrap_or( "unknown" ) ) ) ;
205219 ui. separator ( ) ;
206- ui. label ( format ! ( "FPS:{}" , get_fps( ) ) ) ;
220+ ui. label ( "Made by" ) ;
221+ ui. hyperlink_to ( format ! ( "{}" , AUTHORS . unwrap_or( "unknown" ) ) , "https://github.com/an-Iceberg" ) ;
207222 } ) ;
208223 } ) ;
209224 } ) ;
210225}
211-
212- fn toggle_ui ( ui : & mut Ui , on : & mut bool ) -> Response
213- {
214- let desired_size = ui. spacing ( ) . interact_size . y * vec2 ( 2.0 , 1.0 ) ;
215- let ( rect, mut response) = ui. allocate_exact_size ( desired_size, Sense :: click ( ) ) ;
216- if response. clicked ( )
217- {
218- * on = !* on;
219- response. mark_changed ( ) ;
220- }
221- response. widget_info ( || WidgetInfo :: selected ( WidgetType :: Checkbox , * on, "" ) ) ;
222-
223- if ui. is_rect_visible ( rect)
224- {
225- let how_on = ui. ctx ( ) . animate_bool ( response. id , * on) ;
226- let visuals = ui. style ( ) . interact_selectable ( & response, * on) ;
227- let rect = rect. expand ( visuals. expansion ) ;
228- let radius = 0.5 * rect. height ( ) ;
229- ui. painter ( ) . rect ( rect, radius, visuals. bg_fill , visuals. bg_stroke ) ;
230- let circle_x = lerp ( ( rect. left ( ) + radius) ..=( rect. right ( ) - radius) , how_on) ;
231- let center = pos2 ( circle_x, rect. center ( ) . y ) ;
232- ui. painter ( ) . circle ( center, 0.75 * radius, visuals. bg_fill , visuals. fg_stroke ) ;
233- }
234-
235- return response;
236- }
237-
238- // A wrapper that allows the more idiomatic usage pattern: `ui.add(toggle(&mut my_bool))`
239- /// iOS-style toggle switch.
240- ///
241- /// ## Example:
242- /// ``` ignore
243- /// ui.add(toggle(&mut my_bool));
244- /// ```
245- pub ( crate ) fn toggle ( on : & mut bool ) -> impl Widget + ' _
246- { move |ui : & mut Ui | toggle_ui ( ui, on) }
0 commit comments