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

GetWindowDpiScale() result always equals to 1.0 when multi-viewports is disabled #2621

Closed
Alzathar opened this issue Jun 12, 2019 · 4 comments

Comments

@Alzathar
Copy link
Contributor

Version/Branch of Dear ImGui:

Branch: docking (commit 5f409c6)

Back-end/Renderer/Compiler/OS

Back-ends: GLFW 3.3 + sokol engine

My Issue/Question:
My monitor has a DPI scale equals to 1.5. I expected to get this value when using the function ImGui::GetWindowDpiScale(). However, it returns the value 1.0. The problem is because the ImGuiViewportP::PlatformMonitor is never set for the main viewport and uses the default value -1. By setting manually to platform monitor index to 0, I get the good DPI scale.

Is it intentional? In the code, the member ImGuiViewportP::PlatformMonitor is only updated for owned viewports. Would it be possible to have a public (or internal) API to detect the monitor associated with the main viewport?

Some code used to illustrate the problem

// By default all the DPI scales will be equal to 1.0 and the last line is not shown
ImGuiViewportP*viewport = (ImGuiViewportP*)ImGui::GetMainViewport();
ImGui::Text("Window DPI scale: %f", ImGui::GetWindowDpiScale());
ImGui::Text("Viewport DPI scale: %f", viewport->DpiScale);
ImGui::Text("Viewport DPI scale: %f", viewport->DpiScale);
ImGui::Text("Viewport platform monitor: %i", viewport->PlatformMonitor);
if (viewport->PlatformMonitor != -1) {
  ImGui::Text("Viewport platform monitor DPI scale: %f", ImGui::GetCurrentContext()->PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale);
}
@ocornut
Copy link
Owner

ocornut commented Jun 12, 2019

UpdateViewportsNewFrame() calls UpdateViewportPlatformMonitor() for all viewports.

What do you see in Metrics->Viewports?
Because I see non-100% dpi scale there.

image

And if I add ImGui::Text("Window DPI scale: %f", ImGui::GetWindowDpiScale()); to a window in the main viewport I get:

image

You didn't specify the OS. Please note that windows application needs explicit enabling of dpi awareness.

@Alzathar
Copy link
Contributor Author

The OS is Windows 10 x64 and the embedded manifest sets correctly the dpi awareness.

My problem is elsewhere. The ImGuiConfigFlags_ViewportsEnable flag is not set. The application in development has only one viewport and it is not intended to give the possibility to dock/undock windows. The docking branch is used instead of the master branch to simplify the building of the interface thanks to the DockBuilder* functions.

When the ImGuiConfigFlags_ViewportsEnable flag is set, I get the correct DPI scale.

My refined question is do we have to enable the ImGuiConfigFlags_ViewportsEnable flag to get the DPI scale of the main viewport? Looking into the code, this might not be necessary if we change the call of the function UpdateViewportPlatformMonitor(). Currently, this function is called only when the ImGuiConfigFlags_ViewportsEnable flag is enabled (see imgui.cpp:10626). However, we could call this function just after the condition (i.e. line 10628).

I tested this modification and it works (i.e. I got the correct DPI scale for the main viewport without the ImGuiConfigFlags_ViewportsEnable flag).

With this modification the function GetWindowDpiScale() returns the good DPI scale w or w/o the ImGuiConfigFlags_ViewportsEnable flag enabled.

(sorry if my justification is not developed enough, I will develop more if necessary tomorrow.)

@ocornut
Copy link
Owner

ocornut commented Jun 13, 2019

You are right, this should be available and working even if multi-viewports are not enabled.
Will look into the fix.

@ocornut ocornut changed the title GetWindowDpiScale() result always equals to 1.0 for the main viewport GetWindowDpiScale() result always equals to 1.0 when multi-viewports is disabled Jun 17, 2019
ocornut added a commit that referenced this issue Jun 17, 2019
…wports are not enabled. (#2621, #1676) + Tweaks, short path in FindPlatformMonitorForRect().
@ocornut
Copy link
Owner

ocornut commented Jun 17, 2019

This should be fixed now, thanks for reporting the issue!

@ocornut ocornut closed this as completed Jun 17, 2019
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