@@ -21,7 +21,7 @@ use super::{
21
21
Ui , Vec2 ,
22
22
} ;
23
23
use crate :: { widgets:: * , * } ;
24
- use epaint:: { Stroke , mutex:: RwLock } ;
24
+ use epaint:: { mutex:: RwLock , Stroke } ;
25
25
use std:: sync:: Arc ;
26
26
27
27
/// What is saved between frames.
@@ -43,7 +43,11 @@ impl BarState {
43
43
}
44
44
/// Show a menu at pointer if right-clicked response.
45
45
/// Should be called from [`Context`] on a [`Response`]
46
- pub fn bar_menu < R > ( & mut self , response : & Response , add_contents : impl FnOnce ( & mut Ui ) -> R ) -> Option < InnerResponse < R > > {
46
+ pub fn bar_menu < R > (
47
+ & mut self ,
48
+ response : & Response ,
49
+ add_contents : impl FnOnce ( & mut Ui ) -> R ,
50
+ ) -> Option < InnerResponse < R > > {
47
51
MenuRoot :: stationary_click_interaction ( response, & mut self . open_menu , response. id ) ;
48
52
self . open_menu . show ( response, add_contents)
49
53
}
@@ -137,11 +141,8 @@ pub(crate) fn menu_ui<'c, R>(
137
141
ui. set_max_width ( DEFAULT_MENU_WIDTH ) ;
138
142
ui. set_style ( style) ;
139
143
ui. set_menu_state ( Some ( menu_state_arc. clone ( ) ) ) ;
140
- ui. with_layout (
141
- Layout :: top_down_justified ( Align :: LEFT ) ,
142
- add_contents,
143
- )
144
- . inner
144
+ ui. with_layout ( Layout :: top_down_justified ( Align :: LEFT ) , add_contents)
145
+ . inner
145
146
} )
146
147
. inner
147
148
} ) ;
@@ -184,7 +185,11 @@ pub(crate) struct ContextMenuSystem {
184
185
impl ContextMenuSystem {
185
186
/// Show a menu at pointer if right-clicked response.
186
187
/// Should be called from [`Context`] on a [`Response`]
187
- pub fn context_menu ( & mut self , response : & Response , add_contents : impl FnOnce ( & mut Ui ) ) -> Option < InnerResponse < ( ) > > {
188
+ pub fn context_menu (
189
+ & mut self ,
190
+ response : & Response ,
191
+ add_contents : impl FnOnce ( & mut Ui ) ,
192
+ ) -> Option < InnerResponse < ( ) > > {
188
193
MenuRoot :: context_click_interaction ( response, & mut self . root , response. id ) ;
189
194
self . root . show ( response, add_contents)
190
195
}
@@ -209,7 +214,11 @@ pub(crate) struct MenuRootManager {
209
214
impl MenuRootManager {
210
215
/// Show a menu at pointer if right-clicked response.
211
216
/// Should be called from [`Context`] on a [`Response`]
212
- pub fn show < R > ( & mut self , response : & Response , add_contents : impl FnOnce ( & mut Ui ) -> R ) -> Option < InnerResponse < R > > {
217
+ pub fn show < R > (
218
+ & mut self ,
219
+ response : & Response ,
220
+ add_contents : impl FnOnce ( & mut Ui ) -> R ,
221
+ ) -> Option < InnerResponse < R > > {
213
222
if let Some ( root) = self . inner . as_mut ( ) {
214
223
let ( menu_response, inner_response) = root. show ( response, add_contents) ;
215
224
if let MenuResponse :: Close = menu_response {
@@ -256,7 +265,8 @@ impl MenuRoot {
256
265
add_contents : impl FnOnce ( & mut Ui ) -> R ,
257
266
) -> ( MenuResponse , Option < InnerResponse < R > > ) {
258
267
if self . id == response. id {
259
- let inner_response = MenuState :: show ( & response. ctx , & self . menu_state , self . id , add_contents) ;
268
+ let inner_response =
269
+ MenuState :: show ( & response. ctx , & self . menu_state , self . id , add_contents) ;
260
270
let mut menu_state = self . menu_state . write ( ) ;
261
271
menu_state. rect = inner_response. response . rect ;
262
272
@@ -330,10 +340,7 @@ impl MenuRoot {
330
340
}
331
341
MenuResponse :: Stay
332
342
}
333
- fn handle_menu_response (
334
- root : & mut MenuRootManager ,
335
- menu_response : MenuResponse ,
336
- ) {
343
+ fn handle_menu_response ( root : & mut MenuRootManager , menu_response : MenuResponse ) {
337
344
match menu_response {
338
345
MenuResponse :: Create ( pos, id) => {
339
346
root. inner = Some ( MenuRoot :: new ( pos, id) ) ;
@@ -394,15 +401,8 @@ impl SubMenuButton {
394
401
self . icon = icon. to_string ( ) ;
395
402
self
396
403
}
397
- pub ( crate ) fn show (
398
- self ,
399
- ui : & mut Ui ,
400
- menu_state : & MenuState ,
401
- sub_id : Id ,
402
- ) -> Response {
403
- let SubMenuButton {
404
- text, icon, ..
405
- } = self ;
404
+ pub ( crate ) fn show ( self , ui : & mut Ui , menu_state : & MenuState , sub_id : Id ) -> Response {
405
+ let SubMenuButton { text, icon, .. } = self ;
406
406
407
407
let text_style = TextStyle :: Button ;
408
408
let sense = Sense :: click ( ) ;
@@ -445,8 +445,10 @@ impl SubMenuButton {
445
445
) ;
446
446
447
447
let text_color = visuals. text_color ( ) ;
448
- ui. painter ( ) . galley_with_color ( text_pos, text_galley, text_color) ;
449
- ui. painter ( ) . galley_with_color ( icon_pos, icon_galley, text_color) ;
448
+ ui. painter ( )
449
+ . galley_with_color ( text_pos, text_galley, text_color) ;
450
+ ui. painter ( )
451
+ . galley_with_color ( icon_pos, icon_galley, text_color) ;
450
452
}
451
453
response
452
454
}
@@ -470,11 +472,7 @@ impl SubMenu {
470
472
add_contents : impl FnOnce ( & mut Ui ) -> R ,
471
473
) -> InnerResponse < Option < R > > {
472
474
let sub_id = ui. id ( ) . with ( self . button . index ) ;
473
- let button = self . button . show (
474
- ui,
475
- & * self . parent_state . read ( ) ,
476
- sub_id,
477
- ) ;
475
+ let button = self . button . show ( ui, & * self . parent_state . read ( ) , sub_id) ;
478
476
self . parent_state
479
477
. write ( )
480
478
. submenu_button_interaction ( ui, sub_id, & button) ;
@@ -579,11 +577,7 @@ impl MenuState {
579
577
}
580
578
if let Some ( sub_menu) = self . get_current_submenu ( ) {
581
579
if let Some ( pos) = pointer. hover_pos ( ) {
582
- return Self :: points_at_left_of_rect (
583
- pos,
584
- pointer. velocity ( ) ,
585
- sub_menu. read ( ) . rect ,
586
- ) ;
580
+ return Self :: points_at_left_of_rect ( pos, pointer. velocity ( ) , sub_menu. read ( ) . rect ) ;
587
581
}
588
582
}
589
583
false
0 commit comments