-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Winit 0.29 follow up #11052
Comments
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%; } ```
This has been addressed in Winit v0.29.4.
See #10702 (comment). EDIT: This part of the code will go away in #11065. One thing I believe was overlooked is the missing documentation on setting a CSS size on the canvas. This will become a major footgun for any deployments targeting any platform with a scale factor that's not FWIW: |
# Objective Replace the canvas appending code with a simpler version provided by Winit v0.29. Related: #11052. ## Solution Use [`WindowBuilder::with_append()`](https://docs.rs/winit/0.29.5/wasm32-unknown-unknown/winit/platform/web/trait.WindowBuilderExtWebSys.html#tymethod.with_append).
Could that property be bought back for setting the CSS? Right now, the canvas seems to still get an inline style with width/height (and max-/min-) set, so you also need to use Another thing that seems to have went unnoticed is that canvas elements default to Either way, I do agree it should be at least documented if not added. |
I didn't review #10702, but looking at it now there is at least one big problem: EDIT: I looked into it a bit further, and as far as I can see Bevy has some system in place to update based on The only meaning ascribed to it should be that there are currently no further events. It is recommended to draw either based on your own timings (maybe in combination with If Bevy wants to also update exactly as fast as it draws, then it can do the update in My assumption is that this is the culprit behind #11122 and rust-windowing/winit#1418 (which is linked by a bunch of Bevy issues). Please feel free to tag me at any Winit related issues/PRs, I'm happy to chime in or review them. |
@daxpedda @rniii Not having
Not sure if this is alluding to scale factor / aspect ratio for mobile resolution vs viewport? Are there any issues with reverting back this change until something better is possible? Fwiw |
web-sys = { version = "0.3", features = [
"CssStyleDeclaration",
"Document",
"HtmlCanvasElement",
"Window",
] } fn fit_canvas_to_parent(windows: Query<&Window, With<PrimaryWindow>>) {
let window = windows.single();
let canvas: HtmlCanvasElement = web_sys::window()
.unwrap()
.document()
.unwrap()
.query_selector(window.canvas().unwrap())
.unwrap()
.unwrap();
let style = canvas.style();
style.set_property("width", "100%").unwrap();
style.set_property("height", "100%").unwrap();
} This should do the trick, please let me know if this doesn't work out for you. |
@daxpedda
Changing HtmlCanvasElement to Element causes this error: This is my web-sys dep: [dependencies.web-sys]
version = "0.3"
features = [
"CssStyleDeclaration",
"Document",
"HtmlCanvasElement",
"Clipboard",
"Window",
"Navigator",
"Permissions",
] |
So I actually tried out my suggestion and fixed it up in #11052 (comment). So this is what I tried and I can confirm it works: use web_sys::HtmlCanvasElement;
use wasm_bindgen::JsCast;
fn fit_canvas_to_parent() {
let canvas: HtmlCanvasElement = web_sys::window()
.unwrap()
.document()
.unwrap()
.query_selector("canvas")
.unwrap()
.unwrap()
.unchecked_into();
let style = canvas.style();
style.set_property("width", "100%").unwrap();
style.set_property("height", "100%").unwrap();
} also add the following to your .add_systems(Startup, fit_canvas_to_parent) |
@daxpedda Things seem to be much better doing this. On mobile though the cursor/touch position and where the mouse/touch is.. is off while running off main.. and gets worse the further from top left of the screen i go. Any ideas here? Possibly unrelated but thought i should check. view port in my metadata is: I'm guessing this is a viewport issue scale issue not resizing for mobile now for some reason. I'm assuming the |
What browser and OS are you using? This might be a Winit bug, but we supposedly fixed that a long while ago.
I don't think so, but maybe Bevy was adjusting these positions somewhere to fix the old bug in Winit? |
tested on a bunch devicePixelRatio on old build with bevy 12.1 and new build with main. On new build given the following config I've setup with you, only window.devicePixelRatio resulting in |
Another near duplicate: #11320. |
Following up on #11227 (comment): bevy/crates/bevy_render/src/renderer/mod.rs Lines 74 to 77 in 83d6600
gfx-rs/wgpu#5093 seems to now clarify whats going on here, so Window::pre_present_notify() should be called here.
|
Add logical key data to KeyboardInput Addresses an item of #11052 --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
Add logical key data to KeyboardInput Addresses an item of bevyengine/bevy#11052 --------- Co-authored-by: Mateusz Wachowiak <[email protected]>
PSA: Removing the instant dependency seems to trigger the following error (in the browsers web console) if you happen to have instant somewhere else in your dependency tree:
This happens because bevy previously enabled the A workaround for this issue is to add the instant crate to your application with the |
@daxpedda thanks for this, it saved me since the information is not present in the migration guide: https://bevyengine.org/learn/migration-guides/0-12-to-0-13/#remove-canvasparentresizeplugin |
@Vrixyz I merged your MR on top of the 0.13 release and replace the manual fit_canvas_to_parent system with the |
I'm really interested to know how you discovered this. I found your comment and thank gosh I did! Is this being tracked anywhere? |
I just got lucky googling the error and found: Then double checked my Cargo.lock file and Bevy's dependencies 😅 |
Marking as closed, but we should open individual issues for any remaining problems here. |
A few shortcuts were taken in #10702 in order to merge it in a reasonable amount of time.
This issue serves to :
Feel free to create or ask a dedicated issue for any listed task, if you feel like it's worth it.
Known regressions (important follow ups?)
UpdateMode::Reactive
is brokenAlt
on Windows discards key information rust-windowing/winit#2945window.request_redraw();
fromAboutToWait
, and handle actual redrawing withinRedrawRequested
. I'm not sure how to move all that code so I'd appreciate it to be a follow up.Follow up
I'd like to avoid bloating this PR, here are a few follow up tasks worthy of a separate PR, or new issue to track them once this PR is closed, as they would either complicate reviews, or at risk of being controversial:
CanvasParentResizePlugin
(Update winit dependency to 0.29 #10702 (comment))CanvasParentResizePlugin
Remove CanvasParentResizePlugin #11057NamedKey
integration on bevy_input: Revise Key, KeyCode enums rust-windowing/winit#3143 introduced a new NamedKey variant. I implemented it only on the converters but we'd benefit making the same changes to bevy_input.KeyboardInput
Update winit dependency to 0.29 #10702 (review)RenameKeyCode
toPhysicalKeyCode
Update winit dependency to 0.29 #10702 (comment)dropped: RenameKeyCode
toPhysicalKey
#11692instant
dependency, replaced byweb_time
), we'd need to update to fastrand >= 2.0.winit_window.canvas().unwrap();
)WindowBuilder::with_append()
to append canvas #11065pre_present_notify
Winit 0.29 follow up #11052 (comment)WindowEvent::Occluded
into account #11229The text was updated successfully, but these errors were encountered: