Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 9, 2022
1 parent b95649b commit c476228
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
28 changes: 15 additions & 13 deletions crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,10 @@ fn show_tooltip_at_avoid_dyn<'c, R>(

let position = position.at_least(ctx.input().screen_rect().min);

let InnerResponse { inner, response } = show_tooltip_area_dyn(
ctx,
frame_state.common_id.with(frame_state.count),
position,
add_contents,
);
let area_id = frame_state.common_id.with(frame_state.count);

let InnerResponse { inner, response } =
show_tooltip_area_dyn(ctx, area_id, position, add_contents);

long_state.set_individual_tooltip(
frame_state.common_id,
Expand Down Expand Up @@ -255,12 +253,12 @@ pub fn show_tooltip_text(ctx: &Context, id: Id, text: impl Into<WidgetText>) ->
/// Show a pop-over window.
fn show_tooltip_area_dyn<'c, R>(
ctx: &Context,
id: Id,
area_id: Id,
window_pos: Pos2,
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> InnerResponse<R> {
use containers::*;
Area::new(id)
Area::new(area_id)
.order(Order::Tooltip)
.fixed_pos(window_pos)
.interactable(false)
Expand All @@ -278,11 +276,15 @@ fn show_tooltip_area_dyn<'c, R>(
/// Was this popup visible last frame?
pub fn was_tooltip_open_last_frame(ctx: &Context, tooltip_id: Id) -> bool {
if let Some(state) = TooltipState::load(ctx) {
for (count, (individual_id, _size)) in &state.individual_ids_and_sizes {
if *individual_id == tooltip_id {
let layer_id = LayerId::new(Order::Tooltip, individual_id.with(count));
if ctx.memory().areas.visible_last_frame(&layer_id) {
return true;
if let Some(common_id) = state.last_common_id {
for (count, (individual_id, _size)) in &state.individual_ids_and_sizes {
if *individual_id == tooltip_id {
let area_id = common_id.with(count);
let layer_id = LayerId::new(Order::Tooltip, area_id);
eprintln!("FOUND! Querying layer_id: {:?}", layer_id);
if ctx.memory().areas.visible_last_frame(&layer_id) {
return true;
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ impl Response {
self
}

/// Was the tooltip open last frame?
pub fn is_tooltip_open(&self) -> bool {
crate::popup::was_tooltip_open_last_frame(&self.ctx, self.id.with("__tooltip"))
}

fn should_show_hover_ui(&self) -> bool {
if self.ctx.memory().everything_is_visible() {
return true;
Expand All @@ -400,9 +405,7 @@ impl Response {
// but once shown we keep showing it until the mouse leaves the parent.

let is_pointer_still = self.ctx.input().pointer.is_still();
if !is_pointer_still
&& !crate::popup::was_tooltip_open_last_frame(&self.ctx, self.id.with("__tooltip"))
{
if !is_pointer_still && !self.is_tooltip_open() {
// wait for mouse to stop
self.ctx.request_repaint();
return false;
Expand Down

0 comments on commit c476228

Please sign in to comment.