Skip to content

Commit 4d945f7

Browse files
authored
Fix widgets sometimes being incorrectly marked as hovered (emilk#5523)
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.
1 parent d20f93e commit 4d945f7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/egui/src/interaction.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ pub(crate) fn interact(
256256
// In that case we want to hover _both_ widgets,
257257
// otherwise we won't see tooltips for the label.
258258
//
259-
// Because of how `Ui` work, we will often allocate the `Ui` rect
260-
// _after_ adding the children in it (once we know the size it will occopy)
261-
// so we will also have a lot of such `Ui` widgets rects covering almost any widget.
262-
//
263259
// So: we want to hover _all_ widgets above the interactive widget (if any),
264260
// but none below it (an interactive widget stops the hover search).
265261
//
@@ -275,8 +271,16 @@ pub(crate) fn interact(
275271
let mut hovered: IdSet = hits.click.iter().chain(&hits.drag).map(|w| w.id).collect();
276272

277273
for w in &hits.contains_pointer {
278-
if top_interactive_order <= order(w.id).unwrap_or(0) {
279-
hovered.insert(w.id);
274+
let is_interactive = w.sense.click || w.sense.drag;
275+
if is_interactive {
276+
// The only interactive widgets we mark as hovered are the ones
277+
// in `hits.click` and `hits.drag`!
278+
} else {
279+
let is_on_top_of_the_interactive_widget =
280+
top_interactive_order <= order(w.id).unwrap_or(0);
281+
if is_on_top_of_the_interactive_widget {
282+
hovered.insert(w.id);
283+
}
280284
}
281285
}
282286

0 commit comments

Comments
 (0)