Skip to content

Commit 88e2d51

Browse files
emilkhacknus
authored andcommitted
Add Response::show_tooltip_ui and show_tooltip_text (emilk#4580)
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 emilk#890
1 parent 995eddb commit 88e2d51

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

crates/egui/src/response.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,12 +523,7 @@ impl Response {
523523
#[doc(alias = "tooltip")]
524524
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
525525
if self.enabled && self.should_show_hover_ui() {
526-
crate::containers::show_tooltip_for(
527-
&self.ctx,
528-
self.id.with("__tooltip"),
529-
&self.rect,
530-
add_contents,
531-
);
526+
self.show_tooltip_ui(add_contents);
532527
}
533528
self
534529
}
@@ -558,6 +553,27 @@ impl Response {
558553
self
559554
}
560555

556+
/// Always show this tooltip, even if disabled and the user isn't hovering it.
557+
///
558+
/// This can be used to give attention to a widget during a tutorial.
559+
pub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui)) {
560+
crate::containers::show_tooltip_for(
561+
&self.ctx,
562+
self.id.with("__tooltip"),
563+
&self.rect,
564+
add_contents,
565+
);
566+
}
567+
568+
/// Always show this tooltip, even if disabled and the user isn't hovering it.
569+
///
570+
/// This can be used to give attention to a widget during a tutorial.
571+
pub fn show_tooltip_text(&self, text: impl Into<WidgetText>) {
572+
self.show_tooltip_ui(|ui| {
573+
ui.label(text);
574+
});
575+
}
576+
561577
/// Was the tooltip open last frame?
562578
pub fn is_tooltip_open(&self) -> bool {
563579
crate::popup::was_tooltip_open_last_frame(&self.ctx, self.id.with("__tooltip"))

0 commit comments

Comments
 (0)