Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 1 addition & 32 deletions 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::{LayerId, Pos2, Rect, Sense, WidgetRect, WidgetRects, ahash, emath, id::IdSet};
use crate::{LayerId, Pos2, Sense, WidgetRect, WidgetRects, ahash, emath, id::IdSet};

/// Result of a hit-test against [`WidgetRects`].
///
Expand Down Expand Up @@ -427,16 +427,6 @@ fn find_closest_within(

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

if let Some(closest) = closest
&& dist_sq == closest_dist_sq
{
// It's a tie! Pick the thin candidate over the thick one.
// This makes it easier to hit a thin resize-handle, for instance:
if should_prioritize_hits_on_back(closest.interact_rect, widget.interact_rect) {
continue;
}
}

// In case of a tie, take the last one = the one on top.
if dist_sq <= closest_dist_sq {
closest_dist_sq = dist_sq;
Expand All @@ -447,27 +437,6 @@ fn find_closest_within(
closest
}

/// Should we prioritize hits on `back` over those on `front`?
///
/// `back` should be behind the `front` widget.
///
/// Returns true if `back` is a small hit-target and `front` is not.
fn should_prioritize_hits_on_back(back: Rect, front: Rect) -> bool {
if front.contains_rect(back) {
return false; // back widget is fully occluded; no way to hit it
}

// Reduce each rect to its width or height, whichever is smaller:
let back = back.width().min(back.height());
let front = front.width().min(front.height());

// These are hard-coded heuristics that could surely be improved.
let back_is_much_thinner = back <= 0.5 * front;
let back_is_thin = back <= 16.0;

back_is_much_thinner && back_is_thin
}

#[cfg(test)]
mod tests {
#![expect(clippy::print_stdout)]
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ impl Default for Interaction {
fn default() -> Self {
Self {
interact_radius: 5.0,
resize_grab_radius_side: 5.0,
resize_grab_radius_side: 3.0,
resize_grab_radius_corner: 10.0,
show_tooltips_only_when_still: true,
tooltip_delay: 0.5,
Expand Down
Loading