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] Setting Canvas window width and height to 100% in index.hml css is ignored #1173

Open
andresmakesgames opened this issue Oct 17, 2023 · 0 comments

Comments

@andresmakesgames
Copy link

A follow up to this other issue, which was deemed closed a while back: #668
Setting the canvas width to 100% in the index.html page as noted in that issue 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

1 participant