Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait with showing tooltip until mouse has been still for 300ms #3977

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Owner Author

@emilk emilk Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this doesn't save any CPU right now because of #3109, but that will soon be fixed

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
Loading