AllenDang / giu

Cross platform rapid GUI framework for golang based on Dear ImGui.
MIT License
2.34k stars 133 forks source link

[bug] MasterWindow.GetSize() is wrong on Linux when text scaling is not 1.0 #489

Open rasteric opened 2 years ago

rasteric commented 2 years ago

What happend?

When I make a MasterWindow with width 1024 and height 800, after creating the window MasterWindow.GetSize() returns width 1228 and height 959. The actual size is 1024, 800 however, since in my code the sizes are saved and loaded as preferences and the window grows every time the application is started. Minimal sample included below. Tested on Linux Mint 20.

Code example

main.go ```golang package main import ( "log" g "github.com/AllenDang/giu" ) func loop() { } var mainWin *g.MasterWindow func main() { mainWin = g.NewMasterWindow("Hello world!", 1024, 800, 0) w, h := mainWin.GetSize() log.Printf("Reported size width==%v, height==%v\n", w, h) mainWin.Run(loop) } ```

To Reproduce

  1. Run my demo from a console
  2. Check the reported size. On my Linux system it is width==1228, height==959.

Version

master

OS

Linux Mint 20.3 Cinnamom

gucio321 commented 2 years ago

I cannot reproduce that behaviour: image

my os is Fedora 35; gnome-shell 41.4 here are my display settings (if it could help anyone)

settings ![image](https://user-images.githubusercontent.com/73652197/160628930-b7451679-10ba-4b4b-8b63-0cb880f59511.png)
rasteric commented 2 years ago

Must be a platform issue then. It's 100% reproducible on my Linux Mint 20 Cinnamon, which is based on Ubuntu 20.04. I'm currently using the nouveau drivers. Here is some raw system info:

System: Kernel: 5.4.0-105-generic x86_64 bits: 64 compiler: gcc v: 9.4.0 Desktop: Cinnamon 5.2.7 wm: muffin dm: LightDM Distro: Linux Mint 20.3 Una base: Ubuntu 20.04 focal Machine: Type: Desktop Mobo: Micro-Star model: B350 TOMAHAWK (MS-7A34) v: 1.0 serial: UEFI: American Megatrends v: 1.M0 date: 01/23/2019 CPU: Topology: 8-Core model: AMD Ryzen 7 1800X bits: 64 type: MT MCP arch: Zen rev: 1 L2 cache: 4096 KiB flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 115184 Speed: 3754 MHz min/max: 2200/3600 MHz Core speeds (MHz): 1: 3730 2: 3733 3: 1846 4: 1854 5: 3197 6: 2658 7: 1828 8: 1828 9: 1849 10: 1850 11: 1850 12: 1850 13: 1802 14: 1849 15: 1827 16: 1828 Graphics: Device-1: NVIDIA GP104 [GeForce GTX 1080] driver: nouveau v: kernel bus ID: 1c:00.0 chip ID: 10de:1b80 Display: x11 server: X.Org 1.20.13 driver: modesetting unloaded: fbdev,vesa tty: N/A OpenGL: renderer: NV134 v: 4.3 Mesa 22.1.0-devel (git-36373e8 2022-03-23 focal-oibaf-ppa) direct render: Yes Audio: Device-1: NVIDIA GP104 High Definition Audio driver: snd_hda_intel v: kernel bus ID: 1c:00.1 chip ID: 10de:10f0 Device-2: Microdia type: USB driver: snd-usb-audio,uvcvideo bus ID: 3-3.2:3 chip ID: 0c45:6537 Device-3: Yamaha Steinberg UR22 type: USB driver: snd-usb-audio bus ID: 1-9:5 chip ID: 0499:1509 Device-4: N/A type: USB driver: snd-usb-audio bus ID: 1-8.1.1:8 chip ID: 1c75:0204 Sound Server: ALSA v: k5.4.0-105-generic Network: Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: Micro-Star MSI driver: r8169 v: kernel port: f000 bus ID: 19:00.0 chip ID: 10ec:8168 IF: enp25s0 state: up speed: 1000 Mbps duplex: full mac: Drives: Local Storage: total: 5.71 TiB used: 3.93 TiB (68.8%) ID-1: /dev/sda type: USB vendor: Seagate model: BUP Slim SL size: 1.82 TiB serial: ID-2: /dev/sdb vendor: Crucial model: CT275MX300SSD1 size: 256.17 GiB speed: 6.0 Gb/s serial: ID-3: /dev/sdc vendor: Western Digital model: WD40EFRX-68N32N0 size: 3.64 TiB speed: 6.0 Gb/s serial: Partition: ID-1: / size: 91.64 GiB used: 67.79 GiB (74.0%) fs: ext4 dev: /dev/sdb6 ID-2: /home size: 1.05 TiB used: 431.80 GiB (40.1%) fs: ext4 dev: /dev/sdc3 Sensors: System Temperatures: cpu: 51.0 C mobo: N/A gpu: nouveau temp: 40 C Fan Speeds (RPM): N/A gpu: nouveau fan: 838 Repos: No active apt repos in: /etc/apt/sources.list No active apt repos in: /etc/apt/sources.list.d/christian-boxdoerfer-fsearch-daily-focal.list No active apt repos in: /etc/apt/sources.list.d/damentz-liquorix-focal.list Active apt repos in: /etc/apt/sources.list.d/git-core-ppa-focal.list 1: deb http: //ppa.launchpad.net/git-core/ppa/ubuntu focal main No active apt repos in: /etc/apt/sources.list.d/graphics-drivers-ppa-focal.list Active apt repos in: /etc/apt/sources.list.d/librewolf.list 1: deb [arch=amd64] http: //deb.librewolf.net una main Active apt repos in: /etc/apt/sources.list.d/megasync.list 1: deb https: //mega.nz/linux/repo/xUbuntu_20.04/ ./ Active apt repos in: /etc/apt/sources.list.d/official-package-repositories.list 1: deb http: //packages.linuxmint.com una main upstream import backport #id:linuxmint_main 2: deb http: //archive.ubuntu.com/ubuntu focal main restricted universe multiverse 3: deb http: //archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse 4: deb http: //archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse 5: deb http: //security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse 6: deb http: //archive.canonical.com/ubuntu/ focal partner Active apt repos in: /etc/apt/sources.list.d/oibaf-graphics-drivers-focal.list 1: deb http: //ppa.launchpad.net/oibaf/graphics-drivers/ubuntu focal main Active apt repos in: /etc/apt/sources.list.d/recoll-backports-recoll-1_15-on-focal.list 1: deb http: //ppa.launchpad.net/recoll-backports/recoll-1.15-on/ubuntu focal main Active apt repos in: /etc/apt/sources.list.d/virtualbox.list 1: deb [arch=amd64] http: //download.virtualbox.org/virtualbox/debian focal contrib Active apt repos in: /etc/apt/sources.list.d/x2go-stable-focal.list 1: deb http: //ppa.launchpad.net/x2go/stable/ubuntu focal main Info: Processes: 370 Uptime: 6h 12m Memory: 31.37 GiB used: 10.00 GiB (31.9%) Init: systemd v: 245 runlevel: 5 Compilers: gcc: 9.4.0 alt: 10/5/6/7/8/9 Client: Unknown python3.8 client inxi: 3.0.38

GiuBugScreenshot

rasteric commented 2 years ago

Some more info: GiuBug2 GiuBug3

Could it be the text scaling factor of 1.2? I'll test and report back.

rasteric commented 2 years ago

It's the text scaling factor. If I set it to 1.0 the window size is as requested. How do I take this into account when saving and loading the window size? Is there a way to access the scaling factor and/or should this be fixed in Giu?

gucio321 commented 2 years ago

I suppose it is something about glfw as window sizes are handled by it However I'm not 100% sure, I could be something related with giu DPI scaling or so... CC @AllenDang

gucio321 commented 3 months ago

this issue has about 2 years now, and since this time we've changed much. Especially We've updated to cimgui-go. Could someone check if this still is a problem on v0.8.1?