diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 58a46a823..70b104c18 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -52,6 +52,10 @@ Other changes: - Examples: GLFW (all), SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop to handle minimization without burning CPU or GPU by running unthrottled code. (#7844) +Docking+Viewports Branch: + +- Viewports: added optional platform_io.Platform_GetWindowWorkAreaInsets() hook + to allow backends to alter the default per-viewport work-area. (#7823) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index bf6b4961c..b7fa1876d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -15238,11 +15238,18 @@ static void ImGui::UpdateViewportsNewFrame() // Update/copy monitor info UpdateViewportPlatformMonitor(viewport); - // Lock down space taken by menu bars and status bars + // Lock down space taken by menu bars and status bars + query initial insets from backend // Setup initial value for functions like BeginMainMenuBar(), DockSpaceOverViewport() etc. viewport->WorkInsetMin = viewport->BuildWorkInsetMin; viewport->WorkInsetMax = viewport->BuildWorkInsetMax; viewport->BuildWorkInsetMin = viewport->BuildWorkInsetMax = ImVec2(0.0f, 0.0f); + if (g.PlatformIO.Platform_GetWindowWorkAreaInsets != NULL) + { + ImVec4 insets = g.PlatformIO.Platform_GetWindowWorkAreaInsets(viewport); + IM_ASSERT(insets.x >= 0.0f && insets.y >= 0.0f && insets.z >= 0.0f && insets.w >= 0.0f); + viewport->BuildWorkInsetMin = ImVec2(insets.x, insets.y); + viewport->BuildWorkInsetMax = ImVec2(insets.z, insets.w); + } viewport->UpdateWorkRect(); // Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back. diff --git a/imgui.h b/imgui.h index 4302ca49b..300a189d5 100644 --- a/imgui.h +++ b/imgui.h @@ -3706,6 +3706,7 @@ struct ImGuiPlatformIO void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // . F . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so backend has a chance to swap fonts to adjust style. + ImVec4 (*Platform_GetWindowWorkAreaInsets)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] Get initial work area inset for the viewport (won't be covered by main menu bar, dockspace over viewport etc.). Default to (0,0),(0,0). 'safeAreaInsets' in iOS land, 'DisplayCutout' in Android land. int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For a Vulkan Renderer to call into Platform code (since the surface creation needs to tie them both). // (Optional) Renderer functions (e.g. DirectX, OpenGL, Vulkan) diff --git a/imgui_internal.h b/imgui_internal.h index c41ea700b..a61dd2e6f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1990,6 +1990,7 @@ struct ImGuiViewportP : public ImGuiViewport // Per-viewport work area // - Insets are >= 0.0f values, distance from viewport corners to work area. // - BeginMainMenuBar() and DockspaceOverViewport() tend to use work area to avoid stepping over existing contents. + // - Generally 'safeAreaInsets' in iOS land, 'DisplayCutout' in Android land. ImVec2 WorkInsetMin; // Work Area inset locked for the frame. GetWorkRect() always fits within GetMainRect(). ImVec2 WorkInsetMax; // " ImVec2 BuildWorkInsetMin; // Work Area inset accumulator for current frame, to become next frame's WorkInset