mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Add gamepad support for stdweb and web-sys, as well as web-specific gamepad examples. * [web] Fix compilation error from device api * [wasm] Apply device api changes * [wasm] Format and cleanup * [wasm32] Implement gamepad connections * [wasm] Harmonize * [Test] Made some tests with wasm-pack * Quick fix instant non supporting Hash trait * Fix on_received_character * [web_sys] Split add_event and add_window_event * [web] split device implementations * Update tests/web...still does not work * [tests/web] do not ignore index.html * [web/web_sys] split canvas and window * [tests/web] enable stack trace * [web] fix borrowmut * [web_sys] fix gamepad registration * [web] harmonize naming * [web_sys] create global emitter * [web] implement gamepad buttons * [web] implement gamepad axis * [web] cleanup * [web] update test * [web] move tests/web to examples/web * [web] axis does produce stick event * [web] Support Stick event * [web] implement gamepad to stdweb * [web] rename examples/web to examples/wasm * [web/web-sys] Move gamepad_manager from backend * [web/web_sys] implement EventLoop::gamepads * [web/web_sys] Drain gamepad events * [web/stdweb] apply web_sys changes * [web] update web/examples * [web] move gamepads code to gamepad_manager * [web] simplify and optimise * [web] replace EventCode to GamepadAxis and GamepadButton structs * [web] reuse gamepad events due to chrome issue * [web] rumble does not work * [web/stdweb] try debugging * [web] fix Chrome gamepad not updated * [web/stdweb] created an example * [examples] fix paths * fix warnings * [web/examples] update comments * [web/stdweb] add experimental support to vibrate() * [web] add CR
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
mod canvas;
|
|
pub mod gamepad;
|
|
mod timeout;
|
|
mod utils;
|
|
pub mod window;
|
|
|
|
pub use self::canvas::Canvas;
|
|
pub use self::timeout::Timeout;
|
|
|
|
use crate::dpi::LogicalSize;
|
|
use crate::platform::web::WindowExtStdweb;
|
|
use crate::window::Window;
|
|
|
|
use stdweb::js;
|
|
use stdweb::web::event::BeforeUnloadEvent;
|
|
use stdweb::web::window;
|
|
use stdweb::web::IEventTarget;
|
|
use stdweb::web::{document, html_element::CanvasElement, Element};
|
|
|
|
pub fn throw(msg: &str) {
|
|
js! { throw @{msg} }
|
|
}
|
|
|
|
pub fn exit_fullscreen() {
|
|
document().exit_fullscreen();
|
|
}
|
|
|
|
pub fn on_unload(mut handler: impl FnMut() + 'static) {
|
|
window().add_event_listener(move |_: BeforeUnloadEvent| handler());
|
|
}
|
|
|
|
impl WindowExtStdweb for Window {
|
|
fn canvas(&self) -> CanvasElement {
|
|
self.window.canvas().raw().clone()
|
|
}
|
|
}
|
|
|
|
pub fn window_size() -> LogicalSize {
|
|
let window = window();
|
|
let width = window.inner_width() as f64;
|
|
let height = window.inner_height() as f64;
|
|
|
|
LogicalSize { width, height }
|
|
}
|
|
|
|
pub fn is_fullscreen(canvas: &CanvasElement) -> bool {
|
|
match document().fullscreen_element() {
|
|
Some(elem) => {
|
|
let raw: Element = canvas.clone().into();
|
|
raw == elem
|
|
}
|
|
None => false,
|
|
}
|
|
}
|
|
|
|
pub fn get_gamepads() -> impl Iterator<Item = gamepad::Gamepad> {
|
|
stdweb::web::Gamepad::get_all()
|
|
.into_iter()
|
|
.filter_map(|gamepad| gamepad.map(|gamepad| gamepad::Gamepad::new(gamepad)))
|
|
}
|