engine icon indicating copy to clipboard operation
engine copied to clipboard

MacOS with Retina: UI clickable area is calculated incorrectly

Open dant3 opened this issue 2 years ago • 6 comments

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

https://user-images.githubusercontent.com/820057/183709276-7f04556c-5cc8-4ad5-b405-e5fde9a16b60.mov

dant3 avatar Aug 09 '22 16:08 dant3

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 https://github.com/g3n/engine/pull/161#issuecomment-1159476963 and it might be helpful to look through that PR and the ones linked there.

danaugrs avatar Aug 10 '22 14:08 danaugrs

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

berkeleynerd avatar Aug 16 '22 15:08 berkeleynerd

How to put this in html?

TheRealDigitalMaster avatar Sep 01 '22 19:09 TheRealDigitalMaster

@TheRealDigitalMaster please see https://github.com/g3n/engine/issues/282#issuecomment-1235806125.

danaugrs avatar Sep 02 '22 18:09 danaugrs

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

tomekc avatar Apr 07 '23 00:04 tomekc

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

zyxkad avatar Dec 02 '23 14:12 zyxkad