diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index d23d5d20f31..7d76763f53a 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -25,16 +25,16 @@ use std::sync::Arc; /// What is saved between frames. #[derive(Clone, Default)] -pub(crate) struct BarState { +pub struct BarState { open_menu: MenuRootManager, } impl BarState { - fn load(ctx: &Context, bar_id: Id) -> Self { + pub fn load(ctx: &Context, bar_id: Id) -> Self { ctx.data_mut(|d| d.get_temp::(bar_id).unwrap_or_default()) } - fn store(self, ctx: &Context, bar_id: Id) { + pub fn store(self, ctx: &Context, bar_id: Id) { ctx.data_mut(|d| d.insert_temp(bar_id, self)); } @@ -242,7 +242,7 @@ pub(crate) fn context_menu_opened(response: &Response) -> bool { /// Stores the state for the context menu. #[derive(Clone, Default)] -pub(crate) struct MenuRootManager { +pub struct MenuRootManager { inner: Option, } @@ -287,7 +287,7 @@ impl std::ops::DerefMut for MenuRootManager { /// Menu root associated with an Id from a Response #[derive(Clone)] -pub(crate) struct MenuRoot { +pub struct MenuRoot { pub menu_state: Arc>, pub id: Id, } @@ -372,7 +372,7 @@ impl MenuRoot { } /// Interaction with a context menu (secondary click). - fn context_interaction(response: &Response, root: &mut Option) -> MenuResponse { + pub fn context_interaction(response: &Response, root: &mut Option) -> MenuResponse { let response = response.interact(Sense::click()); let hovered = response.hovered(); let secondary_clicked = response.secondary_clicked(); @@ -398,7 +398,7 @@ impl MenuRoot { }) } - fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) { + pub fn handle_menu_response(root: &mut MenuRootManager, menu_response: MenuResponse) { match menu_response { MenuResponse::Create(pos, id) => { root.inner = Some(Self::new(pos, id)); @@ -421,8 +421,8 @@ impl MenuRoot { } } -#[derive(Copy, Clone, PartialEq)] -pub(crate) enum MenuResponse { +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum MenuResponse { Close, Stay, Create(Pos2, Id), @@ -562,7 +562,10 @@ impl SubMenu { } } -pub(crate) struct MenuState { +/// Components of menu state, public for advanced usage. +/// +/// Usually you don't need to use it directly. +pub struct MenuState { /// The opened sub-menu and its [`Id`] sub_menu: Option<(Id, Arc>)>,