mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-22 15:46:35 +00:00
Viewport: Added ImGuiConfigFlags_ViewportsDecoration to re-enable platform decoration (#1542)
This commit is contained in:
parent
33b88a0339
commit
3a7828de6b
@ -281,6 +281,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
|
|||||||
|
|
||||||
- examples: move ImGui::NewFrame() out of the backend _NewFrame() ?
|
- examples: move ImGui::NewFrame() out of the backend _NewFrame() ?
|
||||||
- viewport: make it possible to have no main/hosting viewport
|
- viewport: make it possible to have no main/hosting viewport
|
||||||
|
- viewport: with platform decoration enabled, platform may force constraint (e.g. minimum size)
|
||||||
- viewport: use getfocus/setfocus api to synchronize imgui<>platform focus better (e.g imgui-side ctrl-tab can focus os window, OS initial setup and alt-tab can focus imgui window etc.)
|
- viewport: use getfocus/setfocus api to synchronize imgui<>platform focus better (e.g imgui-side ctrl-tab can focus os window, OS initial setup and alt-tab can focus imgui window etc.)
|
||||||
- viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for.
|
- viewport: store per-viewport/monitor DPI in .ini file so an application reload or main window changing DPI on reload can be properly patched for.
|
||||||
- viewport: vulkan renderer implementation.
|
- viewport: vulkan renderer implementation.
|
||||||
|
35
imgui.cpp
35
imgui.cpp
@ -3211,10 +3211,13 @@ void ImGui::NewFrame()
|
|||||||
{
|
{
|
||||||
if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports))
|
if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports))
|
||||||
{
|
{
|
||||||
IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() at the end of the previous frame?");
|
IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() in main loop after EndFrame()?");
|
||||||
IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?");
|
IM_ASSERT(g.PlatformIO.Platform_CreateWindow != NULL && "Platform init didn't install handlers?");
|
||||||
IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?");
|
IM_ASSERT(g.PlatformIO.Platform_DestroyWindow != NULL && "Platform init didn't install handlers?");
|
||||||
IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?");
|
IM_ASSERT(g.PlatformIO.Platform_GetWindowPos != NULL && "Platform init didn't install handlers?");
|
||||||
|
IM_ASSERT(g.PlatformIO.Platform_SetWindowPos != NULL && "Platform init didn't install handlers?");
|
||||||
|
IM_ASSERT(g.PlatformIO.Platform_GetWindowSize != NULL && "Platform init didn't install handlers?");
|
||||||
|
IM_ASSERT(g.PlatformIO.Platform_SetWindowSize != NULL && "Platform init didn't install handlers?");
|
||||||
IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport.");
|
IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport.");
|
||||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||||
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
||||||
@ -5028,7 +5031,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
{
|
{
|
||||||
// Late create viewport, based on the assumption that with our calculations, the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport)
|
// Late create viewport, based on the assumption that with our calculations, the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport)
|
||||||
//ImGuiViewport* old_viewport = window->Viewport;
|
//ImGuiViewport* old_viewport = window->Viewport;
|
||||||
ImGuiViewportFlags viewport_flags = ImGuiViewportFlags_NoDecoration | ImGuiViewportFlags_NoFocusOnAppearing | ((window->Flags & ImGuiWindowFlags_NoInputs) ? ImGuiViewportFlags_NoInputs : 0);
|
ImGuiViewportFlags viewport_flags = ImGuiViewportFlags_NoFocusOnAppearing | ((window->Flags & ImGuiWindowFlags_NoInputs) ? ImGuiViewportFlags_NoInputs : 0);
|
||||||
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, viewport_flags);
|
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, viewport_flags);
|
||||||
|
|
||||||
// FIXME-DPI
|
// FIXME-DPI
|
||||||
@ -7191,6 +7194,7 @@ static ImGuiViewportP* FindViewportHoveredFromPlatformWindowStack(const ImVec2 m
|
|||||||
return best_candidate;
|
return best_candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called in NewFrame()
|
||||||
static void ImGui::UpdateViewports()
|
static void ImGui::UpdateViewports()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -7413,7 +7417,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
|
|||||||
{
|
{
|
||||||
window->Viewport = FindViewportByID(window->ViewportId);
|
window->Viewport = FindViewportByID(window->ViewportId);
|
||||||
if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX)
|
if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX)
|
||||||
window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_NoDecoration);
|
window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7443,11 +7447,11 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
|
|||||||
bool leave_host_viewport = has_viewport && !own_viewport && !window->Viewport->GetRect().Contains(window->Rect());
|
bool leave_host_viewport = has_viewport && !own_viewport && !window->Viewport->GetRect().Contains(window->Rect());
|
||||||
bool move_from_own_viewport = has_viewport && own_viewport && !(window->Viewport->Flags & ImGuiViewportFlags_NoInputs);
|
bool move_from_own_viewport = has_viewport && own_viewport && !(window->Viewport->Flags & ImGuiViewportFlags_NoInputs);
|
||||||
if (!has_viewport || leave_host_viewport || move_from_own_viewport)
|
if (!has_viewport || leave_host_viewport || move_from_own_viewport)
|
||||||
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoDecoration | ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoInputs);
|
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoInputs);
|
||||||
}
|
}
|
||||||
else if (GetWindowAlwaysWantOwnViewport(window))
|
else if (GetWindowAlwaysWantOwnViewport(window))
|
||||||
{
|
{
|
||||||
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoDecoration);
|
window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark window as allowed to protrude outside of its viewport and into the current monitor
|
// Mark window as allowed to protrude outside of its viewport and into the current monitor
|
||||||
@ -7472,16 +7476,15 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
|
|||||||
|
|
||||||
// Update flags
|
// Update flags
|
||||||
window->ViewportOwned = (window == window->Viewport->Window);
|
window->ViewportOwned = (window == window->Viewport->Window);
|
||||||
if (window->ViewportOwned)
|
|
||||||
window->Viewport->Flags |= ImGuiViewportFlags_NoDecoration;
|
|
||||||
|
|
||||||
// If the OS window has a title bar, hide our imgui title bar
|
// If the OS window has a title bar, hide our imgui title bar
|
||||||
if (window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
|
//if (window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
|
||||||
window->Flags |= ImGuiWindowFlags_NoTitleBar;
|
// window->Flags |= ImGuiWindowFlags_NoTitleBar;
|
||||||
|
|
||||||
window->ViewportId = window->Viewport->ID;
|
window->ViewportId = window->Viewport->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by imgui at the end of the main loop, after EndFrame()
|
||||||
void ImGui::UpdatePlatformWindows()
|
void ImGui::UpdatePlatformWindows()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -7515,13 +7518,17 @@ void ImGui::UpdatePlatformWindows()
|
|||||||
if (viewport->Size.x <= 0 || viewport->Size.y <= 0)
|
if (viewport->Size.x <= 0 || viewport->Size.y <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Update viewport flags
|
// Update common viewport flags for owned viewports
|
||||||
if (viewport->Window != NULL)
|
if (viewport->Window != NULL)
|
||||||
{
|
{
|
||||||
bool topmost = (viewport->Window->Flags & ImGuiWindowFlags_Tooltip) != 0;
|
ImGuiViewportFlags flags = viewport->Flags & ~(ImGuiViewportFlags_TopMost | ImGuiViewportFlags_NoTaskBarIcon | ImGuiViewportFlags_NoDecoration);
|
||||||
bool no_task_bar_icon = (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsNoTaskBarIcons) != 0 || (viewport->Window->Flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0;
|
if (viewport->Window->Flags & ImGuiWindowFlags_Tooltip)
|
||||||
viewport->Flags = topmost ? (viewport->Flags | ImGuiViewportFlags_TopMost) : (viewport->Flags & ~ImGuiViewportFlags_TopMost);
|
flags |= ImGuiViewportFlags_TopMost;
|
||||||
viewport->Flags = no_task_bar_icon ? (viewport->Flags | ImGuiViewportFlags_NoTaskBarIcon) : (viewport->Flags & ~ImGuiViewportFlags_NoTaskBarIcon);
|
if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsNoTaskBarIcon) != 0 || (viewport->Window->Flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0)
|
||||||
|
flags |= ImGuiViewportFlags_NoTaskBarIcon;
|
||||||
|
if ((g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsDecoration) == 0 || (viewport->Window->Flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0)
|
||||||
|
flags |= ImGuiViewportFlags_NoDecoration;
|
||||||
|
viewport->Flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
|
16
imgui.h
16
imgui.h
@ -886,10 +886,11 @@ enum ImGuiConfigFlags_
|
|||||||
|
|
||||||
// [BETA] Viewports
|
// [BETA] Viewports
|
||||||
ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends)
|
ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends)
|
||||||
ImGuiConfigFlags_ViewportsNoTaskBarIcons= 1 << 11, // Disable task bars icons for all secondary viewports (will set ImGuiViewportFlags_NoTaskBarIcon on them)
|
ImGuiConfigFlags_ViewportsNoTaskBarIcon = 1 << 11, // Disable task bars icons for all secondary viewports (will set ImGuiViewportFlags_NoTaskBarIcon on them)
|
||||||
ImGuiConfigFlags_ViewportsNoMerge = 1 << 12, // All floating windows will always create their own viewport and platform window.
|
ImGuiConfigFlags_ViewportsNoMerge = 1 << 12, // All floating windows will always create their own viewport and platform window.
|
||||||
ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 13, // FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application.
|
ImGuiConfigFlags_ViewportsDecoration = 1 << 13, // FIXME [Broken] Enable platform decoration for all secondary viewports (will not set ImGuiViewportFlags_NoDecoration on them). This currently doesn't behave well in Windows because 1) By default the new window animation get in the way of our transitions, 2) It enable a minimum window size which tends to breaks resizing. You can workaround the later by setting style.WindowMinSize to a bigger value.
|
||||||
ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 14, // FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
|
ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application.
|
||||||
|
ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
|
||||||
|
|
||||||
// User storage (to allow your back-end/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core ImGui)
|
// User storage (to allow your back-end/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core ImGui)
|
||||||
ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware.
|
ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware.
|
||||||
@ -2068,7 +2069,8 @@ struct ImGuiPlatformIO
|
|||||||
// Flags stored in ImGuiViewport::Flags, giving indications to the platform back-ends
|
// Flags stored in ImGuiViewport::Flags, giving indications to the platform back-ends
|
||||||
enum ImGuiViewportFlags_
|
enum ImGuiViewportFlags_
|
||||||
{
|
{
|
||||||
ImGuiViewportFlags_NoDecoration = 1 << 0, // Platform Window: Disable platform title bar, borders, etc.
|
ImGuiViewportFlags_None = 0,
|
||||||
|
ImGuiViewportFlags_NoDecoration = 1 << 0, // Platform Window: Disable platform decorations: title bar, borders, etc.
|
||||||
ImGuiViewportFlags_NoFocusOnAppearing = 1 << 1, // Platform Window: Don't take focus when created.
|
ImGuiViewportFlags_NoFocusOnAppearing = 1 << 1, // Platform Window: Don't take focus when created.
|
||||||
ImGuiViewportFlags_NoInputs = 1 << 2, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it.
|
ImGuiViewportFlags_NoInputs = 1 << 2, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it.
|
||||||
ImGuiViewportFlags_NoTaskBarIcon = 1 << 3, // Platform Window: Disable platform task bar icon (for popups, menus, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcons if set)
|
ImGuiViewportFlags_NoTaskBarIcon = 1 << 3, // Platform Window: Disable platform task bar icon (for popups, menus, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcons if set)
|
||||||
@ -2088,9 +2090,9 @@ struct ImGuiViewport
|
|||||||
|
|
||||||
void* PlatformUserData; // void* to hold custom data structure for the platform (e.g. windowing info, render context)
|
void* PlatformUserData; // void* to hold custom data structure for the platform (e.g. windowing info, render context)
|
||||||
void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GlfwWindow*, SDL_Window*)
|
void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GlfwWindow*, SDL_Window*)
|
||||||
bool PlatformRequestClose; // Platform window requested closure
|
bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4)
|
||||||
bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager)
|
bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position)
|
||||||
bool PlatformRequestResize; // Platform window requested resize (e.g. window was resize by the OS / host window manager)
|
bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size)
|
||||||
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.)
|
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.)
|
||||||
|
|
||||||
ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; PlatformUserData = PlatformHandle = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; RendererUserData = NULL; }
|
ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; PlatformUserData = PlatformHandle = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; RendererUserData = NULL; }
|
||||||
|
@ -312,8 +312,10 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
|||||||
ImGui::SameLine(); ShowHelpMarker("Instruct back-end to not alter mouse cursor shape and visibility.");
|
ImGui::SameLine(); ShowHelpMarker("Instruct back-end to not alter mouse cursor shape and visibility.");
|
||||||
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsEnable", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsEnable);
|
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsEnable", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsEnable);
|
||||||
ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (it will offset your windows).");
|
ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (it will offset your windows).");
|
||||||
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsNoTaskBarIcons", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsNoTaskBarIcons);
|
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsNoTaskBarIcon", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsNoTaskBarIcon);
|
||||||
ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the task bar icon state right away).");
|
ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the task bar icon state right away).");
|
||||||
|
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsDecoration", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsDecoration);
|
||||||
|
ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the decoration right away).");
|
||||||
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsNoMerge", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsNoMerge);
|
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsNoMerge", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsNoMerge);
|
||||||
ImGui::SameLine(); ShowHelpMarker("All floating windows will always create their own viewport and platform window.");
|
ImGui::SameLine(); ShowHelpMarker("All floating windows will always create their own viewport and platform window.");
|
||||||
ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink);
|
ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink);
|
||||||
|
Loading…
Reference in New Issue
Block a user