diff --git a/src/lib.rs b/src/lib.rs index 9a25353..bbfc4d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1206,6 +1206,23 @@ impl<'ui> Ui<'ui> { unsafe { sys::igEndPopup() }; } } + /// Create a modal pop-up. + /// + /// # Example + /// ```rust,no_run + /// # use imgui::*; + /// # let mut imgui = ImGui::init(); + /// # let ui = imgui.frame(FrameSize::new(100.0, 100.0, 1.0), 0.1); + /// if ui.button(im_str!("Show modal"), (0.0, 0.0)) { + /// ui.open_popup(im_str!("modal")); + /// } + /// ui.popup_modal(im_str!("modal")).build(|| { + /// ui.text("Content of my modal"); + /// if ui.button(im_str!("OK"), (0.0, 0.0)) { + /// ui.close_current_popup(); + /// } + /// }); + /// ``` pub fn popup_modal<'p>(&self, str_id: &'p ImStr) -> PopupModal<'ui, 'p> { PopupModal::new(self, str_id) } diff --git a/src/popup_modal.rs b/src/popup_modal.rs index 791a644..0f2e873 100644 --- a/src/popup_modal.rs +++ b/src/popup_modal.rs @@ -5,6 +5,7 @@ use super::{ImGuiWindowFlags, ImStr, Ui}; use sys; +/// Created by call to [`Ui::popup_modal`]. #[must_use] pub struct PopupModal<'ui, 'p> { label: &'p ImStr, @@ -22,6 +23,8 @@ impl<'ui, 'p> PopupModal<'ui, 'p> { _phantom: PhantomData, } } + /// Pass a mutable boolean which will be updated to refer to the current + /// "open" state of the modal. pub fn opened(mut self, opened: &'p mut bool) -> Self { self.opened = Some(opened); self @@ -98,6 +101,7 @@ impl<'ui, 'p> PopupModal<'ui, 'p> { .set(ImGuiWindowFlags::AlwaysUseWindowPadding, value); self } + /// Consume and draw the PopupModal. pub fn build(self, f: F) { let render = unsafe { sys::igBeginPopupModal(