mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Change bevy_input::Touch API to match similar APIs (#952)
This commit is contained in:
parent
c7b9ad5097
commit
4c1bc02723
3 changed files with 44 additions and 12 deletions
|
@ -85,13 +85,13 @@ pub struct TouchSystemState {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Touch {
|
||||
pub id: u64,
|
||||
pub start_position: Vec2,
|
||||
pub start_force: Option<ForceTouch>,
|
||||
pub previous_position: Vec2,
|
||||
pub previous_force: Option<ForceTouch>,
|
||||
pub position: Vec2,
|
||||
pub force: Option<ForceTouch>,
|
||||
id: u64,
|
||||
start_position: Vec2,
|
||||
start_force: Option<ForceTouch>,
|
||||
previous_position: Vec2,
|
||||
previous_force: Option<ForceTouch>,
|
||||
position: Vec2,
|
||||
force: Option<ForceTouch>,
|
||||
}
|
||||
|
||||
impl Touch {
|
||||
|
@ -102,6 +102,36 @@ impl Touch {
|
|||
pub fn distance(&self) -> Vec2 {
|
||||
self.position - self.start_position
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn id(&self) -> u64 {
|
||||
self.id
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn start_position(&self) -> Vec2 {
|
||||
self.start_position
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn start_force(&self) -> Option<ForceTouch> {
|
||||
self.start_force
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn previous_position(&self) -> Vec2 {
|
||||
self.previous_position
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn position(&self) -> Vec2 {
|
||||
self.position
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn force(&self) -> Option<ForceTouch> {
|
||||
self.force
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&TouchInput> for Touch {
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn ui_focus_system(
|
|||
state.cursor_position = cursor_moved.position;
|
||||
}
|
||||
if let Some(touch) = touches_input.get_pressed(0) {
|
||||
state.cursor_position = touch.position;
|
||||
state.cursor_position = touch.position();
|
||||
}
|
||||
|
||||
if mouse_button_input.just_released(MouseButton::Left) || touches_input.just_released(0) {
|
||||
|
|
|
@ -11,24 +11,26 @@ fn touch_system(touches: Res<Touches>) {
|
|||
for touch in touches.iter_just_pressed() {
|
||||
println!(
|
||||
"just pressed touch with id: {:?}, at: {:?}",
|
||||
touch.id, touch.position
|
||||
touch.id(),
|
||||
touch.position()
|
||||
);
|
||||
}
|
||||
|
||||
for touch in touches.iter_just_released() {
|
||||
println!(
|
||||
"just released touch with id: {:?}, at: {:?}",
|
||||
touch.id, touch.position
|
||||
touch.id(),
|
||||
touch.position()
|
||||
);
|
||||
}
|
||||
|
||||
for touch in touches.iter_just_cancelled() {
|
||||
println!("cancelled touch with id: {:?}", touch.id);
|
||||
println!("cancelled touch with id: {:?}", touch.id());
|
||||
}
|
||||
|
||||
// you can also iterate all current touches and retrieve their state like this:
|
||||
for touch in touches.iter() {
|
||||
println!("active touch: {:?}", touch);
|
||||
println!(" just_pressed: {}", touches.just_pressed(touch.id));
|
||||
println!(" just_pressed: {}", touches.just_pressed(touch.id()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue