Skip to content

Commit 7bfee6d

Browse files
emilkhacknus
authored andcommitted
Wait with showing tooltip until mouse has been still for 300ms (emilk#3977)
You can change this with `style.interaction.tooltip_delay§
1 parent 2ba91f3 commit 7bfee6d

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

crates/egui/src/input_state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ impl PointerState {
886886

887887
/// How long has it been (in seconds) since the pointer was last moved?
888888
#[inline(always)]
889-
pub fn time_since_last_movement(&self) -> f64 {
890-
self.time - self.last_move_time
889+
pub fn time_since_last_movement(&self) -> f32 {
890+
(self.time - self.last_move_time) as f32
891891
}
892892

893893
/// Was any pointer button pressed (`!down -> down`) this frame?

crates/egui/src/response.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,16 @@ impl Response {
499499
}
500500
}
501501

502-
if !self.is_tooltip_open()
503-
&& self.ctx.input(|i| i.pointer.time_since_last_movement())
504-
< self.ctx.style().interaction.tooltip_delay
505-
{
506-
// Keep waiting until the mouse has been still for a while
507-
self.ctx.request_repaint();
508-
return false;
502+
if !self.is_tooltip_open() {
503+
let time_til_tooltip = self.ctx.style().interaction.tooltip_delay
504+
- self.ctx.input(|i| i.pointer.time_since_last_movement());
505+
506+
if 0.0 < time_til_tooltip {
507+
// Wait until the mouse has been still for a while
508+
self.ctx
509+
.request_repaint_after(std::time::Duration::from_secs_f32(time_til_tooltip));
510+
return false;
511+
}
509512
}
510513

511514
// We don't want tooltips of things while we are dragging them,

crates/egui/src/style.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub struct Interaction {
719719
pub show_tooltips_only_when_still: bool,
720720

721721
/// Delay in seconds before showing tooltips after the mouse stops moving
722-
pub tooltip_delay: f64,
722+
pub tooltip_delay: f32,
723723

724724
/// Can you select the text on a [`crate::Label`] by default?
725725
pub selectable_labels: bool,
@@ -1128,7 +1128,7 @@ impl Default for Interaction {
11281128
resize_grab_radius_side: 5.0,
11291129
resize_grab_radius_corner: 10.0,
11301130
show_tooltips_only_when_still: true,
1131-
tooltip_delay: 0.0,
1131+
tooltip_delay: 0.3,
11321132
selectable_labels: true,
11331133
multi_widget_text_select: true,
11341134
}

0 commit comments

Comments
 (0)