| Crates.io | micro_bevy_web_utils |
| lib.rs | micro_bevy_web_utils |
| version | 0.4.0 |
| created_at | 2022-12-22 21:57:15.317635+00 |
| updated_at | 2024-02-25 00:30:59.664269+00 |
| description | Utilities for patching various missing parts from Bevy web/touch support |
| homepage | https://lab.lcr.gr/microhacks/bevy-web-utils |
| repository | https://lab.lcr.gr/microhacks/bevy-web-utils.git |
| max_upload_size | |
| id | 744138 |
| size | 20,313 |
Helpers for working with Bevy on the web
This crate includes wasm_bindgen bindings to some JS snippets that help with various
web tasks, that can be accessed from the micro_bevy_web_utils::bindings module
orientation_lock(orientation: String);: Locks the screen to the given orientation. Accepts values defined in the Screen Orientation API. Noop on web platforms that do not support locking orientation orientation_unlock();: Unlocks the screen orientation. Noop when the orientation is not locked, or on web platforms that do not support locking orientation make_selector_fullscreen(selector: String);: Take a query selector, and requests fullscreen mode for the first matching element. Noop if the query selector does not match any elements. Calling make_selector_fullscreen("canvas") is the common usage toggle_selector_fullscreen(selector: String) -> bool;: Take a query selector and either request fullscreen mode if the window is not in fullscreen, or close fullscreen mode if the window is fullscreen exit_fullscreen();: Close fullscreen mode bind_selector_touch_events(selector: String);: Bind touch events to the element. This is used in combination with the micro_bevy_web_utils::bevy::emit_touch_events system to send touch events on touch devices teardown_selector_touch_events(selector: String);: Remove touch event bindings for a given element take_touch_events() -> String;: Clears the touch event buffer and returns a serialised JSON array containing all of the events that have been recorded since the last call to take_touch_events is_fullscreen() -> bool;: Returns whether an element has fullscreen mode enabled is_touch_device() -> bool;: Returns whether the device supports touch inputTouch events will only be intercepted after at least one successful call to bind_selector_touch_events
To dispatch touch events recorded by this library, you can add the micro_bevy_web_utils::bevy::emit_touch_events system. You will then receive
intercepted touch events in any other system that uses the Touches or EventReader<TouchInput> resources.
Alternatively, you can manually use the take_touch_events binding to get all the recorded touch events. They must be handled and/or dispatched after being
taken, or they will be lost - there is no double buffering or equivalent