Closed
Description
How can Bevy's documentation be improved?
Simulating user input for use in tests is very important, but it's not always obvious how to do so.
We should document how to do this in two different places:
- The root
tests
directory, as part of an integration test. - In a doc example in each of the input methods.
A user provided the following example for touch input, which should be helpful to get started.
pub fn mock_touch(
mouse: Res<Input<MouseButton>>,
windows: Res<Windows>,
mut touch_events: EventWriter<TouchInput>,
) {
let window = windows.get_primary().unwrap();
let touch_phase = if mouse.just_pressed(MouseButton::Left) {
Some(TouchPhase::Started)
} else if mouse.just_released(MouseButton::Left) {
Some(TouchPhase::Ended)
} else if mouse.pressed(MouseButton::Left) {
Some(TouchPhase::Moved)
} else {
None
};
if let (Some(phase), Some(cursor_pos)) = (touch_phase, window.cursor_position()) {
touch_events.send(TouchInput {
phase: phase,
position: cursor_pos,
force: None,
id: 0,
})
}
```