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

Monitor Scaling Factor - text and element too small #6348

Closed
Yasso9 opened this issue Apr 18, 2023 · 8 comments
Closed

Monitor Scaling Factor - text and element too small #6348

Yasso9 opened this issue Apr 18, 2023 · 8 comments

Comments

@Yasso9
Copy link

Yasso9 commented Apr 18, 2023

Version/Branch of Dear ImGui:

Version: 1.89.5
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_SDL2.cpp + imgui_impl_opengl3.cpp
Compiler: g++
Operating System: Linux (Manjaro Gnome)

My Issue/Question:

My ImGui program with SDL and OpenGl doesn't scale like the rest of my application in my computer. I have a 200% scaling factor on my monitor and the imgui program act like I have a 100% scaling factor. I know that I can use a different font size and use the method ScaleAllSize, but after that my program will not scale correctly on a 100% scale monitor.

I have already read this part of the FAQ : https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application
And this issue : #1676
But I don't think that they are linked to my issue (correct me if I'm wrong)

My question is : how are we supposed to handle this scaling factor ? How can we get that factor dynamically to resize all the text and elements ?

Screenshots/Video

100% Monitor Scaling Factor :
Screenshot from 2023-04-18 18-42-55
200% Monitor Scaling Factor :
Screenshot from 2023-04-18 18-42-30

Standalone, minimal, complete and verifiable example:

Reproductible with minimal example example_sdl2_opengl3

@ocornut ocornut added the dpi label Apr 18, 2023
@ocornut
Copy link
Owner

ocornut commented Apr 19, 2023

I know that I can use a different font size and use the method ScaleAllSize, but after that my program will not scale correctly on a 100% scale monitor.

I am not sure I understand your problem.
Why wouldn't it scale properly on a 100% scale monitor, if you apply 1.0 scale (aka no scale) on those?

How can we get that factor dynamically

That's something you get from your OS or SDL/GLFW library. SDL has a SDL_GetDisplayDPI() function.

@Yasso9
Copy link
Author

Yasso9 commented Apr 19, 2023

Why wouldn't it scale properly on a 100% scale monitor, if you apply 1.0 scale (aka no scale) on those?

Sorry for my bad explication. I will try to explain the issue better :
When I run my imgui program with no scale on a 100% scaled monitor -> no problem
When I run my imgui program with no scale on a 200% scaled monitor -> text and element too small
When I run my imgui program with applying ScaleAllSize and resizing font on a 100% scaled monitor -> text and element too big
When I run my imgui program with applying ScaleAllSize and resizing font on a 200% scaled monitor -> no problem

So I must find a way to know about the scale factor of my monitor to apply or not apply ScaleAllSize. Or if you have a better way to handle this I am all hearing.

That's something you get from your OS or SDL/GLFW library. SDL has a SDL_GetDisplayDPI() function.

Thanks for this information, but the SDL_GetDisplayDPI will get the same value if it is on a 100% scaled monitor or 200% (which is normal for me). I unfortunately doesn't found a way to get this information with SDL. However I found that GLFW handle this better and have more functions to know about the current scale of the monitor, so I think I will go for this latter.

Thanks a lot !

@ocornut
Copy link
Owner

ocornut commented Apr 19, 2023

So I must find a way to know about the scale factor of my monitor to apply or not apply ScaleAllSize.

Yes of course you are supposed to scale font size and sizes with actual per-monitor scale, not with a fixed number (but you can also provide this option to the user if you like).

Sounds like your question is a SDL/GLFW question then..

@ocornut ocornut closed this as completed Apr 19, 2023
@ocornut
Copy link
Owner

ocornut commented Apr 19, 2023

Note that in docking branch, the backends are querying and filling this information, which is available in viewport->DpiScale
You can confirm the values in Metrics->Viewport. Can you run the SDL example in your setup and confirm the scales you are getting?

On Windows, the app needs to notify the OS (via a manifest file or a specific function call) that your app can handle DPI scaling otherwise Windows reports "low dpi" and scale itself, so it becomes invisible to the app. I don't think LInux has a same thing in place.

@Yasso9
Copy link
Author

Yasso9 commented Apr 19, 2023

Yeah that's more of a SDL/GLFW Issue you are right, sorry.

For anyone having the same question as me and using the GLFW backend, you can use glfwGetMonitorContentScale or glfwGetWindowContentScale function if you want to know about the current monitor scaling.

Can you run the SDL example in your setup and confirm the scales you are getting?

When I use the docking branch and go into Tools->Metrics/Debugger->Viewport->Monitor I see the correct scale of my monitor, the same values that glfwGetWindowContentScale give me, so 150% for example if I set the scaling factor of my monitor to 150%.

Screenshot from 2023-04-19 16-59-52

However the value is not updated if I change the scaling factor of my monitor when the program is still running. glfw has also this problem, but glfw provide a callback when the monitor scaling change.
When the program is restarted the correct scaling factor is printed

@ocornut
Copy link
Owner

ocornut commented Apr 19, 2023

For anyone having the same question as me and using the GLFW backend, you can use glfwGetMonitorContentScale or glfwGetWindowContentScale function if you want to know about the current monitor scaling.

Note the confusion/subtleties between both, the later is only ever != 1.0f on OSX and we currently don't properly support that in your examples and backends.

When I use the docking branch and go into Tools->Metrics/Debugger->Viewport->Monitor I see the correct scale of my monitor, the same values that glfwGetWindowContentScale give me, so 150% for example if I set the scaling factor of my monitor to 150%.

The code setting that value is in ImGui_ImplSDL2_UpdateMonitors() and does:

        float dpi = 0.0f;
        if (!SDL_GetDisplayDPI(n, &dpi, nullptr, nullptr))
            monitor.DpiScale = dpi / 96.0f;

So I wonder if you had misused SDL_GetDisplayDPI() initially?

Note that SDL needs the SDL_WINDOW_ALLOW_HIGHDPI flag to be passed to SDL_CreateWindow().

However the value is not updated if I change the scaling factor of my monitor when the program is still running. glfw has also this problem, but glfw provide a callback when the monitor scaling change.

That's a bug in the SDL backend, note this comment:

// FIXME-PLATFORM: SDL doesn't have an event to notify the application of display/monitor changes
static void ImGui_ImplSDL2_UpdateMonitors()

I guess since SDL3 is in active development we can ask for this event.

GLFW backend should however support it and not have this bug.

@ocornut
Copy link
Owner

ocornut commented Apr 21, 2023

However the value is not updated if I change the scaling factor of my monitor when the program is still running. glfw has also this problem, but glfw provide a callback when the monitor scaling change.

I noticed that SDL3 added a SDL_EVENT_DISPLAY_SCALE_CHANGED event so added support for it along with others in c111288. I also made changes to SDL2 backend to support monitor connect/disconnect but note it won't update on dpi/scaling change only.

@Yasso9
Copy link
Author

Yasso9 commented Apr 24, 2023

So I wonder if you had misused SDL_GetDisplayDPI() initially?

Note that SDL needs the SDL_WINDOW_ALLOW_HIGHDPI flag to be passed to SDL_CreateWindow().

I was using GLFW on this one, not SDL. I will maybe retry with SDL now that I have more knowledge

GLFW backend should however support it and not have this bug.

On Wayland with a glfw-wayland it update the value dynamically when I change the scaling, but on Wayland with glfw-x11 it doesn't update automatically. But that is an issue with GLFW, not ImGui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants