diff --git a/crates/egui/src/input_state.rs b/crates/egui/src/input_state.rs index 1a31c9dd069..0de78a43752 100644 --- a/crates/egui/src/input_state.rs +++ b/crates/egui/src/input_state.rs @@ -886,8 +886,8 @@ impl PointerState { /// How long has it been (in seconds) since the pointer was last moved? #[inline(always)] - pub fn time_since_last_movement(&self) -> f64 { - self.time - self.last_move_time + pub fn time_since_last_movement(&self) -> f32 { + (self.time - self.last_move_time) as f32 } /// Was any pointer button pressed (`!down -> down`) this frame? diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index bc252052ae4..2b55a9d53d6 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -499,13 +499,16 @@ impl Response { } } - if !self.is_tooltip_open() - && self.ctx.input(|i| i.pointer.time_since_last_movement()) - < self.ctx.style().interaction.tooltip_delay - { - // Keep waiting until the mouse has been still for a while - self.ctx.request_repaint(); - return false; + if !self.is_tooltip_open() { + let time_til_tooltip = self.ctx.style().interaction.tooltip_delay + - self.ctx.input(|i| i.pointer.time_since_last_movement()); + + 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)); + return false; + } } // We don't want tooltips of things while we are dragging them, diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 70e65261df6..645a7d188f2 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -719,7 +719,7 @@ pub struct Interaction { pub show_tooltips_only_when_still: bool, /// Delay in seconds before showing tooltips after the mouse stops moving - pub tooltip_delay: f64, + pub tooltip_delay: f32, /// Can you select the text on a [`crate::Label`] by default? pub selectable_labels: bool, @@ -1128,7 +1128,7 @@ impl Default for Interaction { resize_grab_radius_side: 5.0, resize_grab_radius_corner: 10.0, show_tooltips_only_when_still: true, - tooltip_delay: 0.0, + tooltip_delay: 0.3, selectable_labels: true, multi_widget_text_select: true, }