mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-20 06:46:36 +00:00
Viewport: Avoid calling platform functions when window is not created (apart from Platform_GetWindowDpiScale, documented as such). Main viewport situation is still ambiguous. (#1542)
This commit is contained in:
parent
36cbe1e521
commit
2fbbcaa339
19
imgui.cpp
19
imgui.cpp
@ -3681,7 +3681,7 @@ void ImGui::EndFrame()
|
|||||||
IM_ASSERT(g.FrameScopeActive && "Forgot to call ImGui::NewFrame()");
|
IM_ASSERT(g.FrameScopeActive && "Forgot to call ImGui::NewFrame()");
|
||||||
|
|
||||||
// Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
|
// Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
|
||||||
if (g.PlatformIO.Platform_SetImeInputPos && g.PlatformImePosViewport != NULL && ImLengthSqr(g.PlatformImePos - g.PlatformImeLastPos) > 0.0001f)
|
if (g.PlatformIO.Platform_SetImeInputPos && ImLengthSqr(g.PlatformImePos - g.PlatformImeLastPos) > 0.0001f && g.PlatformImePosViewport && g.PlatformImePosViewport->PlatformWindowCreated)
|
||||||
{
|
{
|
||||||
g.PlatformIO.Platform_SetImeInputPos(g.PlatformImePosViewport, g.PlatformImePos);
|
g.PlatformIO.Platform_SetImeInputPos(g.PlatformImePosViewport, g.PlatformImePos);
|
||||||
g.PlatformImeLastPos = g.PlatformImePos;
|
g.PlatformImeLastPos = g.PlatformImePos;
|
||||||
@ -7292,14 +7292,15 @@ static void ImGui::UpdateViewports()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool platform_funcs_available = (n == 0 || viewport->PlatformWindowCreated);
|
||||||
if ((g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
|
if ((g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
|
||||||
{
|
{
|
||||||
if (g.PlatformIO.Platform_GetWindowMinimized && (n == 0 || viewport->PlatformWindowCreated))
|
if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available)
|
||||||
viewport->PlatformWindowMinimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
|
viewport->PlatformWindowMinimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
|
||||||
|
|
||||||
// Apply Position and Size (from Platform Window to ImGui) if requested.
|
// Apply Position and Size (from Platform Window to ImGui) if requested.
|
||||||
// We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
|
// We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
|
||||||
if (!viewport->PlatformWindowMinimized)
|
if (!viewport->PlatformWindowMinimized && platform_funcs_available)
|
||||||
{
|
{
|
||||||
if (viewport->PlatformRequestMove)
|
if (viewport->PlatformRequestMove)
|
||||||
viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport);
|
viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport);
|
||||||
@ -7665,10 +7666,13 @@ void ImGui::UpdatePlatformWindows()
|
|||||||
if (g.PlatformIO.Platform_GetWindowFocus != NULL)
|
if (g.PlatformIO.Platform_GetWindowFocus != NULL)
|
||||||
{
|
{
|
||||||
ImGuiViewportP* focused_viewport = NULL;
|
ImGuiViewportP* focused_viewport = NULL;
|
||||||
for (int i = 0; i < g.Viewports.Size && focused_viewport == NULL; i++)
|
for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++)
|
||||||
if (g.Viewports[i]->PlatformUserData != NULL || g.Viewports[i]->PlatformHandle != NULL)
|
{
|
||||||
if (g.PlatformIO.Platform_GetWindowFocus(g.Viewports[i]))
|
ImGuiViewportP* viewport = g.Viewports[n];
|
||||||
focused_viewport = g.Viewports[i];
|
if (n == 0 || viewport->PlatformWindowCreated)
|
||||||
|
if (g.PlatformIO.Platform_GetWindowFocus(viewport))
|
||||||
|
focused_viewport = viewport;
|
||||||
|
}
|
||||||
if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID)
|
if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID)
|
||||||
{
|
{
|
||||||
if (focused_viewport->LastFrontMostStampCount != g.WindowsFrontMostStampCount)
|
if (focused_viewport->LastFrontMostStampCount != g.WindowsFrontMostStampCount)
|
||||||
@ -7758,6 +7762,7 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
|
|||||||
viewport->PlatformHandle = NULL;
|
viewport->PlatformHandle = NULL;
|
||||||
viewport->RendererUserData = viewport->PlatformHandle = NULL;
|
viewport->RendererUserData = viewport->PlatformHandle = NULL;
|
||||||
viewport->PlatformWindowCreated = false;
|
viewport->PlatformWindowCreated = false;
|
||||||
|
viewport->PlatformRequestClose = viewport->PlatformRequestMove = viewport->PlatformRequestResize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::DestroyPlatformWindows()
|
void ImGui::DestroyPlatformWindows()
|
||||||
|
4
imgui.h
4
imgui.h
@ -2107,8 +2107,8 @@ struct ImGuiPlatformIO
|
|||||||
void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // (Optional) Setup window transparency
|
void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // (Optional) Setup window transparency
|
||||||
void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Setup for render (platform side)
|
void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // (Optional) Setup for render (platform side)
|
||||||
void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (platform side)
|
void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // (Optional) Call Present/SwapBuffers (platform side)
|
||||||
float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // (Optional) DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. (FIXME-DPI)
|
float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // (Optional) [BETA] (FIXME-DPI) DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. IMPORTANT: this will be called _before_ the window is created, in which case the implementation is expected to use the viewport->Pos/Size fields to estimate DPI value.
|
||||||
void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // (Optional) DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style.
|
void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // (Optional) [BETA] (FIXME-DPI) DPI handling: Called during Begin() every time the viewport we are outputting into changes, so back-end has a chance to swap fonts to adjust style.
|
||||||
void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box.
|
void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box.
|
||||||
int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For Renderer to call into Platform code
|
int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For Renderer to call into Platform code
|
||||||
|
|
||||||
|
@ -848,7 +848,7 @@ struct ImGuiContext
|
|||||||
|
|
||||||
// Platform support
|
// Platform support
|
||||||
ImVec2 PlatformImePos, PlatformImeLastPos; // Cursor position request & last passed to the OS Input Method Editor
|
ImVec2 PlatformImePos, PlatformImeLastPos; // Cursor position request & last passed to the OS Input Method Editor
|
||||||
ImGuiViewport* PlatformImePosViewport;
|
ImGuiViewportP* PlatformImePosViewport;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
bool SettingsLoaded;
|
bool SettingsLoaded;
|
||||||
|
Loading…
Reference in New Issue
Block a user