mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-17 08:28:44 +00:00
[popup_modal] Add documentation
This commit is contained in:
parent
ae9a79bd50
commit
88b5b2e3f5
17
src/lib.rs
17
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)
|
||||
}
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user