Fix hovering through custom menu button (#5555)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> This change discards widgets which are fully covered by another widget in a higher layer from the hit test algorithm. * Closes <https://github.com/emilk/egui/issues/5498> * [x] I have followed the instructions in the PR template --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
parent
5b740f97ac
commit
493d5d0982
|
|
@ -2,7 +2,7 @@ use ahash::HashMap;
|
|||
|
||||
use emath::TSTransform;
|
||||
|
||||
use crate::{ahash, emath, LayerId, Pos2, Rect, Sense, WidgetRect, WidgetRects};
|
||||
use crate::{ahash, emath, id::IdSet, LayerId, Pos2, Rect, Sense, WidgetRect, WidgetRects};
|
||||
|
||||
/// Result of a hit-test against [`WidgetRects`].
|
||||
///
|
||||
|
|
@ -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 = IdSet::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
|
||||
|
|
|
|||
Loading…
Reference in New Issue