Viewport, GLFW: Fix for #2756 under Windows.
This commit is contained in:
parent
a89a3cd2f1
commit
a4af3cc814
@ -1,7 +1,7 @@
|
|||||||
// dear imgui: Platform Binding for GLFW
|
// dear imgui: Platform Binding for GLFW
|
||||||
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..)
|
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..)
|
||||||
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
|
||||||
// (Requires: GLFW 3.1+)
|
// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [X] Platform: Clipboard support.
|
// [X] Platform: Clipboard support.
|
||||||
@ -406,9 +406,9 @@ struct ImGuiViewportDataGlfw
|
|||||||
{
|
{
|
||||||
GLFWwindow* Window;
|
GLFWwindow* Window;
|
||||||
bool WindowOwned;
|
bool WindowOwned;
|
||||||
bool IgnoreSetWindowSizeEvent;
|
int IgnoreWindowSizeEventFrame;
|
||||||
|
|
||||||
ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreSetWindowSizeEvent = false; }
|
ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = -1; }
|
||||||
~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); }
|
~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -430,16 +430,17 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
|
|||||||
{
|
{
|
||||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
if (data->IgnoreSetWindowSizeEvent)
|
// GLFW may dispatch window size event after calling glfwSetWindowSize().
|
||||||
{
|
// However depending on the platform the callback may be invoked at different time: on Windows it
|
||||||
// GLFW will dispatch window size event. ImGui expects no such event sent when library explicitly requests setting
|
// appears to be called within the glfwSetWindowSize() call whereas on Linux it is queued and invoked
|
||||||
// window size. Depending on the platform this callback may be invoked during glfwSetWindowSize() call or queued
|
// during glfwPollEvents().
|
||||||
// for the next frame and invoked during glfwPollEvents() call. When latter happens - restoring collapsed window
|
// Because the event doesn't always fire on glfwSetWindowSize() we use a frame counter tag to only
|
||||||
// would have incorrect size.
|
// ignore recent glfwSetWindowSize() calls.
|
||||||
data->IgnoreSetWindowSizeEvent = false;
|
bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1);
|
||||||
|
data->IgnoreWindowSizeEventFrame = -1;
|
||||||
|
if (ignore_event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
viewport->PlatformRequestResize = true;
|
viewport->PlatformRequestResize = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -584,8 +585,6 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
|
||||||
data->IgnoreSetWindowSizeEvent = true;
|
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
|
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
|
||||||
@ -597,6 +596,7 @@ static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
glfwGetWindowSize(data->Window, &width, &height);
|
glfwGetWindowSize(data->Window, &width, &height);
|
||||||
glfwSetWindowPos(data->Window, x, y - height + size.y);
|
glfwSetWindowPos(data->Window, x, y - height + size.y);
|
||||||
#endif
|
#endif
|
||||||
|
data->IgnoreWindowSizeEventFrame = ImGui::GetFrameCount();
|
||||||
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
|
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user