Skip to content

Commit acf804a

Browse files
committed
also touch for symmetry
1 parent 5a3ac37 commit acf804a

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

crates/bevy_input/src/touch.rs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ impl Touches {
246246
}
247247

248248
/// Returns the [`Touch`] input corresponding to the `id` if it is being pressed.
249-
pub fn get_pressed(&self, id: u64) -> Option<&Touch> {
250-
self.pressed.get(&id)
249+
pub fn get_pressed(&self, id: &u64) -> Option<&Touch> {
250+
self.pressed.get(id)
251251
}
252252

253253
/// Checks if any touch input was just pressed.
@@ -268,15 +268,15 @@ impl Touches {
268268
}
269269

270270
/// Returns `true` if the input corresponding to the `id` has just been pressed.
271-
pub fn just_pressed(&self, id: u64) -> bool {
272-
self.just_pressed.contains_key(&id)
271+
pub fn just_pressed(&self, id: &u64) -> bool {
272+
self.just_pressed.contains_key(id)
273273
}
274274

275275
/// Clears the `just_pressed` state of the touch input and returns `true` if the touch input has just been pressed.
276276
///
277277
/// Future calls to [`Touches::just_pressed`] for the given touch input will return false until a new press event occurs.
278-
pub fn clear_just_pressed(&mut self, id: u64) -> bool {
279-
self.just_pressed.remove(&id).is_some()
278+
pub fn clear_just_pressed(&mut self, id: &u64) -> bool {
279+
self.just_pressed.remove(id).is_some()
280280
}
281281

282282
/// An iterator visiting every just pressed [`Touch`] input in arbitrary order.
@@ -285,8 +285,8 @@ impl Touches {
285285
}
286286

287287
/// Returns the [`Touch`] input corresponding to the `id` if it has just been released.
288-
pub fn get_released(&self, id: u64) -> Option<&Touch> {
289-
self.just_released.get(&id)
288+
pub fn get_released(&self, id: &u64) -> Option<&Touch> {
289+
self.just_released.get(id)
290290
}
291291

292292
/// Checks if any touch input was just released.
@@ -295,15 +295,15 @@ impl Touches {
295295
}
296296

297297
/// Returns `true` if the input corresponding to the `id` has just been released.
298-
pub fn just_released(&self, id: u64) -> bool {
299-
self.just_released.contains_key(&id)
298+
pub fn just_released(&self, id: &u64) -> bool {
299+
self.just_released.contains_key(id)
300300
}
301301

302302
/// Clears the `just_released` state of the touch input and returns `true` if the touch input has just been released.
303303
///
304304
/// Future calls to [`Touches::just_released`] for the given touch input will return false until a new release event occurs.
305-
pub fn clear_just_released(&mut self, id: u64) -> bool {
306-
self.just_released.remove(&id).is_some()
305+
pub fn clear_just_released(&mut self, id: &u64) -> bool {
306+
self.just_released.remove(id).is_some()
307307
}
308308

309309
/// An iterator visiting every just released [`Touch`] input in arbitrary order.
@@ -317,8 +317,8 @@ impl Touches {
317317
}
318318

319319
/// Returns `true` if the input corresponding to the `id` has just been canceled.
320-
pub fn just_canceled(&self, id: u64) -> bool {
321-
self.just_canceled.contains_key(&id)
320+
pub fn just_canceled(&self, id: &u64) -> bool {
321+
self.just_canceled.contains_key(id)
322322
}
323323

324324
/// Clears the `just_canceled` state of the touch input and returns `true` if the touch input has just been canceled.
@@ -602,7 +602,7 @@ mod test {
602602
touches.process_touch_event(&moved_touch_event2);
603603

604604
{
605-
let touch = touches.get_pressed(started_touch_event.id).unwrap();
605+
let touch = touches.get_pressed(&started_touch_event.id).unwrap();
606606
assert_eq!(touch.previous_position, started_touch_event.position);
607607
assert_eq!(touch.position, moved_touch_event2.position);
608608
}
@@ -616,7 +616,7 @@ mod test {
616616
touches.process_touch_event(&moved_touch_event1);
617617

618618
{
619-
let touch = touches.get_pressed(started_touch_event.id).unwrap();
619+
let touch = touches.get_pressed(&started_touch_event.id).unwrap();
620620
assert_eq!(touch.previous_position, moved_touch_event2.position);
621621
assert_eq!(touch.position, moved_touch_event1.position);
622622
}
@@ -641,12 +641,12 @@ mod test {
641641
// Register the touch and test that it was registered correctly
642642
touches.process_touch_event(&touch_event);
643643

644-
assert!(touches.get_pressed(touch_event.id).is_some());
645-
assert!(touches.just_pressed(touch_event.id));
644+
assert!(touches.get_pressed(&touch_event.id).is_some());
645+
assert!(touches.just_pressed(&touch_event.id));
646646
assert_eq!(touches.iter().count(), 1);
647647

648-
touches.clear_just_pressed(touch_event.id);
649-
assert!(!touches.just_pressed(touch_event.id));
648+
touches.clear_just_pressed(&touch_event.id);
649+
assert!(!touches.just_pressed(&touch_event.id));
650650
}
651651

652652
#[test]
@@ -668,12 +668,12 @@ mod test {
668668
// Register the touch and test that it was registered correctly
669669
touches.process_touch_event(&touch_event);
670670

671-
assert!(touches.get_released(touch_event.id).is_some());
672-
assert!(touches.just_released(touch_event.id));
671+
assert!(touches.get_released(&touch_event.id).is_some());
672+
assert!(touches.just_released(&touch_event.id));
673673
assert_eq!(touches.iter_just_released().count(), 1);
674674

675-
touches.clear_just_released(touch_event.id);
676-
assert!(!touches.just_released(touch_event.id));
675+
touches.clear_just_released(&touch_event.id);
676+
assert!(!touches.just_released(&touch_event.id));
677677
}
678678

679679
#[test]
@@ -695,11 +695,11 @@ mod test {
695695
// Register the touch and test that it was registered correctly
696696
touches.process_touch_event(&touch_event);
697697

698-
assert!(touches.just_canceled(touch_event.id));
698+
assert!(touches.just_canceled(&touch_event.id));
699699
assert_eq!(touches.iter_just_canceled().count(), 1);
700700

701701
touches.clear_just_canceled(touch_event.id);
702-
assert!(!touches.just_canceled(touch_event.id));
702+
assert!(!touches.just_canceled(&touch_event.id));
703703
}
704704

705705
#[test]
@@ -721,11 +721,11 @@ mod test {
721721
// Register the touch and test that it was registered correctly
722722
touches.process_touch_event(&touch_event);
723723

724-
assert!(touches.get_pressed(touch_event.id).is_some());
724+
assert!(touches.get_pressed(&touch_event.id).is_some());
725725

726726
touches.release(touch_event.id);
727-
assert!(touches.get_pressed(touch_event.id).is_none());
728-
assert!(touches.just_released(touch_event.id));
727+
assert!(touches.get_pressed(&touch_event.id).is_none());
728+
assert!(touches.just_released(&touch_event.id));
729729
}
730730

731731
#[test]
@@ -755,15 +755,15 @@ mod test {
755755
touches.process_touch_event(&touch_pressed_event);
756756
touches.process_touch_event(&touch_moved_event);
757757

758-
assert!(touches.get_pressed(touch_pressed_event.id).is_some());
759-
assert!(touches.get_pressed(touch_moved_event.id).is_some());
758+
assert!(touches.get_pressed(&touch_pressed_event.id).is_some());
759+
assert!(touches.get_pressed(&touch_moved_event.id).is_some());
760760

761761
touches.release_all();
762762

763-
assert!(touches.get_pressed(touch_pressed_event.id).is_none());
764-
assert!(touches.just_released(touch_pressed_event.id));
765-
assert!(touches.get_pressed(touch_moved_event.id).is_none());
766-
assert!(touches.just_released(touch_moved_event.id));
763+
assert!(touches.get_pressed(&touch_pressed_event.id).is_none());
764+
assert!(touches.just_released(&touch_pressed_event.id));
765+
assert!(touches.get_pressed(&touch_moved_event.id).is_none());
766+
assert!(touches.just_released(&touch_moved_event.id));
767767
}
768768

769769
#[test]
@@ -803,17 +803,17 @@ mod test {
803803
touches.process_touch_event(&touch_canceled_event);
804804
touches.process_touch_event(&touch_released_event);
805805

806-
assert!(touches.get_pressed(touch_press_event.id).is_some());
807-
assert!(touches.just_pressed(touch_press_event.id));
808-
assert!(touches.just_canceled(touch_canceled_event.id));
809-
assert!(touches.just_released(touch_released_event.id));
806+
assert!(touches.get_pressed(&touch_press_event.id).is_some());
807+
assert!(touches.just_pressed(&touch_press_event.id));
808+
assert!(touches.just_canceled(&touch_canceled_event.id));
809+
assert!(touches.just_released(&touch_released_event.id));
810810

811811
touches.clear();
812812

813-
assert!(touches.get_pressed(touch_press_event.id).is_some());
814-
assert!(!touches.just_pressed(touch_press_event.id));
815-
assert!(!touches.just_canceled(touch_canceled_event.id));
816-
assert!(!touches.just_released(touch_released_event.id));
813+
assert!(touches.get_pressed(&touch_press_event.id).is_some());
814+
assert!(!touches.just_pressed(&touch_press_event.id));
815+
assert!(!touches.just_canceled(&touch_canceled_event.id));
816+
assert!(!touches.just_released(&touch_released_event.id));
817817
}
818818

819819
#[test]
@@ -853,17 +853,17 @@ mod test {
853853
touches.process_touch_event(&touch_canceled_event);
854854
touches.process_touch_event(&touch_released_event);
855855

856-
assert!(touches.get_pressed(touch_press_event.id).is_some());
857-
assert!(touches.just_pressed(touch_press_event.id));
858-
assert!(touches.just_canceled(touch_canceled_event.id));
859-
assert!(touches.just_released(touch_released_event.id));
856+
assert!(touches.get_pressed(&touch_press_event.id).is_some());
857+
assert!(touches.just_pressed(&touch_press_event.id));
858+
assert!(touches.just_canceled(&touch_canceled_event.id));
859+
assert!(touches.just_released(&touch_released_event.id));
860860

861861
touches.reset_all();
862862

863-
assert!(touches.get_pressed(touch_press_event.id).is_none());
864-
assert!(!touches.just_pressed(touch_press_event.id));
865-
assert!(!touches.just_canceled(touch_canceled_event.id));
866-
assert!(!touches.just_released(touch_released_event.id));
863+
assert!(touches.get_pressed(&touch_press_event.id).is_none());
864+
assert!(!touches.just_pressed(&touch_press_event.id));
865+
assert!(!touches.just_canceled(&touch_canceled_event.id));
866+
assert!(!touches.just_released(&touch_released_event.id));
867867
}
868868

869869
fn clear_all(touch_state: &mut Touches) {

examples/input/touch_input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ fn touch_system(touches: Res<Touches>) {
3333
// you can also iterate all current touches and retrieve their state like this:
3434
for touch in touches.iter() {
3535
info!("active touch: {:?}", touch);
36-
info!(" just_pressed: {}", touches.just_pressed(touch.id()));
36+
info!(" just_pressed: {}", touches.just_pressed(&touch.id()));
3737
}
3838
}

0 commit comments

Comments
 (0)