Skip to content

Commit

Permalink
feat: allow more leeway for doubleclick
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Feb 16, 2025
1 parent 6e17a2b commit 40115e9
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions examples/src/mandelbrot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,50 +282,49 @@ impl AppState for MandelbrotState {
button: MouseButton::Left,
..
} => {
self.interaction_state =
if elem_state == ElementState::Pressed {
self.last_cursor_location = self.cursor_location;

match self.interaction_state.clone() {
InteractionState::Idle {
pre_tapped_at: Some(pre_tapped_at),
} => {
if now_secs() - pre_tapped_at < 0.7f32 {
log::info!("Started zooming out at {}", now_secs());
InteractionState::ZoomingOut
} else {
InteractionState::PanningIdle {
pressed_down_at: now_secs(),
}
self.interaction_state = if elem_state == ElementState::Pressed {
self.last_cursor_location = self.cursor_location;

match self.interaction_state.clone() {
InteractionState::Idle {
pre_tapped_at: Some(pre_tapped_at),
} => {
if now_secs() - pre_tapped_at < 1f32 {
log::info!("Started zooming out at {}", now_secs());
InteractionState::ZoomingOut
} else {
InteractionState::PanningIdle {
pressed_down_at: now_secs(),
}
}
InteractionState::Idle { .. } => InteractionState::PanningIdle {
pressed_down_at: now_secs(),
},
state => state,
}
} else if elem_state == ElementState::Released {
match self.interaction_state.clone() {
InteractionState::PanningIdle { pressed_down_at } => {
let elapsed = now_secs() - pressed_down_at;
let pre_tapped_at = if elapsed < 0.3f32 {
Some(pressed_down_at)
} else {
None
};

InteractionState::Idle { pre_tapped_at }
}
InteractionState::ZoomingIn
| InteractionState::ZoomingOut
| InteractionState::Panning => InteractionState::Idle {
pre_tapped_at: None,
},
state => state,
InteractionState::Idle { .. } => InteractionState::PanningIdle {
pressed_down_at: now_secs(),
},
state => state,
}
} else if elem_state == ElementState::Released {
match self.interaction_state.clone() {
InteractionState::PanningIdle { pressed_down_at } => {
let elapsed = now_secs() - pressed_down_at;
let pre_tapped_at = if elapsed < 0.3f32 {
Some(pressed_down_at)
} else {
None
};

InteractionState::Idle { pre_tapped_at }
}
} else {
self.interaction_state.clone()
};
InteractionState::ZoomingIn
| InteractionState::ZoomingOut
| InteractionState::Panning => InteractionState::Idle {
pre_tapped_at: None,
},
state => state,
}
} else {
self.interaction_state.clone()
};
}
_ => {}
}
Expand Down

0 comments on commit 40115e9

Please sign in to comment.