Skip to content

Commit 5fbc9f1

Browse files
ickshonpekfc35
andauthored
PointerbuttonState::clear (#21997)
# Objective To clear the `PointerButtonState`, `clear` is called on each of its individual fields holding the button state data. Instead add a `clear` method to `PointerButtonState`. ## Solution Add a `clear` method to `PointerButtonState` to clear its data. --------- Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
1 parent c378b7a commit 5fbc9f1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

crates/bevy_picking/src/events.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ pub struct PointerButtonState {
351351
pub dragging_over: HashMap<Entity, HitData>,
352352
}
353353

354+
impl PointerButtonState {
355+
/// Clears all press and drag data tracked for this button on its pointer.
356+
pub fn clear(&mut self) {
357+
self.pressing.clear();
358+
self.dragging.clear();
359+
self.dragging_over.clear();
360+
}
361+
}
362+
354363
/// State for all pointers.
355364
#[derive(Debug, Clone, Default, Resource)]
356365
pub struct PointerState {
@@ -379,9 +388,7 @@ impl PointerState {
379388
pub fn clear(&mut self, pointer_id: PointerId) {
380389
for button in PointerButton::iter() {
381390
if let Some(state) = self.pointer_buttons.get_mut(&(pointer_id, button)) {
382-
state.pressing.clear();
383-
state.dragging.clear();
384-
state.dragging_over.clear();
391+
state.clear();
385392
}
386393
}
387394
}
@@ -699,9 +706,7 @@ pub fn pointer_events(
699706
}
700707

701708
// Finally, we can clear the state of everything relating to presses or drags.
702-
state.pressing.clear();
703-
state.dragging.clear();
704-
state.dragging_over.clear();
709+
state.clear();
705710
}
706711
// Moved
707712
PointerAction::Move { delta } => {

0 commit comments

Comments
 (0)