Skip to content

Commit

Permalink
Wait with showing tooltip until mouse has been still for 300ms (#3977)
Browse files Browse the repository at this point in the history
You can change this with `style.interaction.tooltip_delay§
  • Loading branch information
emilk authored Feb 5, 2024
1 parent 28d3c8e commit d018265
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
17 changes: 10 additions & 7 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit d018265

Please sign in to comment.