Skip to content

Commit

Permalink
Explicitly handle negatve rectangle in hit interaction code
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jun 19, 2024
1 parent 44bca2c commit ea3ffc6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/egui/src/hit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub fn hit_test(
.filter(|layer| layer.order.allow_interaction())
.flat_map(|&layer_id| widgets.get_layer(layer_id))
.filter(|&w| {
if w.interact_rect.is_negative() {
return false;
}

let pos_in_layer = pos_in_layers.get(&w.layer_id).copied().unwrap_or(pos);
let dist_sq = w.interact_rect.distance_sq_to_pos(pos_in_layer);

Expand Down Expand Up @@ -311,6 +315,10 @@ fn find_closest(widgets: impl Iterator<Item = WidgetRect>, pos: Pos2) -> Option<
let mut closest = None;
let mut closest_dist_sq = f32::INFINITY;
for widget in widgets {
if widget.interact_rect.is_negative() {
continue;
}

let dist_sq = widget.interact_rect.distance_sq_to_pos(pos);

// In case of a tie, take the last one = the one on top.
Expand Down

0 comments on commit ea3ffc6

Please sign in to comment.