// use crate::string::ImStr; use crate::sys; use crate::Ui; /// # Widgets: Menus impl<'ui> Ui<'ui> { /// Creates and starts appending to a full-screen menu bar. /// /// Returns `Some(MainMenuBarToken)` if the menu bar is visible. After content has been /// rendered, the token must be ended by calling `.end()`. /// /// Returns `None` if the menu bar is not visible and no content should be rendered. #[must_use] #[doc(alias = "BeginMainMenuBar")] pub fn begin_main_menu_bar(&self) -> Option> { if unsafe { sys::igBeginMainMenuBar() } { Some(MainMenuBarToken::new(self)) } else { None } } /// Creates a full-screen main menu bar and runs a closure to construct the contents. /// /// Note: the closure is not called if the menu bar is not visible. #[doc(alias = "BeginMenuBar")] pub fn main_menu_bar(&self, f: F) { if let Some(_menu_bar) = self.begin_main_menu_bar() { f(); } } /// Creates and starts appending to the menu bar of the current window. /// /// Returns `Some(MenuBarToken)` if the menu bar is visible. After content has been /// rendered, the token must be ended by calling `.end()`. /// /// Returns `None` if the menu bar is not visible and no content should be rendered. #[must_use] #[doc(alias = "BeginMenuBar")] pub fn begin_menu_bar(&self) -> Option> { if unsafe { sys::igBeginMenuBar() } { Some(MenuBarToken::new(self)) } else { None } } /// Creates a menu bar in the current window and runs a closure to construct the contents. /// /// Note: the closure is not called if the menu bar is not visible. #[doc(alias = "BeginMenuBar")] pub fn menu_bar(&self, f: F) { if let Some(_menu_bar) = self.begin_menu_bar() { f(); } } /// Creates and starts appending to a sub-menu entry. /// /// Returns `Some(MenuToken)` if the menu is visible. After content has been /// rendered, the token must be ended by calling `.end()`. /// /// Returns `None` if the menu is not visible and no content should be rendered. /// /// This is the equivalent of [begin_menu_with_enabled](Self::begin_menu_with_enabled) /// with `enabled` set to `true`. #[must_use] #[doc(alias = "BeginMenu")] pub fn begin_menu(&self, label: impl AsRef) -> Option> { self.begin_menu_with_enabled(label, true) } /// Creates and starts appending to a sub-menu entry. /// /// Returns `Some(MenuToken)` if the menu is visible. After content has been /// rendered, the token must be ended by calling `.end()`. /// /// Returns `None` if the menu is not visible and no content should be rendered. #[must_use] #[doc(alias = "BeginMenu")] pub fn begin_menu_with_enabled( &self, label: impl AsRef, enabled: bool, ) -> Option> { if unsafe { sys::igBeginMenu(self.scratch_txt(label), enabled) } { Some(MenuToken::new(self)) } else { None } } /// Creates a menu and runs a closure to construct the contents. /// /// Note: the closure is not called if the menu is not visible. /// /// This is the equivalent of [menu_with_enabled](Self::menu_with_enabled) /// with `enabled` set to `true`. #[doc(alias = "BeginMenu")] pub fn menu(&self, label: impl AsRef, f: F) { self.menu_with_enabled(label, true, f); } /// Creates a menu and runs a closure to construct the contents. /// /// Note: the closure is not called if the menu is not visible. #[doc(alias = "BeginMenu")] pub fn menu_with_enabled(&self, label: impl AsRef, enabled: bool, f: F) { if let Some(_menu) = self.begin_menu_with_enabled(label, enabled) { f(); } } } /// Builder for a menu item. #[derive(Copy, Clone, Debug)] #[must_use] pub struct MenuItem { label: Label, shortcut: Option, selected: bool, enabled: bool, } impl> MenuItem