From 572024e987df01505d5a91b0b28f803eaaba4c8f Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Thu, 3 Aug 2023 23:04:59 -0400 Subject: [PATCH] fixed website canvas --- Cargo.lock | 1 + examples/bevy_ggrs/src/lib.rs | 1 - website/Cargo.toml | 3 ++- website/Trunk.toml | 2 -- website/src/main.rs | 36 +++++++++++++++-------------------- 5 files changed, 18 insertions(+), 25 deletions(-) delete mode 100644 website/Trunk.toml diff --git a/Cargo.lock b/Cargo.lock index 21b45c6f..6e98f5b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5524,6 +5524,7 @@ version = "0.1.0" dependencies = [ "bevy_ggrs_example", "stylist", + "web-sys", "yew", ] diff --git a/examples/bevy_ggrs/src/lib.rs b/examples/bevy_ggrs/src/lib.rs index 46f2d0ad..f76bcf2c 100644 --- a/examples/bevy_ggrs/src/lib.rs +++ b/examples/bevy_ggrs/src/lib.rs @@ -50,7 +50,6 @@ pub fn run() { .set(WindowPlugin { primary_window: Some(Window { title: "Matchbox Bevy GGRS Example".to_string(), - canvas: Some("#bevy_ggrs_example".to_string()), fit_canvas_to_parent: true, // behave on wasm ..default() }), diff --git a/website/Cargo.toml b/website/Cargo.toml index ffae5a9c..e3fddfab 100644 --- a/website/Cargo.toml +++ b/website/Cargo.toml @@ -14,5 +14,6 @@ readme = "../README.md" [dependencies] bevy_ggrs_example = { path = "../examples/bevy_ggrs" } -stylist = { version = "0.12.1", features = ["yew"] } +stylist = { version = "0.12", features = ["yew"] } yew = { version = "0.20.0", features = ["csr"] } +web-sys = { version = "0.3", features = ["Window", "Event", "EventTarget"] } diff --git a/website/Trunk.toml b/website/Trunk.toml deleted file mode 100644 index 8d8f852d..00000000 --- a/website/Trunk.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "index.html" diff --git a/website/src/main.rs b/website/src/main.rs index e8300db7..f4db74b9 100644 --- a/website/src/main.rs +++ b/website/src/main.rs @@ -1,39 +1,33 @@ use stylist::{global_style, yew::styled_component}; +use web_sys::Event; use yew::{html, Html}; #[styled_component(Root)] fn root() -> Html { global_style!( r#" - html { - min-height: 100%; - position: relative; - } - - body { - height: 100%; + html, body { padding: 0; margin: 0; } + body { + width: 100vw; + height: 100vh; + overflow: hidden; + } "# ) .expect("Unable to mount global style"); - let css = css!( - r#" - position: absolute; - overflow: hidden; - width: 100%; - height: 100%; - "# - ); - - html! { -
- -
+ // Trigger a resize to get the Bevy canvas to resize to fit the frame. + // + // Same as window.dispatchEvent(new Event('resize')); + let window = web_sys::window().unwrap(); + window + .dispatch_event(&Event::new("resize").unwrap()) + .unwrap(); - } + html!() // Render nothing. Bevy handles the rest. } fn main() {