Skip to content

Commit

Permalink
Add Response::show_tooltip_ui and show_tooltip_text (#4580)
Browse files Browse the repository at this point in the history
These functions will always show a tooltip under the widget when called,
even if the user is not hovering the widget.

This can be useful for tutorials and notification and similar.

* Closes #890
  • Loading branch information
emilk authored May 29, 2024
1 parent 0039614 commit 16277eb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,7 @@ impl Response {
#[doc(alias = "tooltip")]
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
if self.enabled && self.should_show_hover_ui() {
crate::containers::show_tooltip_for(
&self.ctx,
self.id.with("__tooltip"),
&self.rect,
add_contents,
);
self.show_tooltip_ui(add_contents);
}
self
}
Expand Down Expand Up @@ -558,6 +553,27 @@ impl Response {
self
}

/// Always show this tooltip, even if disabled and the user isn't hovering it.
///
/// This can be used to give attention to a widget during a tutorial.
pub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui)) {
crate::containers::show_tooltip_for(
&self.ctx,
self.id.with("__tooltip"),
&self.rect,
add_contents,
);
}

/// Always show this tooltip, even if disabled and the user isn't hovering it.
///
/// This can be used to give attention to a widget during a tutorial.
pub fn show_tooltip_text(&self, text: impl Into<WidgetText>) {
self.show_tooltip_ui(|ui| {
ui.label(text);
});
}

/// Was the tooltip open last frame?
pub fn is_tooltip_open(&self) -> bool {
crate::popup::was_tooltip_open_last_frame(&self.ctx, self.id.with("__tooltip"))
Expand Down

0 comments on commit 16277eb

Please sign in to comment.