mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Fix dead-lock when alt-tabbing while also showing a tooltip (#1618)
Closes https://github.com/emilk/egui/issues/1609
This commit is contained in:
@@ -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()
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)]
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user