Spawn Bevy canvas at full viewport size

This commit is contained in:
Danny McGee
2023-09-29 20:36:23 -04:00
parent bed97cff47
commit c1f92cc2d6
6 changed files with 64 additions and 429 deletions
+13 -6
View File
@@ -1,24 +1,31 @@
#![allow(clippy::type_complexity)]
use bevy::prelude::*;
use orbit_cam::{OrbitCam, OrbitCamPlugin};
use test_scene::TestScenePlugin;
use ui::UiLayerPlugin;
use viewport::ViewportSize;
use wasm_bindgen::prelude::*;
mod orbit_cam;
mod test_scene;
mod ui;
use orbit_cam::{OrbitCam, OrbitCamPlugin};
use test_scene::TestScenePlugin;
use ui::UiLayerPlugin;
mod viewport;
#[wasm_bindgen]
pub fn init() {
pub fn init(viewport_size: ViewportSize) {
#[cfg(target_arch = "wasm32")]
console_error_panic_hook::set_once();
App::new()
.add_plugins((
DefaultPlugins,
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: viewport_size.into(),
..default()
}),
..default()
}),
OrbitCamPlugin,
TestScenePlugin,
UiLayerPlugin,
+1 -1
View File
@@ -1,3 +1,3 @@
fn main() {
studio::init();
studio::init(Default::default());
}
+37
View File
@@ -0,0 +1,37 @@
use bevy::window::WindowResolution;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct ViewportSize {
pub width: f32,
pub height: f32,
}
#[wasm_bindgen]
impl ViewportSize {
#[wasm_bindgen(constructor)]
pub fn new(width: f32, height: f32) -> Self {
Self { width, height }
}
}
impl Default for ViewportSize {
fn default() -> Self {
WindowResolution::default().into()
}
}
impl From<ViewportSize> for WindowResolution {
fn from(value: ViewportSize) -> Self {
Self::new(value.width, value.height)
}
}
impl From<WindowResolution> for ViewportSize {
fn from(value: WindowResolution) -> Self {
Self {
width: value.width(),
height: value.height(),
}
}
}