Viewports: added platform_io.Platform_GetWindowWorkAreaInsets() hook. (#7823)

This commit is contained in:
ocornut 2024-08-01 19:10:17 +02:00
parent d8c98c8c14
commit a18f020072
4 changed files with 14 additions and 1 deletions

View File

@ -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)
-----------------------------------------------------------------------

View File

@ -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.

View File

@ -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)

View File

@ -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