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

Per-monitor DPI scaling #448

Open
Wouterdek opened this issue Apr 20, 2020 · 0 comments
Open

Per-monitor DPI scaling #448

Wouterdek opened this issue Apr 20, 2020 · 0 comments

Comments

@Wouterdek
Copy link

NanoGUI already supports scaling applications based on the DPI of the monitor.
However, most GUI frameworks (including Qt, GTK3, WxWidgets, WPF/UWP, ...) now support "per-monitor DPI" and it seems NanoGUI does not. The idea here is that as an application window is dragged from one monitor to another, the window is rerendered with the DPI value of the second screen. This makes sure GUI elements maintain a consistent physical size, independent of screen size or resolution.

Below are two screenshots of a NanoGUI application on two different monitors on the same Windows computer. Notice that the application did not scale correctly in the second image, while Firefox in the background did.

monitor1
monitor2

It might be very simple to support this in NanoGUI. The snippet below offloads all the hard work of detecting DPI changes to GLFW. The rescaling uses the pre-existing mPixelRatio and get_pixel_ratio.

glfwSetWindowContentScaleCallback(mGLFWWindow,
    [](GLFWwindow* w, float xScale, float yScale) {
        auto it = __nanogui_screens.find(w);
        if (it == __nanogui_screens.end())
            return;
        Screen* s = it->second;
        
        s->mPixelRatio = get_pixel_ratio(w);
        if(!s->mFullscreen) {
            auto width = s->mSize.x() * s->mPixelRatio;
            auto height = s->mSize.y() * s->mPixelRatio;
            glfwSetWindowSize(w, width, height);
            s->resizeCallbackEvent(width, height);
        }
    }
);

The only issue here is that glfwSetWindowContentScaleCallback is a GLFW 3.3 function, while NanoGUI seems to be using 3.2.

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

No branches or pull requests

1 participant