-
I'm trying to set a initial size for the window, but let window = WindowBuilder::new()
.with_title("Example")
.with_inner_size(PhysicalSize::new(100, 100))
.with_append(true)
.build(&event_loop)
.unwrap();
let size = window.inner_size(); // return (0, 0)
info!("{} {}", size.width, size.height)
web_sys::window()
.and_then(|win| win.document())
.and_then(|doc| {
let canvas = window.canvas().unwrap();
let body = doc.body().unwrap();
let body_style = &body.style();
body_style.set_property("height", "100vh");
let style = &canvas.style();
style.set_property("display", "block");
style.set_property("width", "100%");
style.set_property("height", "100%");
canvas.set_width(canvas.offset_width() as u32);
canvas.set_height(canvas.offset_height() as u32);
let body = doc.body().unwrap();
body.append_child(&canvas).ok()?;
Some(())
})
.expect("Could't initialize!"); The window only gets its values after the WindowEvent::Resized(physical_size) => state.resize(*physical_size), But I need the window size before the Resized event in order to configure the wgpu. let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface_format,
width: size.width,
height: size.height,
present_mode: surface_caps.present_modes[0],
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![]
};
|
Beta Was this translation helpful? Give feedback.
Answered by
daxpedda
Dec 14, 2023
Replies: 1 comment 2 replies
-
See #2863. Unfortunately this is not possible, as we use |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
devrangel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See #2863.
Unfortunately this is not possible, as we use
ResizeObserver
to figure out the size of the canvas, which is async by nature. This is unfortunately a limitation by the Web API.