1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Make on_disabled_hover_ui respect tooltip_delay (#4012)

* Closes <https://github.com/emilk/egui/issues/3997>
This commit is contained in:
YgorSouza
2024-02-10 09:07:21 +01:00
committed by GitHub
parent 15370bbea0
commit 1bc70b20b1
2 changed files with 32 additions and 9 deletions

View File

@@ -438,7 +438,7 @@ impl Response {
/// If you call this multiple times the tooltips will stack underneath the previous ones.
#[doc(alias = "tooltip")]
pub fn on_hover_ui(self, add_contents: impl FnOnce(&mut Ui)) -> Self {
if self.should_show_hover_ui() {
if self.enabled && self.should_show_hover_ui() {
crate::containers::show_tooltip_for(
&self.ctx,
self.id.with("__tooltip"),
@@ -451,7 +451,7 @@ impl Response {
/// 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) {
if !self.enabled && self.should_show_hover_ui() {
crate::containers::show_tooltip_for(
&self.ctx,
self.id.with("__tooltip"),
@@ -464,7 +464,7 @@ impl Response {
/// 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 {
if self.should_show_hover_ui() {
if self.enabled && self.should_show_hover_ui() {
crate::containers::show_tooltip_at_pointer(
&self.ctx,
self.id.with("__tooltip"),
@@ -484,7 +484,11 @@ impl Response {
return true;
}
if !self.hovered || !self.ctx.input(|i| i.pointer.has_pointer()) {
if self.enabled {
if !self.hovered || !self.ctx.input(|i| i.pointer.has_pointer()) {
return false;
}
} else if !self.ctx.rect_contains_pointer(self.layer_id, self.rect) {
return false;
}
@@ -505,8 +509,9 @@ impl Response {
if 0.0 < time_til_tooltip {
// Wait until the mouse has been still for a while
self.ctx
.request_repaint_after(std::time::Duration::from_secs_f32(time_til_tooltip));
if let Ok(duration) = std::time::Duration::try_from_secs_f32(time_til_tooltip) {
self.ctx.request_repaint_after(duration);
}
return false;
}
}