Skip to content

Commit

Permalink
Remove outdated resize code on web demo now that we're on winit 0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Nov 6, 2023
1 parent 05cb678 commit 04a6de3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
27 changes: 5 additions & 22 deletions crates/demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) {

match event {
Event::AboutToWait => {
#[cfg(target_arch = "wasm32")]
{
use winit::dpi::LogicalSize;
use winit::event::WindowEvent;
use winit::window::WindowId;

let web_window = web_sys::window().unwrap();

let event: Event<'_, ()> = Event::WindowEvent {
window_id: unsafe { WindowId::dummy() },
event: WindowEvent::Resized(window.inner_size()),
};

let width = web_window.inner_width().unwrap().as_f64().unwrap();
let height = web_window.inner_height().unwrap().as_f64().unwrap();
window.set_inner_size(LogicalSize::new(width, height));
graphics.handle_event(&mut yak, &event, control_flow);
}

window.request_redraw();
}

Expand All @@ -73,23 +54,25 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
fn main() {
let event_loop = EventLoop::new().unwrap();
let window = winit::window::Window::new(&event_loop).unwrap();

#[cfg(not(target_arch = "wasm32"))]
{
env_logger::init();
// Temporarily avoid srgb formats for the swapchain on the web
pollster::block_on(run(event_loop, window));
}

#[cfg(target_arch = "wasm32")]
{
use winit::platform::web::WindowExtWebSys;

std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init().expect("could not initialize logger");
use winit::platform::web::WindowExtWebSys;
// On wasm, append the canvas to the document body
web_sys::window()
.and_then(|win| win.document())
.and_then(|doc| doc.body())
.and_then(|body| {
body.append_child(&web_sys::Element::from(window.canvas()))
body.append_child(&web_sys::Element::from(window.canvas().unwrap()))
.ok()
})
.expect("couldn't append canvas to document body");
Expand Down
9 changes: 8 additions & 1 deletion crates/yakui-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ pub struct Graphics {

impl Graphics {
pub async fn new(window: &Window) -> Self {
let size = window.inner_size();
let mut size = window.inner_size();

// FIXME: On web, we're receiving (0, 0) as the initial size of the
// window, which makes wgpu upset. If we hit that case, let's just make
// up a size and let it get fixed later.
if size == PhysicalSize::new(0, 0) {
size = PhysicalSize::new(800, 600);
}

let instance = wgpu::Instance::default();
let surface =
Expand Down

0 comments on commit 04a6de3

Please sign in to comment.