The open source OpenXR runtime

u/debug_gui: Properly scale ImGui interface to match the display DPI

Make it easy to read on 4K screens.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2430>

authored by

Aleksander and committed by
Marge Bot
3c3587a5 a2087886

+18 -1
+18 -1
src/xrt/auxiliary/util/u_debug_gui.c
··· 8 8 * @author Moshi Turner <moshiturner@protonmail.com> 9 9 */ 10 10 11 + #include "math/m_api.h" 11 12 #include "xrt/xrt_system.h" 12 13 #include "xrt/xrt_instance.h" 13 14 #include "xrt/xrt_config_build.h" ··· 84 85 bool sdl_initialized; 85 86 char layout_file[1024]; 86 87 88 + float gui_scale; 89 + 87 90 #ifdef XRT_BUILD_DRIVER_QWERTY 88 91 bool qwerty_enabled; 89 92 #endif ··· 151 154 152 155 // Start the scene. 153 156 gui_scene_debug(&p->base); 157 + 158 + // Set imgui interface scale percentage 159 + p->gui_scale = 1.0f; // Fallback (default) value 160 + int disp_idx = SDL_GetWindowDisplayIndex(p->win); 161 + if (disp_idx >= 0) { 162 + float dpi; 163 + if (SDL_GetDisplayDPI(disp_idx, &dpi, NULL, NULL) >= 0) { 164 + // 96.0f is the base 100% GUI scale reported by SDL2 165 + p->gui_scale = CLAMP(dpi / 96.0f, 1.0f, 3.0f); // up to 300% 166 + } 167 + } 154 168 } 155 169 156 170 static void ··· 237 251 238 252 // Local state 239 253 ImGuiIO *io = igGetIO(); 254 + io->FontGlobalScale = p->gui_scale; 240 255 241 256 // Make window layout file "imgui.ini" live in config dir 242 257 XRT_MAYBE_UNUSED int res = u_file_get_path_in_config_dir("imgui.ini", p->layout_file, sizeof(p->layout_file)); ··· 254 269 ImGui_ImplOpenGL3_Init(NULL); 255 270 256 271 // Setup Dear ImGui style 257 - igStyleColorsDark(NULL); 272 + ImGuiStyle *style = igGetStyle(); 273 + ImGuiStyle_ScaleAllSizes(style, p->gui_scale); 274 + igStyleColorsDark(style); 258 275 259 276 // Setup the plot context. 260 277 ImPlotContext *plot_ctx = ImPlot_CreateContext();