micro_bevy_web_utils

Crates.iomicro_bevy_web_utils
lib.rsmicro_bevy_web_utils
version0.4.0
sourcesrc
created_at2022-12-22 21:57:15.317635
updated_at2024-02-25 00:30:59.664269
descriptionUtilities for patching various missing parts from Bevy web/touch support
homepagehttps://lab.lcr.gr/microhacks/bevy-web-utils
repositoryhttps://lab.lcr.gr/microhacks/bevy-web-utils.git
max_upload_size
id744138
size20,313
Louis Capitanchik (Commander-lol)

documentation

README

Bevy Web Utils

Helpers for working with Bevy on the web

Bindings

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 input

Bevy System

Touch 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

Commit count: 0

cargo fmt