Skip to content

Commit 09780b8

Browse files
rokupsocornut
authored andcommitted
Viewport: Fix setting window size on macos (glfw). (#2767, #2117)
MacOS positions windows by their bottom-left corner why the rest of the world (including imgui) position windows by the top-left corner. This created an issue where collapsing imgui window would cause window header to remain at the bottom the full window rect. Likewise resizing window by using sizing handle caused window to grow upwards when we tried to expand window downwards. This workaround moves window to the opposite direction by the delta of size change creating an illusion that windows are positioned by their top-left corner.
1 parent 9e294be commit 09780b8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

examples/imgui_impl_glfw.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,16 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
570570
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
571571
{
572572
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
573+
#if __APPLE__
574+
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
575+
// positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it
576+
// doesn't handle it when changing size. We are manually moving the window in order for changes of size to be based
577+
// on the upper-left corner.
578+
int x, y, width, height;
579+
glfwGetWindowPos(data->Window, &x, &y);
580+
glfwGetWindowSize(data->Window, &width, &height);
581+
glfwSetWindowPos(data->Window, x, y - height + size.y);
582+
#endif
573583
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
574584
}
575585

0 commit comments

Comments
 (0)