mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 21:48:36 +00:00
Merge pull request #327 from barsoosayque/master
Manually managing tooltips
This commit is contained in:
commit
f7f074423d
29
src/lib.rs
29
src/lib.rs
@ -327,6 +327,28 @@ impl<'ui> Ui<'ui> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Tracks a layout tooltip that must be ended by calling `.end()`
|
||||
#[must_use]
|
||||
pub struct TooltipToken {
|
||||
ctx: *const Context,
|
||||
}
|
||||
|
||||
impl TooltipToken {
|
||||
/// Ends a layout tooltip
|
||||
pub fn end(mut self, _: &Ui) {
|
||||
self.ctx = ptr::null();
|
||||
unsafe { sys::igEndTooltip() };
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TooltipToken {
|
||||
fn drop(&mut self) {
|
||||
if !self.ctx.is_null() && !thread::panicking() {
|
||||
panic!("A TooltipToken was leaked. Did you call .end()?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// # Tooltips
|
||||
impl<'ui> Ui<'ui> {
|
||||
/// Construct a tooltip window that can have any kind of content.
|
||||
@ -351,6 +373,13 @@ impl<'ui> Ui<'ui> {
|
||||
f();
|
||||
unsafe { sys::igEndTooltip() };
|
||||
}
|
||||
/// Construct a tooltip window that can have any kind of content.
|
||||
///
|
||||
/// Returns a `TooltipToken` that must be ended by calling `.end()`
|
||||
pub fn begin_tooltip(&self) -> TooltipToken {
|
||||
unsafe { sys::igBeginTooltip() };
|
||||
TooltipToken { ctx: self.ctx }
|
||||
}
|
||||
/// Construct a tooltip window with simple text content.
|
||||
///
|
||||
/// Typically used with `Ui::is_item_hovered()` or some other conditional check.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user