Skip to content

Commit

Permalink
Fix widgets sometimes being incorrectly marked as hovered (#5523)
Browse files Browse the repository at this point in the history
An interactive widget should only be marked hovered if a click/drag
would start an interaction with it.

egui 0.30 introduced a feature where a thin interactive widget could be
hit even if it was partially behind a larger interactive widget.
Unfortunately, this introduced a bug where the top widget would still be
marked as hovered, even though a click would go through to the thin
widget below.

This bug was most notacible when trying to reisize a window by dragging
its corner, which often would result in dragging one of its sides
instead.

This PR fixes this bug.
  • Loading branch information
emilk authored Dec 27, 2024
1 parent d20f93e commit 4d945f7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/egui/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ pub(crate) fn interact(
// In that case we want to hover _both_ widgets,
// otherwise we won't see tooltips for the label.
//
// Because of how `Ui` work, we will often allocate the `Ui` rect
// _after_ adding the children in it (once we know the size it will occopy)
// so we will also have a lot of such `Ui` widgets rects covering almost any widget.
//
// So: we want to hover _all_ widgets above the interactive widget (if any),
// but none below it (an interactive widget stops the hover search).
//
Expand All @@ -275,8 +271,16 @@ pub(crate) fn interact(
let mut hovered: IdSet = hits.click.iter().chain(&hits.drag).map(|w| w.id).collect();

for w in &hits.contains_pointer {
if top_interactive_order <= order(w.id).unwrap_or(0) {
hovered.insert(w.id);
let is_interactive = w.sense.click || w.sense.drag;
if is_interactive {
// The only interactive widgets we mark as hovered are the ones
// in `hits.click` and `hits.drag`!
} else {
let is_on_top_of_the_interactive_widget =
top_interactive_order <= order(w.id).unwrap_or(0);
if is_on_top_of_the_interactive_widget {
hovered.insert(w.id);
}
}
}

Expand Down

0 comments on commit 4d945f7

Please sign in to comment.