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

Web canvas is stuck at fixed size on master #1265

Closed
2 tasks done
jg2562 opened this issue Feb 25, 2022 · 1 comment · Fixed by #2271
Closed
2 tasks done

Web canvas is stuck at fixed size on master #1265

jg2562 opened this issue Feb 25, 2022 · 1 comment · Fixed by #2271
Labels
bug Something isn't working shell web
Milestone

Comments

@jg2562
Copy link

jg2562 commented Feb 25, 2022

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

When building both tour and my own app on master, they now get rendered into a web canvas. However, the web canvas is a fixed size of 1024x768. Oddly, the canvas also doesn't get rendered until the mouse is hovered over it. This also seems to happen when rendered on both windows and linux.

After a discussion with hecjr, I realized this problem is probably on iced rather than iced_web as it uses a canvas. So I moved the issue to here.

What is the expected behavior?

The canvas should be resized to fit the screen.

Version

master

Operative System

Linux

Do you have any log output?

No response

@jg2562 jg2562 added the bug Something isn't working label Feb 25, 2022
@powpingdone
Copy link

powpingdone commented Dec 15, 2022

Some asides I found while diving into this and what I'll document here.

The current system is currently bound by winit's implementation of the window in WASM. Manually resizing the canvas element doesn't work, so using the inner Action::Window(Action::Resize) to do so is needed. The code needed to fire the command is as such:

#[cfg(target_arch = "wasm32")]
{
    use iced_native::{command, window};
    let window = web_sys::window().unwrap();
    let (width, height) = (
        (window.inner_width().unwrap().as_f64().unwrap())
            as u32,
        (window.inner_height().unwrap().as_f64().unwrap())
            as u32,
    );
    Command::single(command::Action::Window(
        window::Action::Resize { width, height },
   ))
},

Note that the body must also have the style:

margin:0px;
overflow:hidden;

The only thing I haven't figured out at this point is getting text inputs to work on mobile (no keyboard pops up) and how to impl a subscription that sends a message on onresize. The TODO example works otherwise.

@hecrj hecrj added this to the 0.12.1 milestone Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shell web
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants