Skip to content

Commit

Permalink
Only show tooltips when mouse pointer is still
Browse files Browse the repository at this point in the history
Revert to the old behavior by setting
`style.interaction.show_tooltips_only_when_still = false`.
  • Loading branch information
emilk committed Nov 8, 2022
1 parent 3521360 commit d1fc794
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG

### Changed 🔧
* Panels always have a separator line, but no stroke on other sides. Their spacing has also changed slightly ([#2261](https://github.com/emilk/egui/pull/2261)).
* Tooltips are only shown when mouse pointer is still ([#2263](https://github.com/emilk/egui/pull/2263)).

### Fixed 🐛
* ⚠️ BREAKING: Fix text being too small ([#2069](https://github.com/emilk/egui/pull/2069)).
Expand Down
12 changes: 8 additions & 4 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::*;

/// Same state for all tooltips.
#[derive(Clone, Debug, Default)]
pub(crate) struct MonoState {
pub(crate) struct PopupState {
last_id: Option<Id>,
last_size: Vec<Vec2>,
}

impl MonoState {
fn load(ctx: &Context) -> Option<Self> {
impl PopupState {
pub fn load(ctx: &Context) -> Option<Self> {
ctx.data().get_temp(Id::null())
}

Expand Down Expand Up @@ -45,6 +45,10 @@ impl MonoState {
self.last_size.extend((0..index).map(|_| Vec2::ZERO));
self.last_size.push(size);
}

pub fn is_open(ctx: &Context, id: &Id) -> bool {
Self::load(ctx).map_or(false, |state| state.last_id == Some(*id))
}
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -181,7 +185,7 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
return None; // No good place for a tooltip :(
};

let mut state = MonoState::load(ctx).unwrap_or_default();
let mut state = PopupState::load(ctx).unwrap_or_default();
let expected_size = state.tooltip_size(id, count);
let expected_size = expected_size.unwrap_or_else(|| vec2(64.0, 32.0));

Expand Down
18 changes: 12 additions & 6 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,18 @@ impl Response {
return false;
}

if self.ctx.style().interaction.show_tooltips_only_when_still
&& !self.ctx.input().pointer.is_still()
{
// wait for mouse to stop
self.ctx.request_repaint();
return false;
if self.ctx.style().interaction.show_tooltips_only_when_still {
// We only show the tooltip when the mouse pointer is still,
// but once shown we keep showing it until the mouse leaves the parent.

use crate::containers::popup::PopupState;

let is_pointer_still = self.ctx.input().pointer.is_still();
if !is_pointer_still && !PopupState::is_open(&self.ctx, &self.id.with("__tooltip")) {
// wait for mouse to stop
self.ctx.request_repaint();
return false;
}
}

// We don't want tooltips of things while we are dragging them,
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl Default for Interaction {
Self {
resize_grab_radius_side: 5.0,
resize_grab_radius_corner: 10.0,
show_tooltips_only_when_still: false,
show_tooltips_only_when_still: true,
}
}
}
Expand Down

0 comments on commit d1fc794

Please sign in to comment.