Skip to content

Commit

Permalink
Fix dead-lock when alt-tabbing while also showing a tooltip (#1618)
Browse files Browse the repository at this point in the history
Closes #1609
  • Loading branch information
emilk committed May 11, 2022
1 parent c47e20c commit 9624de6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,9 +5,14 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w


## Unreleased
### Added ⭐
* Add `*_released` & `*_clicked` methods for `PointerState` ([#1582](https://github.com/emilk/egui/pull/1582)).
* Optimize painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).

### Fixed 🐛
* Fixed `ImageButton`'s changing background padding on hover ([#1595](https://github.com/emilk/egui/pull/1595)).
* Fix dead-lock when alt-tabbing while also showing a tooltip ([#1618](https://github.com/emilk/egui/pull/1618)).


## 0.18.1 - 2022-05-01
* Change `Shape::Callback` from `&dyn Any` to `&mut dyn Any` to support more backends.
Expand Down
18 changes: 11 additions & 7 deletions egui/src/containers/popup.rs
Expand Up @@ -160,13 +160,13 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
let mut tooltip_rect = Rect::NOTHING;
let mut count = 0;

let mut position = if let Some((stored_id, stored_tooltip_rect, stored_count)) =
ctx.frame_state().tooltip_rect
{
let stored = ctx.frame_state().tooltip_rect;

let mut position = if let Some(stored) = stored {
// if there are multiple tooltips open they should use the same id for the `tooltip_size` caching to work.
id = stored_id;
tooltip_rect = stored_tooltip_rect;
count = stored_count;
id = stored.id;
tooltip_rect = stored.rect;
count = stored.count;
avoid_rect = avoid_rect.union(tooltip_rect);
if above {
tooltip_rect.left_top()
Expand Down Expand Up @@ -214,7 +214,11 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
state.set_tooltip_size(id, count, response.rect.size());
state.store(ctx);

ctx.frame_state().tooltip_rect = Some((id, tooltip_rect.union(response.rect), count + 1));
ctx.frame_state().tooltip_rect = Some(crate::frame_state::TooltipRect {
id,
rect: tooltip_rect.union(response.rect),
count: count + 1,
});
Some(inner)
}

Expand Down
9 changes: 8 additions & 1 deletion egui/src/frame_state.rs
Expand Up @@ -2,6 +2,13 @@ use std::ops::RangeInclusive;

use crate::*;

#[derive(Clone, Copy, Debug)]
pub(crate) struct TooltipRect {
pub id: Id,
pub rect: Rect,
pub count: usize,
}

/// State that is collected during a frame and then cleared.
/// Short-term (single frame) memory.
#[derive(Clone)]
Expand All @@ -25,7 +32,7 @@ pub(crate) struct FrameState {
/// If a tooltip has been shown this frame, where was it?
/// This is used to prevent multiple tooltips to cover each other.
/// Initialized to `None` at the start of each frame.
pub(crate) tooltip_rect: Option<(Id, Rect, usize)>,
pub(crate) tooltip_rect: Option<TooltipRect>,

/// Set to [`InputState::scroll_delta`] on the start of each frame.
///
Expand Down

0 comments on commit 9624de6

Please sign in to comment.