Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Response::show_tooltip_ui and show_tooltip_text #4580

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading