[popup_modal] Add documentation

This commit is contained in:
Malik Olivier Boussejra 2018-09-26 14:27:35 +09:00
parent ae9a79bd50
commit 88b5b2e3f5
2 changed files with 21 additions and 0 deletions

View File

@ -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)
}

View File

@ -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<F: FnOnce()>(self, f: F) {
let render = unsafe {
sys::igBeginPopupModal(