Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WindowBuilder::with_append() to append canvas #11065

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ impl WinitWindows {
}

winit_window_builder =
winit_window_builder.with_prevent_default(window.prevent_default_event_handling)
winit_window_builder.with_prevent_default(window.prevent_default_event_handling);
winit_window_builder = winit_window_builder.with_append(true);
}

let winit_window = winit_window_builder.build(event_loop).unwrap();
Expand Down Expand Up @@ -189,22 +190,6 @@ impl WinitWindows {
self.entity_to_winit.insert(entity, winit_window.id());
self.winit_to_entity.insert(winit_window.id(), entity);

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

if window.canvas.is_none() {
let canvas = winit_window.canvas().expect("Failed to retrieve canvas.");

let window = web_sys::window().unwrap();
let document = window.document().unwrap();
let body = document.body().unwrap();

body.append_child(&canvas)
.expect("Append canvas to HTML body.");
}
}

self.windows
.entry(winit_window.id())
.insert(winit_window)
Expand Down