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

Viewports: Fix window having incorrect size after it is uncollapsed #2756

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions examples/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@ struct ImGuiViewportDataGlfw
{
GLFWwindow* Window;
bool WindowOwned;
bool IgnoreSetWindowSizeEvent;

ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; }
ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreSetWindowSizeEvent = false; }
~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); }
};

Expand All @@ -426,7 +427,21 @@ static void ImGui_ImplGlfw_WindowPosCallback(GLFWwindow* window, int, int)
static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
{
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
{
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
{
if (data->IgnoreSetWindowSizeEvent)
{
// GLFW will dispatch window size event. ImGui expects no such event sent when library explicitly requests setting
// window size. Depending on the platform this callback may be invoked during glfwSetWindowSize() call or queued
// for the next frame and invoked during glfwPollEvents() call. When latter happens - restoring collapsed window
// would have incorrect size.
data->IgnoreSetWindowSizeEvent = false;
return;
}
}
viewport->PlatformRequestResize = true;
}
}

static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
Expand Down Expand Up @@ -569,6 +584,8 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)

static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
{
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
data->IgnoreSetWindowSizeEvent = true;
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
}
Expand Down Expand Up @@ -620,7 +637,7 @@ static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*)
static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
{
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
if (g_ClientApi == GlfwClientApi_OpenGL)
if (g_ClientApi == GlfwClientApi_OpenGL)
{
glfwMakeContextCurrent(data->Window);
glfwSwapBuffers(data->Window);
Expand Down