Clean up context menu documentation
This commit is contained in:
parent
369ce95bbd
commit
f919b0cc05
3 changed files with 26 additions and 19 deletions
|
@ -313,16 +313,6 @@ impl CtxRef {
|
||||||
pub fn debug_painter(&self) -> Painter {
|
pub fn debug_painter(&self) -> Painter {
|
||||||
Self::layer_painter(self, LayerId::debug())
|
Self::layer_painter(self, LayerId::debug())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to secondary clicks (right-clicks) by showing the given menu.
|
|
||||||
pub(crate) fn show_context_menu(
|
|
||||||
&self,
|
|
||||||
response: &Response,
|
|
||||||
add_contents: impl FnOnce(&mut Ui),
|
|
||||||
) {
|
|
||||||
self.context_menu_system()
|
|
||||||
.context_menu(response, add_contents);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -332,7 +322,7 @@ impl CtxRef {
|
||||||
/// This is the first thing you need when working with egui.
|
/// This is the first thing you need when working with egui.
|
||||||
/// Use [`CtxRef`] to create and refer to a [`Context`].
|
/// Use [`CtxRef`] to create and refer to a [`Context`].
|
||||||
///
|
///
|
||||||
/// Contains the [`InputState`], [`Memory`], [`Output`], and more.///
|
/// Contains the [`InputState`], [`Memory`], [`Output`], and more.
|
||||||
///
|
///
|
||||||
/// Almost all methods are marked `&self`, [`Context`] has interior mutability (protected by mutexes).
|
/// Almost all methods are marked `&self`, [`Context`] has interior mutability (protected by mutexes).
|
||||||
/// Multi-threaded access to a [`Context`] is behind the feature flag `multi_threaded`.
|
/// Multi-threaded access to a [`Context`] is behind the feature flag `multi_threaded`.
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl BarState {
|
||||||
ctx.memory().data.insert_temp(bar_id, self);
|
ctx.memory().data.insert_temp(bar_id, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show a menu at pointer if right-clicked response.
|
/// Show a menu at pointer if primary-clicked response.
|
||||||
/// Should be called from [`Context`] on a [`Response`]
|
/// Should be called from [`Context`] on a [`Response`]
|
||||||
pub fn bar_menu<R>(
|
pub fn bar_menu<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -87,8 +87,11 @@ pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> InnerResp
|
||||||
add_contents(ui)
|
add_contents(ui)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a top level menu in a menu bar. This would be e.g. "File", "Edit" etc.
|
/// Construct a top level menu in a menu bar. This would be e.g. "File", "Edit" etc.
|
||||||
///
|
///
|
||||||
|
/// Responds to primary clicks.
|
||||||
|
///
|
||||||
/// Returns `None` if the menu is not open.
|
/// Returns `None` if the menu is not open.
|
||||||
pub fn menu_button<R>(
|
pub fn menu_button<R>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
|
@ -97,8 +100,11 @@ pub fn menu_button<R>(
|
||||||
) -> InnerResponse<Option<R>> {
|
) -> InnerResponse<Option<R>> {
|
||||||
stationary_menu_impl(ui, title, Box::new(add_contents))
|
stationary_menu_impl(ui, title, Box::new(add_contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a nested sub menu in another menu.
|
/// Construct a nested sub menu in another menu.
|
||||||
///
|
///
|
||||||
|
/// Opens on hover.
|
||||||
|
///
|
||||||
/// Returns `None` if the menu is not open.
|
/// Returns `None` if the menu is not open.
|
||||||
pub(crate) fn submenu_button<R>(
|
pub(crate) fn submenu_button<R>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
|
@ -150,7 +156,9 @@ pub(crate) fn menu_ui<'c, R>(
|
||||||
inner_response
|
inner_response
|
||||||
}
|
}
|
||||||
|
|
||||||
/// build a top level menu with a button
|
/// Build a top level menu with a button.
|
||||||
|
///
|
||||||
|
/// Responds to primary clicks.
|
||||||
fn stationary_menu_impl<'c, R>(
|
fn stationary_menu_impl<'c, R>(
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
title: impl Into<WidgetText>,
|
title: impl Into<WidgetText>,
|
||||||
|
@ -275,7 +283,10 @@ impl MenuRoot {
|
||||||
}
|
}
|
||||||
(MenuResponse::Stay, None)
|
(MenuResponse::Stay, None)
|
||||||
}
|
}
|
||||||
/// interaction with a stationary menu, i.e. fixed in another Ui
|
|
||||||
|
/// Interaction with a stationary menu, i.e. fixed in another Ui.
|
||||||
|
///
|
||||||
|
/// Responds to primary clicks.
|
||||||
fn stationary_interaction(
|
fn stationary_interaction(
|
||||||
response: &Response,
|
response: &Response,
|
||||||
root: &mut MenuRootManager,
|
root: &mut MenuRootManager,
|
||||||
|
@ -310,7 +321,8 @@ impl MenuRoot {
|
||||||
}
|
}
|
||||||
MenuResponse::Stay
|
MenuResponse::Stay
|
||||||
}
|
}
|
||||||
/// interaction with a context menu
|
|
||||||
|
/// Interaction with a context menu (secondary clicks).
|
||||||
fn context_interaction(
|
fn context_interaction(
|
||||||
response: &Response,
|
response: &Response,
|
||||||
root: &mut Option<MenuRoot>,
|
root: &mut Option<MenuRoot>,
|
||||||
|
@ -328,10 +340,9 @@ impl MenuRoot {
|
||||||
destroy = root.id == response.id;
|
destroy = root.id == response.id;
|
||||||
}
|
}
|
||||||
if !in_old_menu {
|
if !in_old_menu {
|
||||||
let in_target = response.hovered();
|
if response.hovered() && pointer.secondary_down() {
|
||||||
if in_target && pointer.secondary_down() {
|
|
||||||
return MenuResponse::Create(pos, id);
|
return MenuResponse::Create(pos, id);
|
||||||
} else if (in_target && pointer.primary_down()) || destroy {
|
} else if (response.hovered() && pointer.primary_down()) || destroy {
|
||||||
return MenuResponse::Close;
|
return MenuResponse::Close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,6 +350,7 @@ impl MenuRoot {
|
||||||
}
|
}
|
||||||
MenuResponse::Stay
|
MenuResponse::Stay
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) {
|
fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) {
|
||||||
match menu_response {
|
match menu_response {
|
||||||
MenuResponse::Create(pos, id) => {
|
MenuResponse::Create(pos, id) => {
|
||||||
|
@ -348,11 +360,14 @@ impl MenuRoot {
|
||||||
MenuResponse::Stay => {}
|
MenuResponse::Stay => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to secondary (right) clicks.
|
/// Respond to secondary (right) clicks.
|
||||||
pub fn context_click_interaction(response: &Response, root: &mut MenuRootManager, id: Id) {
|
pub fn context_click_interaction(response: &Response, root: &mut MenuRootManager, id: Id) {
|
||||||
let menu_response = Self::context_interaction(response, root, id);
|
let menu_response = Self::context_interaction(response, root, id);
|
||||||
Self::handle_menu_response(root, menu_response);
|
Self::handle_menu_response(root, menu_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Responds to primary clicks.
|
||||||
pub fn stationary_click_interaction(response: &Response, root: &mut MenuRootManager, id: Id) {
|
pub fn stationary_click_interaction(response: &Response, root: &mut MenuRootManager, id: Id) {
|
||||||
let menu_response = Self::stationary_interaction(response, root, id);
|
let menu_response = Self::stationary_interaction(response, root, id);
|
||||||
Self::handle_menu_response(root, menu_response);
|
Self::handle_menu_response(root, menu_response);
|
||||||
|
|
|
@ -491,7 +491,9 @@ impl Response {
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
pub fn context_menu(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
pub fn context_menu(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||||
self.ctx.show_context_menu(&self, add_contents);
|
self.ctx
|
||||||
|
.context_menu_system()
|
||||||
|
.context_menu(&self, add_contents);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue