-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for event::Touch
on web targets
#1945
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You indicated that you want to help out with WASM, @FuriouZz, and I think helping review and test this (and other) web PRs would be a good start. You don't need to be a maintainer to review and/or test PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation sounds good to me. The force touch is currently implemented on iOS and it is possible on the web (see my comment). I prefer to validate this PR with its implementation.
Just asking @maroider, this may be the subject of another Issue/PR : winit does have any plans to support multi-touch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything being done in this PR to prevent non-touch pointer events being reported as WindowEvent::Touch
?
I've added a guard for it now. |
Well, I'll be damned. I had completely forgotten about that PR. |
Do note that that PR uses touch events instead of pointers, as was preferred in #1673 |
So I should close #1900 to avoid confusion, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to do a real-world test (although I don't think it's strictly necessary for me to do so), but this should otherwise be ready to be merged, despite how CI is a bit wonky ATM.
I'd also like a final sign-off from @FuriouZz before merging.
@maroider I can try this out, if you want before you merge it. I'm currently having to use my fork in order to power my Bounty Bros. game touch support on web so I have a perfect test case. I'll try to test it within the next ~12 hours ( probably less ) and comment here with the result. |
Sounds like a plan, @zicklag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some reword from pointer
to touch
@@ -231,6 +231,62 @@ impl<T> WindowTarget<T> { | |||
runner.request_redraw(WindowId(id)); | |||
}); | |||
|
|||
let runner = self.runner.clone(); | |||
canvas.on_pointer_move(move |device_id, location| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canvas.on_pointer_move(move |device_id, location| { | |
canvas.on_touch_move(move |device_id, location| { |
}); | ||
|
||
let runner = self.runner.clone(); | ||
canvas.on_pointer_down(move |device_id, location| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canvas.on_pointer_down(move |device_id, location| { | |
canvas.on_touch_down(move |device_id, location| { |
}); | ||
|
||
let runner = self.runner.clone(); | ||
canvas.on_pointer_up(move |device_id, location| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canvas.on_pointer_up(move |device_id, location| { | |
canvas.on_touch_up(move |device_id, location| { |
}); | ||
|
||
let runner = self.runner.clone(); | ||
canvas.on_pointer_cancel(move |device_id, location| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canvas.on_pointer_cancel(move |device_id, location| { | |
canvas.on_touch_cancel(move |device_id, location| { |
@@ -247,6 +247,46 @@ impl Canvas { | |||
} | |||
} | |||
|
|||
pub fn on_pointer_move<F>(&mut self, handler: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_pointer_move<F>(&mut self, handler: F) | |
pub fn on_touch_move<F>(&mut self, handler: F) |
F: 'static + FnMut(i32, PhysicalPosition<f64>), | ||
{ | ||
match &mut self.mouse_state { | ||
MouseState::HasPointerEvent(h) => h.on_pointer_cancel(&self.common, handler), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MouseState::HasPointerEvent(h) => h.on_pointer_cancel(&self.common, handler), | |
MouseState::HasPointerEvent(h) => h.on_touch_cancel(&self.common, handler), |
@@ -103,11 +111,103 @@ impl PointerHandler { | |||
)); | |||
} | |||
|
|||
pub fn on_pointer_move<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_pointer_move<F>(&mut self, canvas_common: &super::Common, mut handler: F) | |
pub fn on_touch_move<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
)); | ||
} | ||
|
||
pub fn on_pointer_down<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_pointer_down<F>(&mut self, canvas_common: &super::Common, mut handler: F) | |
pub fn on_touch_down<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
)); | ||
} | ||
|
||
pub fn on_pointer_up<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_pointer_up<F>(&mut self, canvas_common: &super::Common, mut handler: F) | |
pub fn on_touch_up<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
)); | ||
} | ||
|
||
pub fn on_pointer_cancel<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_pointer_cancel<F>(&mut self, canvas_common: &super::Common, mut handler: F) | |
pub fn on_touch_cancel<F>(&mut self, canvas_common: &super::Common, mut handler: F) |
I'll be investigating, more, but for some reason when testing with my game it doesn't seem to be picking up tap-and-drags, when inputing through the Chrome browser's mobile viewer. I think maybe it's not holding down the touch or something. I'll debug more in a bit to see what the difference in the the sent events are between my fork and this PR. |
This comment has been minimized.
This comment has been minimized.
This seems to be an oversight on my end. I thought the call to |
Did you try it with |
The problem seems to come from the browser canceling pointermove event. Setting
|
Does it work if you only apply the style to the canvas? If so, we can apply the style programmatically. |
It works on my sample canvas.style().set_property("touch-action", "none");
I tried that, but it does not work. |
That worked for me, too. Looks like that might be all we need. |
Must be added here. |
If I'm not mistaken then the previous message was directed to you, @dsluijk. If you don't have the opportunity to continue working on this, feel free to indicate that. |
It works but the origin (0, 0) is at the top-left corner, with Y going downwards. |
Up please |
Is there something I can do to help this one along? I backported the PR to winit 0.24 (that was what bevy 0.5 was on) and tested it with one of my games, and it worked great. Would be nice to have it merged. @dsluijk, if you don't have the time, I can try to see if I can resolve the conflicts and flip the y-axis. |
#2188 has been merged, which fixes this as well. |
Finally! |
cargo fmt
has been run on this branchcargo doc
builds successfullyCHANGELOG.md
if knowledge of this change could be valuable to usersThis pull request adds touch support to web targets by the Pointer events API.
This PR also adds a new datatype to the Touch struct,
PointerType
. This indicates which pointer is being used to generate the touch event. As this has been added to the platform-independent Touch struct, all platforms supporting touch had to be changed slightly. I manually checked all implementations and added a None value to all (non-web) Touch structs, but it is possible I missed one.Closes #1673 .