Skip to content

Commit

Permalink
use winit window::canvas() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Jan 10, 2024
1 parent 4c22868 commit f168ae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
9 changes: 1 addition & 8 deletions crates/bevy_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ winit = { version = "0.29", default-features = false, features = [
] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = [
# features used by fit_canvas_to_parent
"CssStyleDeclaration",
"Document",
"HtmlCanvasElement",
"Window",
#
] }
wasm-bindgen = { version = "0.2" }
web-sys = "0.3"
crossbeam-channel = "0.5"

[package.metadata.docs.rs]
Expand Down
23 changes: 7 additions & 16 deletions crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use winit::{
};

#[cfg(target_arch = "wasm32")]
use {wasm_bindgen::JsCast, web_sys::HtmlCanvasElement};
use winit::platform::web::WindowExtWebSys;

use crate::{
accessibility::{AccessKitAdapters, WinitActionHandlers},
Expand Down Expand Up @@ -87,21 +87,12 @@ pub(crate) fn create_windows<'a>(
#[cfg(target_arch = "wasm32")]
{
if window.fit_canvas_to_parent {
if let raw_window_handle::RawWindowHandle::Web(handle) =
winit_window.raw_window_handle()
{
let canvas: HtmlCanvasElement = web_sys::window()
.unwrap()
.document()
.unwrap()
.query_selector(&format!("canvas[data-raw-handle=\"{}\"]", handle.id))
.unwrap()
.unwrap()
.unchecked_into();
let style = canvas.style();
style.set_property("width", "100%").unwrap();
style.set_property("height", "100%").unwrap();
}
let canvas = winit_window
.canvas()
.expect("window.canvas() can only be called in main thread.");
let style = canvas.style();
style.set_property("width", "100%").unwrap();
style.set_property("height", "100%").unwrap();
}
}
event_writer.send(WindowCreated { window: entity });
Expand Down

0 comments on commit f168ae0

Please sign in to comment.