Skip to content

Commit 89684bd

Browse files
committedMay 11, 2022
Fix dead-lock when alt-tabbing while also showing a tooltip
Closes #1609
1 parent c47e20c commit 89684bd

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
 

‎CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui-w
55

66

77
## Unreleased
8+
### Added ⭐
89
* Add `*_released` & `*_clicked` methods for `PointerState` ([#1582](https://github.com/emilk/egui/pull/1582)).
910
* Optimize painting of filled circles (e.g. for scatter plots) by 10x or more ([#1616](https://github.com/emilk/egui/pull/1616)).
11+
12+
### Fixed 🐛
1013
* Fixed `ImageButton`'s changing background padding on hover ([#1595](https://github.com/emilk/egui/pull/1595)).
14+
* Fix dead-lock when alt-tabbing while also showing a tooltip.
15+
1116

1217
## 0.18.1 - 2022-05-01
1318
* Change `Shape::Callback` from `&dyn Any` to `&mut dyn Any` to support more backends.

‎egui/src/containers/popup.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
160160
let mut tooltip_rect = Rect::NOTHING;
161161
let mut count = 0;
162162

163-
let mut position = if let Some((stored_id, stored_tooltip_rect, stored_count)) =
164-
ctx.frame_state().tooltip_rect
165-
{
163+
let stored = ctx.frame_state().tooltip_rect;
164+
165+
let mut position = if let Some(stored) = stored {
166166
// if there are multiple tooltips open they should use the same id for the `tooltip_size` caching to work.
167-
id = stored_id;
168-
tooltip_rect = stored_tooltip_rect;
169-
count = stored_count;
167+
id = stored.id;
168+
tooltip_rect = stored.rect;
169+
count = stored.count;
170170
avoid_rect = avoid_rect.union(tooltip_rect);
171171
if above {
172172
tooltip_rect.left_top()
@@ -214,7 +214,11 @@ fn show_tooltip_at_avoid_dyn<'c, R>(
214214
state.set_tooltip_size(id, count, response.rect.size());
215215
state.store(ctx);
216216

217-
ctx.frame_state().tooltip_rect = Some((id, tooltip_rect.union(response.rect), count + 1));
217+
ctx.frame_state().tooltip_rect = Some(crate::frame_state::TooltipRect {
218+
id,
219+
rect: tooltip_rect.union(response.rect),
220+
count: count + 1,
221+
});
218222
Some(inner)
219223
}
220224

‎egui/src/frame_state.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ use std::ops::RangeInclusive;
22

33
use crate::*;
44

5+
#[derive(Clone, Copy, Debug)]
6+
pub(crate) struct TooltipRect {
7+
pub id: Id,
8+
pub rect: Rect,
9+
pub count: usize,
10+
}
11+
512
/// State that is collected during a frame and then cleared.
613
/// Short-term (single frame) memory.
714
#[derive(Clone)]
@@ -25,7 +32,7 @@ pub(crate) struct FrameState {
2532
/// If a tooltip has been shown this frame, where was it?
2633
/// This is used to prevent multiple tooltips to cover each other.
2734
/// Initialized to `None` at the start of each frame.
28-
pub(crate) tooltip_rect: Option<(Id, Rect, usize)>,
35+
pub(crate) tooltip_rect: Option<TooltipRect>,
2936

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

0 commit comments

Comments
 (0)