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

[html5]:Cannot get the width and height of the screen when Chrome Zoom Level Not Set to 100% #694

Open
labolado opened this issue Apr 12, 2024 · 0 comments

Comments

@labolado
Copy link

When running a Solar2D HTML5 app in Google Chrome, if the page zoom level is set to a value other than 100%, the program cannot get correctly retrieve the actual width and height of the screen.

Test code:

local topInset, leftInset, bottomInset, rightInset = 0, 0, 0, 0
if (not isHarmonyOS) and (not isAndroidCard) then
	topInset, leftInset, bottomInset, rightInset = display.getSafeAreaInsets()
end
bottomInset = topInset
local maxInset = math.max(leftInset, rightInset)
leftInset = maxInset
rightInset = maxInset

_W      = display.contentWidth              
_H      = display.contentHeight             
_AW     = display.actualContentWidth - (leftInset + rightInset)
_AH     = display.actualContentHeight - (topInset + bottomInset)
_T      = display.screenOriginY + topInset
_B      = _T + _AH
_L      = display.screenOriginX + leftInset
_R      = _L + _AW
_RW     = _R - _L
_RH     = _B - _T
print(string.format(
[[	_RW: %s,
	_RH: %s,
	_L: %s,
	_R: %s,
	_T: %s,
	_B: %s,
	topInset: %s,
	leftInset: %s,
	bottomInset: %s,
	rightInset: %s
]],
_RW,
_RH,
_L,
_R,
_T,
_B,
topInset,
leftInset,
bottomInset,
rightInset
))

When zoom level is 100%, the results are:

	_RW: 2304,
	_RH: 1536,
	_L: -128,
	_R: 2176,
	_T: 0,
	_B: 1536,
	topInset: 0,
	leftInset: 0,
	bottomInset: 0,
	rightInset: 0

When zoom level is not 100%, the results are:

	_RW: nan,
	_RH: nan,
	_L: nan,
	_R: nan,
	_T: nan,
	_B: nan,
	topInset: nan,
	leftInset: nan,
	bottomInset: nan,
	rightInset: nan
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