Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hovering through custom menu button #5555

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/egui/src/hit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ahash::HashMap;

use emath::TSTransform;

use crate::{ahash, emath, LayerId, Pos2, Rect, WidgetRect, WidgetRects};
use crate::{ahash, emath, Id, LayerId, Pos2, Rect, WidgetRect, WidgetRects};

/// Result of a hit-test against [`WidgetRects`].
///
Expand Down Expand Up @@ -133,6 +133,23 @@ pub fn hit_test(
}
}

// Find widgets which are hidden behind another widget and discard them.
// This is the case when a widget fully contains another widget and is on a different layer.
// It prevents "hovering through" widgets when there is a clickable widget behind.

let mut hidden: ahash::HashSet<Id> = Default::default();
for (i, current) in close.iter().enumerate().rev() {
for next in &close[i + 1..] {
if next.interact_rect.contains_rect(current.interact_rect)
&& current.layer_id != next.layer_id
{
hidden.insert(current.id);
}
}
}

close.retain(|c| !hidden.contains(&c.id));

let mut hits = hit_test_on_close(&close, pos);

hits.contains_pointer = close
Expand Down