g3n/engine

MacOS with Retina: UI clickable area is calculated incorrectly

dant3 opened this issue · 6 comments

dant3 commented

Most likely bug is caused by incorrect calculation of UI element position due to Retina. See video for a reproduction. I used an example code from the readme.md

Screen.Recording.2022-08-09.at.19.41.23.mov

Hi and thanks for the video! Unfortunately I don't have a MacOS device and can't reproduce/debug/fix. The relevant code is probably in gui/panel.go in the SetModelMatrix function if you (or anyone else with a MacOS device) would like to have a stab at fixing it. You might also want to add the window hint mentioned in #161 (comment) and it might be helpful to look through that PR and the ones linked there.

I am able to reproduce this issue on a MacBook Pro M1.

How to put this in html?

tomekc commented

Hi, I come late to the party and took a moment to apply #161 tu current master, and it brings some improvement: the button is now clickable, but apparently incorrectly scaled (2x) with regards to size and position I guess.

I also am experiencing a strange glitch where initially the 3D scene takes only lower left quadrant of the window. It gets right after simply moving a window (!).

Screenshot 2023-04-07 at 02 25 37

And after moving a window button is clickable:

Screenshot 2023-04-07 at 02 25 55

EDIT

Glitch resolved by fixing onResize handler:

		scaleX, scaleY := a.GetScale()
		width, height := a.GetSize()
		a.Gls().Viewport(0, 0, int32(float32(width)*scaleX), int32(float32(height)*scaleY))

Now the UI is rendered properly, but mouse coordinates read improperly (need to move to coordinates 2x position of the button to click). Probably resolved by simple fix of the mouse coordinate reading?

Screenshot 2023-04-07 at 02 40 49

Hi @tomekc , your solution works for me. The cursor position does not have the 2x error but have 2 pixels offset on my computer.
Also, the actual code fixed for me is:

r.Gls().Viewport(0, 0, (int32)((float64)(w)*scaleX), (int32)((float64)(h)*scaleY))

which scaleX/Y is float64