Add Response::on_disabled_hover_text to show tooltip for disabled widgets
Closes https://github.com/emilk/egui/issues/323
This commit is contained in:
parent
07da54ad08
commit
fb6f49024f
2 changed files with 27 additions and 2 deletions
|
@ -22,6 +22,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
|
||||||
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).
|
* Fix [defocus-bug on touch screens](https://github.com/emilk/egui/issues/288).
|
||||||
* Fix bug with the layout of wide `DragValue`:s.
|
* Fix bug with the layout of wide `DragValue`:s.
|
||||||
|
|
||||||
|
|
||||||
## 0.11.0 - 2021-04-05 - Optimization, screen reader & new layout logic
|
## 0.11.0 - 2021-04-05 - Optimization, screen reader & new layout logic
|
||||||
|
|
||||||
### Added ⭐
|
### Added ⭐
|
||||||
|
|
|
@ -289,7 +289,9 @@ impl Response {
|
||||||
self.changed = true;
|
self.changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show this UI if the item was hovered (i.e. a tooltip).
|
/// Show this UI if the widget was hovered (i.e. a tooltip).
|
||||||
|
///
|
||||||
|
/// The text will not be visible if the widget is not enabled.
|
||||||
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
||||||
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||||
if self.should_show_hover_ui() {
|
if self.should_show_hover_ui() {
|
||||||
|
@ -303,6 +305,19 @@ impl Response {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show this UI when hovering if the widget is disabled.
|
||||||
|
pub fn on_disabled_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||||
|
if !self.enabled && self.ctx.rect_contains_pointer(self.layer_id, self.rect) {
|
||||||
|
crate::containers::show_tooltip_under(
|
||||||
|
&self.ctx,
|
||||||
|
self.id.with("__tooltip"),
|
||||||
|
&self.rect,
|
||||||
|
add_contents,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Like `on_hover_ui`, but show the ui next to cursor.
|
/// Like `on_hover_ui`, but show the ui next to cursor.
|
||||||
pub fn on_hover_ui_at_pointer(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
pub fn on_hover_ui_at_pointer(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
|
||||||
if self.should_show_hover_ui() {
|
if self.should_show_hover_ui() {
|
||||||
|
@ -337,7 +352,9 @@ impl Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show this text if the item was hovered (i.e. a tooltip).
|
/// Show this text if the widget was hovered (i.e. a tooltip).
|
||||||
|
///
|
||||||
|
/// The text will not be visible if the widget is not enabled.
|
||||||
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
/// If you call this multiple times the tooltips will stack underneath the previous ones.
|
||||||
pub fn on_hover_text(self, text: impl Into<String>) -> Self {
|
pub fn on_hover_text(self, text: impl Into<String>) -> Self {
|
||||||
self.on_hover_ui(|ui| {
|
self.on_hover_ui(|ui| {
|
||||||
|
@ -345,6 +362,13 @@ impl Response {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show this text when hovering if the widget is disabled.
|
||||||
|
pub fn on_disabled_hover_text(self, text: impl Into<String>) -> Self {
|
||||||
|
self.on_disabled_hover_ui(|ui| {
|
||||||
|
ui.add(crate::widgets::Label::new(text));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[deprecated = "Deprecated 2020-10-01: use `on_hover_text` instead."]
|
#[deprecated = "Deprecated 2020-10-01: use `on_hover_text` instead."]
|
||||||
pub fn tooltip_text(self, text: impl Into<String>) -> Self {
|
pub fn tooltip_text(self, text: impl Into<String>) -> Self {
|
||||||
self.on_hover_text(text)
|
self.on_hover_text(text)
|
||||||
|
|
Loading…
Reference in a new issue