Skip to content

Commit

Permalink
Fix clickable widgets blocking scrolling on touch screens
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Jan 14, 2024
1 parent 301c72b commit 86cb281
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ struct ViewportState {
used: bool,

/// Written to during the frame.
layer_rects_this_frame: HashMap<LayerId, Vec<(Id, Rect)>>,
layer_rects_this_frame: HashMap<LayerId, Vec<(Id, Rect, Sense)>>,

/// Read
layer_rects_prev_frame: HashMap<LayerId, Vec<(Id, Rect)>>,
layer_rects_prev_frame: HashMap<LayerId, Vec<(Id, Rect, Sense)>>,

/// State related to repaint scheduling.
repaint: ViewportRepaintInfo,
Expand Down Expand Up @@ -865,17 +865,20 @@ impl Context {
.layer_rects_this_frame
.entry(layer_id)
.or_default()
.push((id, interact_rect));
.push((id, interact_rect, sense));

if hovered {
let pointer_pos = viewport.input.pointer.interact_pos();
if let Some(pointer_pos) = pointer_pos {
if let Some(rects) = viewport.layer_rects_prev_frame.get(&layer_id) {
for &(prev_id, prev_rect) in rects.iter().rev() {
for &(prev_id, prev_rect, prev_sense) in rects.iter().rev() {
if prev_id == id {
break; // there is no other interactive widget covering us at the pointer position.
}
if prev_rect.contains(pointer_pos) {
if prev_rect.contains(pointer_pos)
&& ((prev_sense.click && sense.click)
|| (prev_sense.drag && sense.drag))
{
// Another interactive widget is covering us at the pointer position,
// so we aren't hovered.

Expand Down

0 comments on commit 86cb281

Please sign in to comment.