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

Flag to not change canvas CSS on scale factor change #3023

Closed
OptimisticPeach opened this issue Aug 13, 2023 · 4 comments
Closed

Flag to not change canvas CSS on scale factor change #3023

OptimisticPeach opened this issue Aug 13, 2023 · 4 comments
Labels

Comments

@OptimisticPeach
Copy link

I have my canvas's size change automatically using css with a width: 100%; height: 100% style that's applied to the canvas on creation.

I then watch for changes to the canvas's actual size with a ResizeObserver, quite similar to what's done here: https://github.com/BVE-Reborn/rend3/blob/trunk/rend3-framework/src/resize_observer.rs

However, when dpi gets changed, winit will change the styling of the canvas element to no longer be my width: 100%; height: 100%.

I mitigate this using the following code placed in my handler for a winit size changed event:

#[cfg(target_arch = "wasm32")]
{
    use winit::platform::web::WindowExtWebSys;
    let canvas = window.canvas();
    let style = canvas.style();
    // reset styling
    style.set_property("width", "100%").unwrap();
    style.set_property("height", "100%").unwrap();
}

(Included for anyone reading this facing the same issue)
(This needs to go in a resize event, not a scale factor changed event, since winit changes the canvas style after I handle that event, but before I handle the resize event)

However, this is clearly a hack, and I am wondering if there's an existing method to do this correctly, and if not, this issue can be interpreted as a request for such a method.

@kchibisov
Copy link
Member

Which winit version have you used? Have you tried recent master?

@OptimisticPeach
Copy link
Author

To check recent master, I cloned and patched with that -- and got dozens of errors.

I'll figure those out tomorrow and after I've finished my current commit.

@daxpedda
Copy link
Member

This has already been done in #2859. If you don't change the new_size variable in ScaleFactorChanged the canvas CSS won't be touched.

@daxpedda
Copy link
Member

Sorry, that was wrong, it was fixed here: #2860.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants