mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Sim GUI: Handle low resolutions and scale default window positions
Low resolutions result in a maximized window and forced user scaling down (by default, can still be changed by the user).
This commit is contained in:
@@ -292,8 +292,22 @@ bool HALSimGui::Initialize() {
|
||||
|
||||
// Set initial window settings
|
||||
glfwWindowHint(GLFW_MAXIMIZED, gWindowMaximized ? GLFW_TRUE : GLFW_FALSE);
|
||||
if (!gWindowLoadedWidthHeight)
|
||||
|
||||
float windowScale = 1.0;
|
||||
if (!gWindowLoadedWidthHeight) {
|
||||
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
|
||||
// get the primary monitor work area to see if we have a reasonable initial
|
||||
// window size; if not, maximize, and default scaling to smaller
|
||||
if (GLFWmonitor* primary = glfwGetPrimaryMonitor()) {
|
||||
int monWidth, monHeight;
|
||||
glfwGetMonitorWorkarea(primary, nullptr, nullptr, &monWidth, &monHeight);
|
||||
if (monWidth < gWindowWidth || monHeight < gWindowHeight) {
|
||||
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||
windowScale = (std::min)(monWidth * 1.0 / gWindowWidth,
|
||||
monHeight * 1.0 / gWindowHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gWindowXPos != -1 && gWindowYPos != -1)
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
@@ -302,6 +316,26 @@ bool HALSimGui::Initialize() {
|
||||
"Robot Simulation GUI", nullptr, nullptr);
|
||||
if (!gWindow) return false;
|
||||
|
||||
if (!gWindowLoadedWidthHeight) {
|
||||
if (windowScale == 1.0)
|
||||
glfwGetWindowContentScale(gWindow, &windowScale, nullptr);
|
||||
wpi::outs() << "windowScale = " << windowScale;
|
||||
// force user scale if window scale is smaller
|
||||
if (windowScale <= 0.5)
|
||||
gUserScale = 0;
|
||||
else if (windowScale <= 0.75)
|
||||
gUserScale = 1;
|
||||
if (windowScale != 1.0) {
|
||||
// scale default window positions
|
||||
for (auto&& window : gWindows) {
|
||||
if ((window.posCond & ImGuiCond_FirstUseEver) != 0) {
|
||||
window.pos.x *= windowScale;
|
||||
window.pos.y *= windowScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update window settings
|
||||
if (gWindowXPos != -1 && gWindowYPos != -1) {
|
||||
glfwSetWindowPos(gWindow, gWindowXPos, gWindowYPos);
|
||||
|
||||
Reference in New Issue
Block a user