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

[JS] Window.js.hx width and height stay the same on window resize #668

Closed
zapparo opened this issue Sep 11, 2019 · 4 comments
Closed

[JS] Window.js.hx width and height stay the same on window resize #668

zapparo opened this issue Sep 11, 2019 · 4 comments

Comments

@zapparo
Copy link

zapparo commented Sep 11, 2019

The width and height stay at the same value as as when first opened int the browser and in turn resize events aren't triggered.

@zapparo
Copy link
Author

zapparo commented Sep 11, 2019

Also this is happening, and it might be related.
If the size of the window is smaller than the scene and resize the window the image remains cropped.

normal

normal_mid

cropped_on_resize

@zapparo
Copy link
Author

zapparo commented Sep 11, 2019

So I've tried something, I was using the index.html from https://heaps.io/documentation/hello-world.html I've also tried the one from the samples (base2d) and this behavior is the normal expected one.

@ncannasse
Copy link
Member

onResize and windows size represents your canvas size, so it needs to be set to 100% to adjust to the browser window.

@andresmakesgames
Copy link

andresmakesgames commented Oct 15, 2023

[Edit] Just going to open a new issue since these are not the exact same.

I'd like to reopen this; setting the canvas width to 100% in the index.html page appears to no longer work on Chrome v118.0.5993.70.
My css on index.html follows the hello world example:

   <style>
        body {
            margin: 0;
            padding: 0;
            background-color: black;
        }

        canvas#webgl {
            width: 100%;
            height: 100%;
        }
    </style>

Using the web inspector I saw my canvas was being automatically assigned a style on the element level,
<canvas id="webgl" tabindex="1" style="outline: none; width: 857px; height: 998px;" width="1071" height="1248"></canvas>

So I dug into the code and found this code in GlDriver.resize():

// prevent infinite grow if pixelRatio != 1
if( canvas.style.width == "" ) {
	canvas.style.width = Std.int(width / js.Browser.window.devicePixelRatio)+"px";
	canvas.style.height = Std.int(height / js.Browser.window.devicePixelRatio)+"px";
}

I can confirm this gets hit and canvas.style.width is an empty string, so my css is now ignored. If I comment out this style change, the canvas is correctly assigned the 100% width from my css. This code is almost a decade old, though; did some other change make it so this canvas.style.width value is now an empty string when it wasn't previously?

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

No branches or pull requests

3 participants