Merge pull request #327 from barsoosayque/master

Manually managing tooltips
This commit is contained in:
Joonas Javanainen 2020-07-07 22:33:44 +03:00 committed by GitHub
commit f7f074423d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.