-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
Wrong viewport on web+mobile #338
Comments
Yeah, I think so. Any help with this is much appreciated, I basically just need a way to get the correct viewport (without the browser header) from the web API, the rest is simple. |
Hi again, sorry i dont come with a solution, just some observations i just did:
let k = 10.;
html_canvas.set_width((k * browser_inner_width) as u32);
html_canvas.set_height((k * browser_inner_height) as u32); Also I'm a bit surprised by the canvas size. log::warn!(
"browser inner width/height: {} --- {}",
browser_window.inner_width().unwrap().as_f64().unwrap(),
browser_window.inner_height().unwrap().as_f64().unwrap()
);
log::warn!(
"canvas width/height: {} xxx {}",
html_canvas.width(),
html_canvas.height()
); gives the log (in pc browser)
is it normal that they are not in the same "unit"? it seems that the inner values are logical pixel but canvas physical (factor 2 between the 2) but the function |
So going to the original live demo on mobile, and halving my screen size by 2 with the split screen phone feature, actually the example works (ratio + accurate touching) You can see in the upper half of the image the the correct view. I dont know where to go from this ? any idea? |
so i went on with this : browser inner size == canvas size. |
after Xmas I can open a PR for this so some more knowledgeable people could review this, as usability/fidelity on mobile web could be a nice to have for some projects. |
Thank you so much for looking into this @huand 🙏 I've spend a lot of time on these kind of problems, especially when I handled the canvas myself. A year ago or something, I realized that winit started supporting web so I removed my own code and started using that. I since realized that winit web support is not very good 😕 so it is possible that this is a bug in winit. However, I think it's something else. To make the canvas cover the entire document I set the CSS margins to zero in index.html. That might be the issue since that will make the canvas be underneath the header as well? And the width and height that we retrieve to set the viewport is without that header and then the canvas width height is different from the screen viewport and we get the problem? About canvas physical size, if the dpr is 2, the canvas size needs to be twice as big as the canvas logical size in the document, otherwise we'll get a pixelated result. It is very confusing, took me a long time to understand that. The split screen experiment might be better than without split screen but it is still wrong. The green line doesn't hit the corner exactly. I'll be very happy to review a PR, though I'm not sure I'm more knowledgeable than you 😄 just so you know, I'm perfectly ok with a hack if that's what it takes, just as long as it doesn't add a lot of code. |
For info, I saw in winit changelog a lot of changes lately. Maybe there is some stuff related to this issue? It might be worth it to try to upgrade this dependency? |
Open this example in a browser on mobile and see that the green line is not going from top left corner to bottom right corner of the browser viewport.
The problem is that
Window::innerWidth()
used here includes the browser header and similar. Same for height. It's only a problem on mobile though. It seems like visualViewport might be correct, but that's not exposed by theweb_sys
crate.The text was updated successfully, but these errors were encountered: