Skip to content

Commit

Permalink
proposed extra methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbox-irl committed Sep 17, 2023
1 parent 3237845 commit 3fe6ec6
Showing 1 changed file with 59 additions and 6 deletions.
65 changes: 59 additions & 6 deletions imgui/src/popups.rs
Expand Up @@ -249,7 +249,10 @@ impl Ui {
}

/// Open and begin popup when clicked with the right mouse button on last item.
/// If you want to use that on a non-interactive item such as text() use [`Self::begin_popup_context_item_id`].
///
/// This does not take a label, which means that multiple calls **in a row** will use the same label, which
/// is based on the last node which had a label. Text and other non-interactive elements generally don't have
/// ids, so you'll need to use [begin_popup_context_with_label] for them.
#[doc(alias = "BeginPopupContextItem")]
pub fn begin_popup_context_item(&self) -> Option<PopupToken<'_>> {
let render = unsafe {
Expand All @@ -266,10 +269,12 @@ impl Ui {
}
}

/// Open and begin popup when clicked with the right mouse button on the given item.
/// If you want to use the last item and it has an id you, you can use [`Self::begin_popup_context_item`].
/// Open and begin popup when clicked with the right mouse button on the given item with a dedicated label.
///
/// If you want to use the label of the previous popup (outside of `Text` and other non-interactive cases, that
/// is the more normal case), use [begin_popup_context_item].
#[doc(alias = "BeginPopupContextItem")]
pub fn begin_popup_context_item_id<Label: AsRef<str>>(
pub fn begin_popup_context_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>> {
Expand All @@ -288,8 +293,32 @@ impl Ui {
}

/// Open and begin popup when clicked on current window.
///
/// This does not take a label, which means that multiple calls will use the same provided label.
/// If you want an explicit label, such as having two different kinds of windows popups in your program,
/// use [begin_popup_context_window_with_label].
#[doc(alias = "BeginPopupContextWindow")]
pub fn begin_popup_context_window(&self) -> Option<PopupToken<'_>> {
let render = unsafe {
sys::igBeginPopupContextWindow(
std::ptr::null(),
imgui_sys::ImGuiPopupFlags_MouseButtonRight as i32,
)
};

if render {
Some(PopupToken::new(self))
} else {
None
}
}

/// Open and begin popup when clicked on current window.
///
/// This takes a label explicitly. This is useful when multiple code
/// locations may want to manipulate/open the same popup, given an explicit id.
#[doc(alias = "BeginPopupContextWindow")]
pub fn begin_popup_context_window<Label: AsRef<str>>(
pub fn begin_popup_context_window_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>> {
Expand All @@ -308,8 +337,32 @@ impl Ui {
}

/// Open and begin popup when right clicked in void (where there are no windows).
///
/// This does not take a label, which means that multiple calls will use the same provided label.
/// If you want an explicit label, such as having two different kinds of void popups in your program,
/// use [begin_popup_context_void_with_label].
#[doc(alias = "BeginPopupContextWindow")]
pub fn begin_popup_context_void(&self) -> Option<PopupToken<'_>> {
let render = unsafe {
sys::igBeginPopupContextVoid(
std::ptr::null(),
imgui_sys::ImGuiPopupFlags_MouseButtonRight as i32,
)
};

if render {
Some(PopupToken::new(self))
} else {
None
}
}

/// Open and begin popup when right clicked in void (where there are no windows).
///
/// This takes a label explicitly. This is useful when multiple code
/// locations may want to manipulate/open the same popup, given an explicit id.
#[doc(alias = "BeginPopupContextVoid")]
pub fn begin_popup_context_void<Label: AsRef<str>>(
pub fn begin_popup_context_void_with_label<Label: AsRef<str>>(
&self,
str_id: Label,
) -> Option<PopupToken<'_>> {
Expand Down

0 comments on commit 3fe6ec6

Please sign in to comment.