@@ -39,13 +39,14 @@ impl BarState {
39
39
}
40
40
41
41
/// Show a menu at pointer if primary-clicked response.
42
+ ///
42
43
/// Should be called from [`Context`] on a [`Response`]
43
44
pub fn bar_menu < R > (
44
45
& mut self ,
45
46
response : & Response ,
46
47
add_contents : impl FnOnce ( & mut Ui ) -> R ,
47
48
) -> Option < InnerResponse < R > > {
48
- MenuRoot :: stationary_click_interaction ( response, & mut self . open_menu , response . id ) ;
49
+ MenuRoot :: stationary_click_interaction ( response, & mut self . open_menu ) ;
49
50
self . open_menu . show ( response, add_contents)
50
51
}
51
52
@@ -134,7 +135,7 @@ pub(crate) fn submenu_button<R>(
134
135
/// wrapper for the contents of every menu.
135
136
pub ( crate ) fn menu_ui < ' c , R > (
136
137
ctx : & Context ,
137
- menu_id : impl Into < Id > ,
138
+ menu_id : Id ,
138
139
menu_state_arc : & Arc < RwLock < MenuState > > ,
139
140
add_contents : impl FnOnce ( & mut Ui ) -> R + ' c ,
140
141
) -> InnerResponse < R > {
@@ -144,7 +145,7 @@ pub(crate) fn menu_ui<'c, R>(
144
145
menu_state. rect . min
145
146
} ;
146
147
147
- let area = Area :: new ( menu_id)
148
+ let area = Area :: new ( menu_id. with ( "__menu" ) )
148
149
. order ( Order :: Foreground )
149
150
. fixed_pos ( pos)
150
151
. constrain_to ( ctx. screen_rect ( ) )
@@ -222,7 +223,7 @@ pub(crate) fn context_menu(
222
223
let menu_id = Id :: new ( CONTEXT_MENU_ID_STR ) ;
223
224
let mut bar_state = BarState :: load ( & response. ctx , menu_id) ;
224
225
225
- MenuRoot :: context_click_interaction ( response, & mut bar_state, response . id ) ;
226
+ MenuRoot :: context_click_interaction ( response, & mut bar_state) ;
226
227
let inner_response = bar_state. show ( response, add_contents) ;
227
228
228
229
bar_state. store ( & response. ctx , menu_id) ;
@@ -237,6 +238,7 @@ pub(crate) struct MenuRootManager {
237
238
238
239
impl MenuRootManager {
239
240
/// Show a menu at pointer if right-clicked response.
241
+ ///
240
242
/// Should be called from [`Context`] on a [`Response`]
241
243
pub fn show < R > (
242
244
& mut self ,
@@ -308,11 +310,9 @@ impl MenuRoot {
308
310
/// Interaction with a stationary menu, i.e. fixed in another Ui.
309
311
///
310
312
/// Responds to primary clicks.
311
- fn stationary_interaction (
312
- response : & Response ,
313
- root : & mut MenuRootManager ,
314
- id : Id ,
315
- ) -> MenuResponse {
313
+ fn stationary_interaction ( response : & Response , root : & mut MenuRootManager ) -> MenuResponse {
314
+ let id = response. id ;
315
+
316
316
if ( response. clicked ( ) && root. is_menu_open ( id) )
317
317
|| response. ctx . input ( |i| i. key_pressed ( Key :: Escape ) )
318
318
{
@@ -357,8 +357,8 @@ impl MenuRoot {
357
357
MenuResponse :: Stay
358
358
}
359
359
360
- /// Interaction with a context menu (secondary clicks ).
361
- fn context_interaction ( response : & Response , root : & mut Option < Self > , id : Id ) -> MenuResponse {
360
+ /// Interaction with a context menu (secondary click ).
361
+ fn context_interaction ( response : & Response , root : & mut Option < Self > ) -> MenuResponse {
362
362
let response = response. interact ( Sense :: click ( ) ) ;
363
363
response. ctx . input ( |input| {
364
364
let pointer = & input. pointer ;
@@ -371,7 +371,7 @@ impl MenuRoot {
371
371
}
372
372
if !in_old_menu {
373
373
if response. hovered ( ) && response. secondary_clicked ( ) {
374
- return MenuResponse :: Create ( pos, id) ;
374
+ return MenuResponse :: Create ( pos, response . id ) ;
375
375
} else if ( response. hovered ( ) && pointer. primary_down ( ) ) || destroy {
376
376
return MenuResponse :: Close ;
377
377
}
@@ -392,14 +392,14 @@ impl MenuRoot {
392
392
}
393
393
394
394
/// Respond to secondary (right) clicks.
395
- pub fn context_click_interaction ( response : & Response , root : & mut MenuRootManager , id : Id ) {
396
- let menu_response = Self :: context_interaction ( response, root, id ) ;
395
+ pub fn context_click_interaction ( response : & Response , root : & mut MenuRootManager ) {
396
+ let menu_response = Self :: context_interaction ( response, root) ;
397
397
Self :: handle_menu_response ( root, menu_response) ;
398
398
}
399
399
400
400
// Responds to primary clicks.
401
- pub fn stationary_click_interaction ( response : & Response , root : & mut MenuRootManager , id : Id ) {
402
- let menu_response = Self :: stationary_interaction ( response, root, id ) ;
401
+ pub fn stationary_click_interaction ( response : & Response , root : & mut MenuRootManager ) {
402
+ let menu_response = Self :: stationary_interaction ( response, root) ;
403
403
Self :: handle_menu_response ( root, menu_response) ;
404
404
}
405
405
}
0 commit comments