Incorrect cursor pos when framebuffer_size/window_size
isnt an integer ratio
#3
Labels
bug
Something isn't working
framebuffer_size/window_size
isnt an integer ratio
#3
TL;DR: zgui (Dear ImGui) rounds the ratio between the framebuffer size and the window size up to the next integer when calculating cursor collisions with gui elements, leading to a mismatch of true cursor position and gui collision when the true ratio isn't an integer value.
(This issue may be an upstream issue with Dear ImGui, but I was unsure so I'm adding here first)
I just got the
triangle_wgpu
demo up and running on my machine, Linux (Wayland) 2880x1800 res @ 1.75 screen scaleI immediately noticed zgui not calculating the mouse position correctly for the purposes of determining whether a gui element was hovered. The issue was less noticeable on the left side of the window and more extreme on the right side. I ran some tests and found that due to my Wayland screen scaling factor the mouse position that zgui (Dear ImGui) was reporting was way off.
Using the zgui demo window
mouse pos
and some debug prints I discovered an issue, results below.1.75 Scaled Wayland, mouse top-left
1.75 Scaled Wayland, mouse bot-right
I then tweaked some settings to see if I could get a usable experience, and discovered that when the framebuffer was the same size as the window size, the mouse was exactly correct (at the cost of either an uncomfortably small gui or a blurry framebuffer due to rounding)
1.00 Scaled Wayland (or 1.75 scaled and
zglfw.windowHintTyped(.scale_framebuffer, true);
), mouse bot-rightI tried going up to 2.0 scaling and the issue was also fixed
2.0 Scaled Wayland, mouse bot-right
And finally I went up to 2.5 scaling, expecting the disparity to be in the other direction, but found the exact same problem as before at a larger scale
2.5 Scaled Wayland, mouse bot-right
I then discovered that zgui or Dear ImGui was rounding up the scale factor between the framebuffer size and window size to the next integer, and using THAT scaled mouse position to determine gui collision, making it nearly unusable at any non-integer ratio between framebuffer and window size:
Screenshot: Scale 1.0, mouse bottom right
Screenshot: Scale 1.75, mouse bottom right
Screenshot: Scale 1.75, mouse top left
Screenshot: Scale 1.75, dragging gui left edge near left side of screen
Screenshot: Scale 1.75, dragging gui left edge near right side of screen
The text was updated successfully, but these errors were encountered: