Skip to content

Commit 46fb9ff

Browse files
authored
Context menus (#543)
Main usage: `response.context_menu(…)` and `ui.menu_button`
1 parent b31ca7e commit 46fb9ff

File tree

10 files changed

+792
-74
lines changed

10 files changed

+792
-74
lines changed

egui/src/context.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
frame_state::FrameState,
1212
input_state::*,
1313
layers::GraphicLayers,
14+
menu::ContextMenuSystem,
1415
mutex::{Mutex, MutexGuard},
1516
*,
1617
};
@@ -303,6 +304,15 @@ impl CtxRef {
303304
pub fn debug_painter(&self) -> Painter {
304305
Self::layer_painter(self, LayerId::debug())
305306
}
307+
308+
pub(crate) fn show_context_menu(
309+
&self,
310+
response: &Response,
311+
add_contents: impl FnOnce(&mut Ui),
312+
) {
313+
self.context_menu_system()
314+
.context_menu(response, add_contents);
315+
}
306316
}
307317

308318
// ----------------------------------------------------------------------------
@@ -329,6 +339,7 @@ pub struct Context {
329339
fonts: Option<Arc<Fonts>>,
330340
memory: Arc<Mutex<Memory>>,
331341
animation_manager: Arc<Mutex<AnimationManager>>,
342+
context_menu_system: Arc<Mutex<ContextMenuSystem>>,
332343

333344
input: InputState,
334345

@@ -357,6 +368,7 @@ impl Clone for Context {
357368
output: self.output.clone(),
358369
paint_stats: self.paint_stats.clone(),
359370
repaint_requests: self.repaint_requests.load(SeqCst).into(),
371+
context_menu_system: self.context_menu_system.clone(),
360372
}
361373
}
362374
}
@@ -375,6 +387,10 @@ impl Context {
375387
self.memory.lock()
376388
}
377389

390+
pub(crate) fn context_menu_system(&self) -> MutexGuard<'_, ContextMenuSystem> {
391+
self.context_menu_system.lock()
392+
}
393+
378394
pub(crate) fn graphics(&self) -> MutexGuard<'_, GraphicLayers> {
379395
self.graphics.lock()
380396
}

0 commit comments

Comments
 (0)