From 32a9b4abcc36e5a5481d870d0f64995f5eac8c7d Mon Sep 17 00:00:00 2001 From: Juan Campa Date: Sat, 5 Feb 2022 04:51:16 -0500 Subject: [PATCH] Add on_hover_text_at_pointer (#1179) --- CHANGELOG.md | 1 + egui/src/response.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 906f896f892..713a2011fda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * Added `ui.data()`, `ctx.data()`, `ctx.options()` and `ctx.tessellation_options()` ([#1175](https://github.com/emilk/egui/pull/1175)). * Added `Plot::allow_boxed_zoom()`, `Plot::boxed_zoom_pointer()` for boxed zooming on plots ([#1188](https://github.com/emilk/egui/pull/1188)). * Added linked axis support for plots via `plot::LinkedAxisGroup` ([#1184](https://github.com/emilk/egui/pull/1184)). +* Added `Response::on_hover_text_at_pointer` as a convenience akin to `Response::on_hover_text`. ([1179](https://github.com/emilk/egui/pull/1179)) ### Changed 🔧 * ⚠️ `Context::input` and `Ui::input` now locks a mutex. This can lead to a dead-lock is used in an `if let` binding! diff --git a/egui/src/response.rs b/egui/src/response.rs index e20c87b3313..d685174f3eb 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -383,6 +383,14 @@ impl Response { true } + /// Like `on_hover_text`, but show the text next to cursor. + #[doc(alias = "tooltip")] + pub fn on_hover_text_at_pointer(self, text: impl Into) -> Self { + self.on_hover_ui_at_pointer(|ui| { + ui.add(crate::widgets::Label::new(text)); + }) + } + /// Show this text if the widget was hovered (i.e. a tooltip). /// /// The text will not be visible if the widget is not enabled.