Skip to content

Commit 80f15e0

Browse files
Remove CanvasParentResizePlugin (#11057)
Improves #11052 # Changelog - Remove `Window::fit_canvas_to_parent`, as its resizing on wasm now respects its CSS configuration. ## Migration Guide - Remove uses of `Window::fit_canvas_to_parent` in favor of CSS properties, for example: ```css canvas { width: 100%; height: 100%; } ```
1 parent b27f749 commit 80f15e0

6 files changed

Lines changed: 1 addition & 166 deletions

File tree

crates/bevy_window/src/window.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ pub struct Window {
191191
///
192192
/// This value has no effect on non-web platforms.
193193
pub canvas: Option<String>,
194-
/// Whether or not to fit the canvas element's size to its parent element's size.
195-
///
196-
/// **Warning**: this will not behave as expected for parents that set their size according to the size of their
197-
/// children. This creates a "feedback loop" that will result in the canvas growing on each resize. When using this
198-
/// feature, ensure the parent's size is not affected by its children.
199-
///
200-
/// This value has no effect on non-web platforms.
201-
pub fit_canvas_to_parent: bool,
202194
/// Whether or not to stop events from propagating out of the canvas element
203195
///
204196
/// When `true`, this will prevent common browser hotkeys like F5, F12, Ctrl+R, tab, etc.
@@ -266,7 +258,6 @@ impl Default for Window {
266258
transparent: false,
267259
focused: true,
268260
window_level: Default::default(),
269-
fit_canvas_to_parent: false,
270261
prevent_default_event_handling: true,
271262
canvas: None,
272263
window_theme: None,

crates/bevy_winit/src/lib.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
pub mod accessibility;
1010
mod converters;
1111
mod system;
12-
#[cfg(target_arch = "wasm32")]
13-
mod web_resize;
1412
mod winit_config;
1513
mod winit_windows;
1614

@@ -55,8 +53,6 @@ use winit::{
5553
use crate::accessibility::{AccessKitAdapters, AccessKitPlugin, WinitActionHandlers};
5654

5755
use crate::converters::convert_winit_theme;
58-
#[cfg(target_arch = "wasm32")]
59-
use crate::web_resize::{CanvasParentResizeEventChannel, CanvasParentResizePlugin};
6056

6157
/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
6258
/// (for example lifecycle and input events).
@@ -143,9 +139,6 @@ impl Plugin for WinitPlugin {
143139

144140
app.add_plugins(AccessKitPlugin);
145141

146-
#[cfg(target_arch = "wasm32")]
147-
app.add_plugins(CanvasParentResizePlugin);
148-
149142
let event_loop = event_loop_builder
150143
.build()
151144
.expect("Failed to build event loop");
@@ -181,7 +174,6 @@ impl Plugin for WinitPlugin {
181174
NonSendMut<AccessKitAdapters>,
182175
ResMut<WinitActionHandlers>,
183176
ResMut<AccessibilityRequested>,
184-
ResMut<CanvasParentResizeEventChannel>,
185177
)> = SystemState::from_world(&mut app.world);
186178

187179
#[cfg(not(target_arch = "wasm32"))]
@@ -204,7 +196,6 @@ impl Plugin for WinitPlugin {
204196
adapters,
205197
handlers,
206198
accessibility_requested,
207-
event_channel,
208199
) = create_window_system_state.get_mut(&mut app.world);
209200

210201
create_windows(
@@ -216,8 +207,6 @@ impl Plugin for WinitPlugin {
216207
adapters,
217208
handlers,
218209
accessibility_requested,
219-
#[cfg(target_arch = "wasm32")]
220-
event_channel,
221210
);
222211

223212
create_window_system_state.apply(&mut app.world);
@@ -340,18 +329,6 @@ pub fn winit_runner(mut app: App) {
340329
NonSend<AccessKitAdapters>,
341330
)> = SystemState::new(&mut app.world);
342331

343-
#[cfg(not(target_arch = "wasm32"))]
344-
let mut create_window_system_state: SystemState<(
345-
Commands,
346-
Query<(Entity, &mut Window), Added<Window>>,
347-
EventWriter<WindowCreated>,
348-
NonSendMut<WinitWindows>,
349-
NonSendMut<AccessKitAdapters>,
350-
ResMut<WinitActionHandlers>,
351-
ResMut<AccessibilityRequested>,
352-
)> = SystemState::from_world(&mut app.world);
353-
354-
#[cfg(target_arch = "wasm32")]
355332
let mut create_window_system_state: SystemState<(
356333
Commands,
357334
Query<(Entity, &mut Window), Added<Window>>,
@@ -360,7 +337,6 @@ pub fn winit_runner(mut app: App) {
360337
NonSendMut<AccessKitAdapters>,
361338
ResMut<WinitActionHandlers>,
362339
ResMut<AccessibilityRequested>,
363-
ResMut<CanvasParentResizeEventChannel>,
364340
)> = SystemState::from_world(&mut app.world);
365341

366342
// setup up the event loop
@@ -390,7 +366,6 @@ pub fn winit_runner(mut app: App) {
390366
StartCause::Init => {
391367
#[cfg(any(target_os = "ios", target_os = "macos"))]
392368
{
393-
#[cfg(not(target_arch = "wasm32"))]
394369
let (
395370
commands,
396371
mut windows,
@@ -401,18 +376,6 @@ pub fn winit_runner(mut app: App) {
401376
accessibility_requested,
402377
) = create_window_system_state.get_mut(&mut app.world);
403378

404-
#[cfg(target_arch = "wasm32")]
405-
let (
406-
commands,
407-
mut windows,
408-
event_writer,
409-
winit_windows,
410-
adapters,
411-
handlers,
412-
accessibility_requested,
413-
event_channel,
414-
) = create_window_system_state.get_mut(&mut app.world);
415-
416379
create_windows(
417380
event_loop,
418381
commands,
@@ -422,8 +385,6 @@ pub fn winit_runner(mut app: App) {
422385
adapters,
423386
handlers,
424387
accessibility_requested,
425-
#[cfg(target_arch = "wasm32")]
426-
event_channel,
427388
);
428389

429390
create_window_system_state.apply(&mut app.world);
@@ -842,18 +803,6 @@ pub fn winit_runner(mut app: App) {
842803

843804
// create any new windows
844805
// (even if app did not update, some may have been created by plugin setup)
845-
#[cfg(not(target_arch = "wasm32"))]
846-
let (
847-
commands,
848-
mut windows,
849-
event_writer,
850-
winit_windows,
851-
adapters,
852-
handlers,
853-
accessibility_requested,
854-
) = create_window_system_state.get_mut(&mut app.world);
855-
856-
#[cfg(target_arch = "wasm32")]
857806
let (
858807
commands,
859808
mut windows,
@@ -862,7 +811,6 @@ pub fn winit_runner(mut app: App) {
862811
adapters,
863812
handlers,
864813
accessibility_requested,
865-
event_channel,
866814
) = create_window_system_state.get_mut(&mut app.world);
867815

868816
create_windows(
@@ -874,8 +822,6 @@ pub fn winit_runner(mut app: App) {
874822
adapters,
875823
handlers,
876824
accessibility_requested,
877-
#[cfg(target_arch = "wasm32")]
878-
event_channel,
879825
);
880826

881827
create_window_system_state.apply(&mut app.world);

crates/bevy_winit/src/system.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use winit::{
1919
event_loop::EventLoopWindowTarget,
2020
};
2121

22-
#[cfg(target_arch = "wasm32")]
23-
use crate::web_resize::{CanvasParentResizeEventChannel, WINIT_CANVAS_SELECTOR};
2422
use crate::{
2523
accessibility::{AccessKitAdapters, WinitActionHandlers},
2624
converters::{
@@ -45,7 +43,6 @@ pub(crate) fn create_windows<'a>(
4543
mut adapters: NonSendMut<AccessKitAdapters>,
4644
mut handlers: ResMut<WinitActionHandlers>,
4745
accessibility_requested: ResMut<AccessibilityRequested>,
48-
#[cfg(target_arch = "wasm32")] event_channel: ResMut<CanvasParentResizeEventChannel>,
4946
) {
5047
for (entity, mut window) in created_windows {
5148
if winit_windows.get_window(entity).is_some() {
@@ -84,18 +81,6 @@ pub(crate) fn create_windows<'a>(
8481
window: window.clone(),
8582
});
8683

87-
#[cfg(target_arch = "wasm32")]
88-
{
89-
if window.fit_canvas_to_parent {
90-
let selector = if let Some(selector) = &window.canvas {
91-
selector
92-
} else {
93-
WINIT_CANVAS_SELECTOR
94-
};
95-
event_channel.listen_to_selector(entity, selector);
96-
}
97-
}
98-
9984
event_writer.send(WindowCreated { window: entity });
10085
}
10186
}

crates/bevy_winit/src/web_resize.rs

Lines changed: 0 additions & 83 deletions
This file was deleted.

examples/window/window_settings.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ fn main() {
1616
title: "I am a window!".into(),
1717
resolution: (500., 300.).into(),
1818
present_mode: PresentMode::AutoVsync,
19-
// Tells wasm to resize the window according to the available canvas
20-
fit_canvas_to_parent: true,
2119
// Tells wasm not to override default event handling, like F5, Ctrl+R etc.
2220
prevent_default_event_handling: false,
2321
window_theme: Some(WindowTheme::Dark),

tools/example-showcase/window-settings-wasm.patch

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs
22
index 7b5c75d38..8e9404b93 100644
33
--- a/crates/bevy_window/src/window.rs
44
+++ b/crates/bevy_window/src/window.rs
5-
@@ -245,9 +245,9 @@ impl Default for Window {
5+
@@ -245,8 +245,8 @@ impl Default for Window {
66
transparent: false,
77
focused: true,
88
window_level: Default::default(),
9-
- fit_canvas_to_parent: false,
10-
+ fit_canvas_to_parent: true,
119
prevent_default_event_handling: true,
1210
- canvas: None,
1311
+ canvas: Some("#bevy".to_string()),

0 commit comments

Comments
 (0)