From 39e3d51fa1194e78df5376072164455270154b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Fri, 20 Aug 2021 09:48:36 -0700 Subject: [PATCH] Updated ImGui. --- 3rdparty/dear-imgui/imgui.cpp | 5879 +------------------------ 3rdparty/dear-imgui/imgui.h | 303 +- 3rdparty/dear-imgui/imgui_demo.cpp | 319 +- 3rdparty/dear-imgui/imgui_draw.cpp | 17 +- 3rdparty/dear-imgui/imgui_internal.h | 340 +- 3rdparty/dear-imgui/imgui_tables.cpp | 2 +- 3rdparty/dear-imgui/imgui_widgets.cpp | 223 +- 7 files changed, 345 insertions(+), 6738 deletions(-) diff --git a/3rdparty/dear-imgui/imgui.cpp b/3rdparty/dear-imgui/imgui.cpp index 226994908..434571fe4 100644 --- a/3rdparty/dear-imgui/imgui.cpp +++ b/3rdparty/dear-imgui/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (main code and documentation) // Help: @@ -11,7 +11,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/3793 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/4451 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -76,8 +76,7 @@ CODE // [SECTION] DRAG AND DROP // [SECTION] LOGGING/CAPTURING // [SECTION] SETTINGS -// [SECTION] VIEWPORTS, PLATFORM WINDOWS -// [SECTION] DOCKING +// [SECTION] VIEWPORTS // [SECTION] PLATFORM DEPENDENT HELPERS // [SECTION] METRICS/DEBUGGER WINDOW @@ -377,15 +376,6 @@ CODE When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files. You can read releases logs https://github.com/ocornut/imgui/releases for more details. -(Docking/Viewport Branch) - - 2021/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: - - reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore. - you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos) - - likewise io.MousePos and GetMousePos() will use OS coordinates. - If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos. - - 2021/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api. - - - 2021/07/26 (1.84) - commented out redirecting functions/enums names that were marked obsolete in 1.67 and 1.69 (March 2019): - ImGui::GetOverlayDrawList() -> use ImGui::GetForegroundDrawList() - ImFont::GlyphRangesBuilder -> use ImFontGlyphRangesBuilder @@ -888,10 +878,6 @@ static const float WINDOWS_HOVER_PADDING = 4.0f; // Exten static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time. static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 2.00f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved. -// Docking -static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For use with io.ConfigDockingTransparentPayload. Apply to Viewport _or_ WindowBg in host viewport. -static const float DOCKING_SPLITTER_SIZE = 2.0f; - //------------------------------------------------------------------------- // [SECTION] FORWARD DECLARATIONS //------------------------------------------------------------------------- @@ -914,6 +900,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSetti // Platform Dependents default implementation for IO functions static const char* GetClipboardTextFn_DefaultImpl(void* user_data); static void SetClipboardTextFn_DefaultImpl(void* user_data, const char* text); +static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y); namespace ImGui { @@ -947,23 +934,11 @@ static void UpdateTabFocus(); static void UpdateDebugToolItemPicker(); static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect); static void RenderWindowOuterBorders(ImGuiWindow* window); -static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size); +static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size); static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open); -static void EndFrameDrawDimmedBackgrounds(); // Viewports -const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHashStr("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter. -static ImGuiViewportP* AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& platform_pos, const ImVec2& size, ImGuiViewportFlags flags); static void UpdateViewportsNewFrame(); -static void UpdateViewportsEndFrame(); -static void WindowSelectViewport(ImGuiWindow* window); -static void WindowSyncOwnedViewport(ImGuiWindow* window, ImGuiWindow* parent_window_in_stack); -static bool UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* host_viewport); -static bool UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window); -static bool GetWindowAlwaysWantOwnViewport(ImGuiWindow* window); -static int FindPlatformMonitorForPos(const ImVec2& pos); -static int FindPlatformMonitorForRect(const ImRect& r); -static void UpdateViewportPlatformMonitor(ImGuiViewportP* viewport); } @@ -1015,7 +990,8 @@ static void* GImAllocatorUserData = NULL; ImGuiStyle::ImGuiStyle() { - Alpha = 1.0f; // Global alpha applies to everything in ImGui + Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui. + DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. WindowPadding = ImVec2(8,8); // Padding within a window WindowRounding = 0.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows. Large values tend to lead to variety of artifacts and are not recommended. WindowBorderSize = 1.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested. @@ -1116,17 +1092,6 @@ ImGuiIO::ImGuiIO() FontAllowUserScaling = false; DisplayFramebufferScale = ImVec2(1.0f, 1.0f); - // Docking options (when ImGuiConfigFlags_DockingEnable is set) - ConfigDockingNoSplit = false; - ConfigDockingAlwaysTabBar = false; - ConfigDockingTransparentPayload = false; - - // Viewport options (when ImGuiConfigFlags_ViewportsEnable is set) - ConfigViewportsNoAutoMerge = false; - ConfigViewportsNoTaskBarIcon = false; - ConfigViewportsNoDecoration = true; - ConfigViewportsNoDefaultParent = false; - // Miscellaneous options MouseDrawCursor = false; #ifdef __APPLE__ @@ -1145,6 +1110,8 @@ ImGuiIO::ImGuiIO() GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; ClipboardUserData = NULL; + ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl; + ImeWindowHandle = NULL; // Input (NB: we already have memset zero the entire structure!) MousePos = ImVec2(-FLT_MAX, -FLT_MAX); @@ -1216,8 +1183,13 @@ void ImGuiIO::ClearInputCharacters() InputQueueCharacters.resize(0); } -void ImGuiIO::ClearInputKeys() +void ImGuiIO::AddFocusEvent(bool focused) { + if (focused) + return; + + // Clear buttons state when focus is lost + // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle) memset(KeysDown, 0, sizeof(KeysDown)); for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++) KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f; @@ -1227,13 +1199,6 @@ void ImGuiIO::ClearInputKeys() NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f; } -void ImGuiIO::AddFocusEvent(bool focused) -{ - // We intentionally overwrite this and process in NewFrame(), in order to give a chance - // to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame. - AppFocusLost = !focused; -} - //----------------------------------------------------------------------------- // [SECTION] MISC HELPERS/UTILITIES (Geometry functions) //----------------------------------------------------------------------------- @@ -2568,14 +2533,10 @@ struct ImGuiStyleVarInfo void* GetVarPtr(ImGuiStyle* style) const { return (void*)((unsigned char*)style + Offset); } }; -static const ImGuiCol GWindowDockStyleColors[ImGuiWindowDockStyleCol_COUNT] = -{ - ImGuiCol_Text, ImGuiCol_Tab, ImGuiCol_TabHovered, ImGuiCol_TabActive, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive -}; - static const ImGuiStyleVarInfo GStyleVarInfo[] = { { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha + { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, DisabledAlpha) }, // ImGuiStyleVar_DisabledAlpha { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize @@ -2695,8 +2656,6 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx) case ImGuiCol_TabActive: return "TabActive"; case ImGuiCol_TabUnfocused: return "TabUnfocused"; case ImGuiCol_TabUnfocusedActive: return "TabUnfocusedActive"; - case ImGuiCol_DockingPreview: return "DockingPreview"; - case ImGuiCol_DockingEmptyBg: return "DockingEmptyBg"; case ImGuiCol_PlotLines: return "PlotLines"; case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; case ImGuiCol_PlotHistogram: return "PlotHistogram"; @@ -2976,21 +2935,17 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst NameBufLen = (int)strlen(name) + 1; ID = ImHashStr(name); IDStack.push_back(ID); - ViewportAllowPlatformMonitorExtend = -1; - ViewportPos = ImVec2(FLT_MAX, FLT_MAX); MoveId = GetID("#MOVE"); ScrollTarget = ImVec2(FLT_MAX, FLT_MAX); ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f); AutoFitFramesX = AutoFitFramesY = -1; AutoPosLastDirection = ImGuiDir_None; - SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = SetWindowDockAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; + SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing; SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX); LastFrameActive = -1; - LastFrameJustFocused = -1; LastTimeActive = -1.0f; - FontWindowScale = FontDpiScale = 1.0f; + FontWindowScale = 1.0f; SettingsOffset = -1; - DockOrder = -1; DrawList = &DrawListInst; DrawList->_Data = &context->DrawListSharedData; DrawList->_OwnerName = Name; @@ -3209,8 +3164,8 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla // FIXME-OPT: This could be cached/stored within the window. ImGuiContext& g = *GImGui; if (g.NavWindow) - if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindowDockTree) - if (focused_root_window->WasActive && focused_root_window != window->RootWindowDockTree) + if (ImGuiWindow* focused_root_window = g.NavWindow->RootWindow) + if (focused_root_window->WasActive && focused_root_window != window->RootWindow) { // For the purpose of those flags we differentiate "standard popup" from "modal popup" // NB: The order of those two tests is important because Modal windows are also Popups. @@ -3219,12 +3174,6 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window, ImGuiHoveredFla if ((focused_root_window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup)) return false; } - - // Filter by viewport - if (window->Viewport != g.MouseViewport) - if (g.MovingWindow == NULL || window->RootWindowDockTree != g.MovingWindow->RootWindowDockTree) - return false; - return true; } @@ -3273,7 +3222,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) // Special handling for calling after Begin() which represent the title bar or tab. // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case. - if ((g.LastItemData.ID == window->ID || g.LastItemData.ID == window->MoveId) && window->WriteAccessed) + if (g.LastItemData.ID == window->MoveId && window->WriteAccessed) return false; return true; } @@ -3343,17 +3292,6 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged return false; } -// This is also inlined in ItemAdd() -// Note: if ImGuiItemStatusFlags_HasDisplayRect is set, user needs to set window->DC.LastItemDisplayRect! -void ImGui::SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags item_flags, const ImRect& item_rect) -{ - ImGuiContext& g = *GImGui; - g.LastItemData.ID = item_id; - g.LastItemData.InFlags = in_flags; - g.LastItemData.StatusFlags = item_flags; - g.LastItemData.Rect = item_rect; -} - // Called by ItemAdd() // Process TAB/Shift+TAB. Be mindful that this function may _clear_ the ActiveID when tabbing out. void ImGui::ItemFocusable(ImGuiWindow* window, ImGuiID id) @@ -3546,12 +3484,6 @@ ImGuiIO& ImGui::GetIO() return GImGui->IO; } -ImGuiPlatformIO& ImGui::GetPlatformIO() -{ - IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?"); - return GImGui->PlatformIO; -} - // Pass this to your backend rendering function! Valid after Render() and until the next call to NewFrame() ImDrawData* ImGui::GetDrawData() { @@ -3602,7 +3534,7 @@ ImDrawList* ImGui::GetBackgroundDrawList(ImGuiViewport* viewport) ImDrawList* ImGui::GetBackgroundDrawList() { ImGuiContext& g = *GImGui; - return GetBackgroundDrawList(g.CurrentWindow->Viewport); + return GetBackgroundDrawList(g.Viewports[0]); } ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport) @@ -3613,7 +3545,7 @@ ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport) ImDrawList* ImGui::GetForegroundDrawList() { ImGuiContext& g = *GImGui; - return GetForegroundDrawList(g.CurrentWindow->Viewport); + return GetForegroundDrawList(g.Viewports[0]); } ImDrawListSharedData* ImGui::GetDrawListSharedData() @@ -3630,46 +3562,17 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window) FocusWindow(window); SetActiveID(window->MoveId, window); g.NavDisableHighlight = true; - g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindowDockTree->Pos; + g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindow->Pos; g.ActiveIdNoClearOnFocusLoss = true; SetActiveIdUsingNavAndKeys(); bool can_move_window = true; - if ((window->Flags & ImGuiWindowFlags_NoMove) || (window->RootWindowDockTree->Flags & ImGuiWindowFlags_NoMove)) + if ((window->Flags & ImGuiWindowFlags_NoMove) || (window->RootWindow->Flags & ImGuiWindowFlags_NoMove)) can_move_window = false; - if (ImGuiDockNode* node = window->DockNodeAsHost) - if (node->VisibleWindow && (node->VisibleWindow->Flags & ImGuiWindowFlags_NoMove)) - can_move_window = false; if (can_move_window) g.MovingWindow = window; } -// We use 'undock_floating_node == false' when dragging from title bar to allow moving groups of floating nodes without undocking them. -// - undock_floating_node == true: when dragging from a floating node within a hierarchy, always undock the node. -// - undock_floating_node == false: when dragging from a floating node within a hierarchy, move root window. -void ImGui::StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* node, bool undock_floating_node) -{ - ImGuiContext& g = *GImGui; - bool can_undock_node = false; - if (node != NULL && node->VisibleWindow && (node->VisibleWindow->Flags & ImGuiWindowFlags_NoMove) == 0) - { - // Can undock if: - // - part of a floating node hierarchy with more than one visible node (if only one is visible, we'll just move the whole hierarchy) - // - part of a dockspace node hierarchy (trivia: undocking from a fixed/central node will create a new node and copy windows) - ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (root_node->OnlyNodeWithWindows != node || root_node->CentralNode != NULL) // -V1051 PVS-Studio thinks node should be root_node and is wrong about that. - if (undock_floating_node || root_node->IsDockSpace()) - can_undock_node = true; - } - - const bool clicked = IsMouseClicked(0); - const bool dragging = IsMouseDragging(0, g.IO.MouseDragThreshold * 1.70f); - if (can_undock_node && dragging) - DockContextQueueUndockNode(&g, node); // Will lead to DockNodeStartMouseMovingWindow() -> StartMouseMovingWindow() being called next frame - else if (!can_undock_node && (clicked || dragging) && g.MovingWindow != window) - StartMouseMovingWindow(window); -} - // Handle mouse moving window // Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing() // FIXME: We don't have strong guarantee that g.MovingWindow stay synched with g.ActiveId == g.MovingWindow->MoveId. @@ -3683,8 +3586,8 @@ void ImGui::UpdateMouseMovingWindowNewFrame() // We actually want to move the root window. g.MovingWindow == window we clicked on (could be a child window). // We track it to preserve Focus and so that generally ActiveIdWindow == MovingWindow and ActiveId == MovingWindow->MoveId for consistency. KeepAliveID(g.ActiveId); - IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindowDockTree); - ImGuiWindow* moving_window = g.MovingWindow->RootWindowDockTree; + IM_ASSERT(g.MovingWindow && g.MovingWindow->RootWindow); + ImGuiWindow* moving_window = g.MovingWindow->RootWindow; if (g.IO.MouseDown[0] && IsMousePosValid(&g.IO.MousePos)) { ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset; @@ -3692,28 +3595,11 @@ void ImGui::UpdateMouseMovingWindowNewFrame() { MarkIniSettingsDirty(moving_window); SetWindowPos(moving_window, pos, ImGuiCond_Always); - if (moving_window->ViewportOwned) // Synchronize viewport immediately because some overlays may relies on clipping rectangle before we Begin() into the window. - { - moving_window->Viewport->Pos = pos; - moving_window->Viewport->UpdateWorkRect(); - } } FocusWindow(g.MovingWindow); } else { - // Try to merge the window back into the main viewport. - // This works because MouseViewport should be != MovingWindow->Viewport on release (as per code in UpdateViewports) - if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) - UpdateTryMergeWindowIntoHostViewport(moving_window, g.MouseViewport); - - // Restore the mouse viewport so that we don't hover the viewport _under_ the moved window during the frame we released the mouse button. - if (!IsDragDropPayloadBeingAccepted()) - g.MouseViewport = moving_window->Viewport; - - // Clear the NoInput window flag set by the Viewport system - moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs; // FIXME-VIEWPORT: Test engine managed to crash here because Viewport was NULL. - g.MovingWindow = NULL; ClearActiveID(); } @@ -3743,7 +3629,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame() return; // Click on empty space to focus window and start moving - // (after we're done with all our widgets, so e.g. clicking on docking tab-bar which have set HoveredId already and not get us here!) + // (after we're done with all our widgets) if (g.IO.MouseClicked[0]) { // Handle the edge case of a popup being closed while clicking in its empty space. @@ -3756,10 +3642,9 @@ void ImGui::UpdateMouseMovingWindowEndFrame() StartMouseMovingWindow(g.HoveredWindow); //-V595 // Cancel moving if clicked outside of title bar - if (g.IO.ConfigWindowsMoveFromTitleBarOnly) - if (!(root_window->Flags & ImGuiWindowFlags_NoTitleBar) || root_window->DockIsActive) - if (!root_window->TitleBarRect().Contains(g.IO.MouseClickedPos[0])) - g.MovingWindow = NULL; + if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(root_window->Flags & ImGuiWindowFlags_NoTitleBar)) + if (!root_window->TitleBarRect().Contains(g.IO.MouseClickedPos[0])) + g.MovingWindow = NULL; // Cancel moving if clicked over an item which was disabled or inhibited by popups (note that we know HoveredId == 0 already) if (g.HoveredIdDisabled) @@ -3785,26 +3670,6 @@ void ImGui::UpdateMouseMovingWindowEndFrame() } } -static void TranslateWindow(ImGuiWindow* window, const ImVec2& delta) -{ - window->Pos += delta; - window->ClipRect.Translate(delta); - window->OuterRectClipped.Translate(delta); - window->InnerRect.Translate(delta); - window->DC.CursorPos += delta; - window->DC.CursorStartPos += delta; - window->DC.CursorMaxPos += delta; -} - -static void ScaleWindow(ImGuiWindow* window, float scale) -{ - ImVec2 origin = window->Viewport->Pos; - window->Pos = ImFloor((window->Pos - origin) * scale + origin); - window->Size = ImFloor(window->Size * scale); - window->SizeFull = ImFloor(window->SizeFull * scale); - window->ContentSize = ImFloor(window->ContentSize * scale); -} - static bool IsWindowActiveAndVisible(ImGuiWindow* window) { return (window->Active) && (!window->Hidden); @@ -4012,11 +3877,10 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags() // - We also support the moved window toggling the NoInputs flag after moving has started in order to be able to detect windows below it, which is useful for e.g. docking mechanisms. bool clear_hovered_windows = false; FindHoveredWindow(); - IM_ASSERT(g.HoveredWindow == NULL || g.HoveredWindow == g.MovingWindow || g.HoveredWindow->Viewport == g.MouseViewport); // Modal windows prevents mouse from hovering behind them. ImGuiWindow* modal_window = GetTopMostPopupModal(); - if (modal_window && g.HoveredWindow && !IsWindowChildOf(g.HoveredWindow->RootWindowDockTree, modal_window)) + if (modal_window && g.HoveredWindow && !IsWindowChildOf(g.HoveredWindow->RootWindow, modal_window)) clear_hovered_windows = true; // Disabled mouse? @@ -4089,9 +3953,7 @@ void ImGui::NewFrame() CallContextHooks(&g, ImGuiContextHookType_NewFramePre); // Check and assert for various common IO and Configuration mistakes - g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame; ErrorCheckNewFrameSanityChecks(); - g.ConfigFlagsCurrFrame = g.IO.ConfigFlags; // Load settings on first frame, save settings when modified (after a delay) UpdateSettings(); @@ -4113,7 +3975,6 @@ void ImGui::NewFrame() UpdateViewportsNewFrame(); // Setup current font and draw list shared data - // FIXME-VIEWPORT: the concept of a single ClipRectFullscreen is not ideal! g.IO.Fonts->Locked = true; SetCurrentFont(GetDefaultFont()); IM_ASSERT(g.Font->IsLoaded()); @@ -4137,7 +3998,6 @@ void ImGui::NewFrame() for (int n = 0; n < g.Viewports.Size; n++) { ImGuiViewportP* viewport = g.Viewports[n]; - viewport->DrawData = NULL; viewport->DrawDataP.Clear(); } @@ -4191,14 +4051,6 @@ void ImGui::NewFrame() g.DragDropWithinTarget = false; g.DragDropHoldJustPressedId = 0; - // Clear buttons state when focus is lost - // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle) - if (g.IO.AppFocusLost) - { - g.IO.ClearInputKeys(); - g.IO.AppFocusLost = false; - } - // Update keyboard input state // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools g.IO.KeyMods = GetMergedKeyModFlags(); @@ -4212,10 +4064,6 @@ void ImGui::NewFrame() // Update mouse input state UpdateMouseInputs(); - // Undocking - // (needs to be before UpdateMouseMovingWindowNewFrame so the window is already offset and following the mouse on the detaching frame) - DockContextNewFrameUpdateUndocking(&g); - // Find hovered window // (needs to be before UpdateMouseMovingWindowNewFrame so we fill g.HoveredWindowUnderMovingWindow on the mouse release frame) UpdateHoveredWindowAndCaptureFlags(); @@ -4232,7 +4080,6 @@ void ImGui::NewFrame() g.MouseCursor = ImGuiMouseCursor_Arrow; g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1; g.PlatformImePos = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default - g.PlatformImePosViewport = NULL; // Mouse wheel scrolling, scale UpdateMouseWheel(); @@ -4279,9 +4126,6 @@ void ImGui::NewFrame() g.ItemFlagsStack.push_back(ImGuiItemFlags_None); g.GroupStack.resize(0); - // Docking - DockContextNewFrameUpdateDocking(&g); - // [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack. UpdateDebugToolItemPicker(); @@ -4344,16 +4188,9 @@ void ImGui::Initialize(ImGuiContext* context) // Create default viewport ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); - viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID; - viewport->Idx = 0; - viewport->PlatformWindowCreated = true; - viewport->Flags = ImGuiViewportFlags_OwnedByApp; g.Viewports.push_back(viewport); - g.PlatformIO.Viewports.push_back(g.Viewports[0]); #ifdef IMGUI_HAS_DOCK - // Initialize Docking - DockContextInitialize(&g); #endif g.Initialized = true; @@ -4384,15 +4221,6 @@ void ImGui::Shutdown(ImGuiContext* context) SetCurrentContext(backup_context); } - // Destroy platform windows - ImGuiContext* backup_context = ImGui::GetCurrentContext(); - SetCurrentContext(context); - DestroyPlatformWindows(); - SetCurrentContext(backup_context); - - // Shutdown extensions - DockContextShutdown(&g); - CallContextHooks(&g, ImGuiContextHookType_Shutdown); // Clear everything else @@ -4412,7 +4240,6 @@ void ImGui::Shutdown(ImGuiContext* context) g.OpenPopupStack.clear(); g.BeginPopupStack.clear(); - g.CurrentViewport = g.MouseViewport = g.MouseLastHoveredViewport = NULL; g.Viewports.clear_delete(); g.TabBars.Clear(); @@ -4511,7 +4338,7 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d static void AddWindowToDrawData(ImGuiWindow* window, int layer) { ImGuiContext& g = *GImGui; - ImGuiViewportP* viewport = window->Viewport; + ImGuiViewportP* viewport = g.Viewports[0]; g.IO.MetricsRenderWindows++; AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[layer], window->DrawList); for (int i = 0; i < window->DC.ChildWindows.Size; i++) @@ -4549,24 +4376,15 @@ void ImDrawDataBuilder::FlattenIntoSingleLayer() static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVector* draw_lists) { - // When minimized, we report draw_data->DisplaySize as zero to be consistent with non-viewport mode, - // and to allow applications/backends to easily skip rendering. - // FIXME: Note that we however do NOT attempt to report "zero drawlist / vertices" into the ImDrawData structure. - // This is because the work has been done already, and its wasted! We should fix that and add optimizations for - // it earlier in the pipeline, rather than pretend to hide the data at the end of the pipeline. - const bool is_minimized = (viewport->Flags & ImGuiViewportFlags_Minimized) != 0; - ImGuiIO& io = ImGui::GetIO(); ImDrawData* draw_data = &viewport->DrawDataP; - viewport->DrawData = draw_data; // Make publicly accessible draw_data->Valid = true; draw_data->CmdLists = (draw_lists->Size > 0) ? draw_lists->Data : NULL; draw_data->CmdListsCount = draw_lists->Size; draw_data->TotalVtxCount = draw_data->TotalIdxCount = 0; draw_data->DisplayPos = viewport->Pos; - draw_data->DisplaySize = is_minimized ? ImVec2(0.0f, 0.0f) : viewport->Size; - draw_data->FramebufferScale = io.DisplayFramebufferScale; // FIXME-VIEWPORT: This may vary on a per-monitor/viewport basis? - draw_data->OwnerViewport = viewport; + draw_data->DisplaySize = viewport->Size; + draw_data->FramebufferScale = io.DisplayFramebufferScale; for (int n = 0; n < draw_lists->Size; n++) { draw_data->TotalVtxCount += draw_lists->Data[n]->VtxBuffer.Size; @@ -4594,69 +4412,6 @@ void ImGui::PopClipRect() window->ClipRect = window->DrawList->_ClipRectStack.back(); } -static ImGuiWindow* FindFrontMostVisibleChildWindow(ImGuiWindow* window) -{ - for (int n = window->DC.ChildWindows.Size - 1; n >= 0; n--) - if (IsWindowActiveAndVisible(window->DC.ChildWindows[n])) - return FindFrontMostVisibleChildWindow(window->DC.ChildWindows[n]); - return window; -} - -static void ImGui::EndFrameDrawDimmedBackgrounds() -{ - ImGuiContext& g = *GImGui; - - // Draw modal whitening background on _other_ viewports than the one the modal is one - ImGuiWindow* modal_window = GetTopMostPopupModal(); - const bool dim_bg_for_modal = (modal_window != NULL); - const bool dim_bg_for_window_list = (g.NavWindowingTargetAnim != NULL); - if (dim_bg_for_modal || dim_bg_for_window_list) - for (int viewport_n = 0; viewport_n < g.Viewports.Size; viewport_n++) - { - ImGuiViewportP* viewport = g.Viewports[viewport_n]; - if (modal_window && viewport == modal_window->Viewport) - continue; - if (g.NavWindowingListWindow && viewport == g.NavWindowingListWindow->Viewport) - continue; - if (g.NavWindowingTargetAnim && viewport == g.NavWindowingTargetAnim->Viewport) - continue; - if (viewport->Window && modal_window && IsWindowAbove(viewport->Window, modal_window)) - continue; - ImDrawList* draw_list = GetForegroundDrawList(viewport); - const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio); - draw_list->AddRectFilled(viewport->Pos, viewport->Pos + viewport->Size, dim_bg_col); - } - - // Draw modal whitening background between CTRL-TAB list - if (dim_bg_for_window_list && g.NavWindowingTargetAnim->Active) - { - // Choose a draw list that will be front-most across all our children - // In the unlikely case that the window wasn't made active we can't rely on its drawlist and skip rendering all-together. - ImGuiWindow* window = g.NavWindowingTargetAnim; - ImDrawList* draw_list = FindFrontMostVisibleChildWindow(window->RootWindowDockTree)->DrawList; - draw_list->PushClipRectFullScreen(); - - // Docking: draw modal whitening background on other nodes of a same dock tree - // For CTRL+TAB within a docking node we need to render the dimming background in 8 steps - // (Because the root node renders the background in one shot, in order to avoid flickering when a child dock node is not submitted) - if (window->RootWindow->DockIsActive) - if (window->RootWindowDockTree != window->RootWindow) - RenderRectFilledWithHole(draw_list, window->RootWindowDockTree->Rect(), window->RootWindow->Rect(), GetColorU32(ImGuiCol_NavWindowingDimBg, g.DimBgRatio), g.Style.WindowRounding); - - // Draw navigation selection/windowing rectangle border - float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding); - ImRect bb = window->Rect(); - bb.Expand(g.FontSize); - if (bb.Contains(window->Viewport->GetMainRect())) // If a window fits the entire viewport, adjust its highlight inward - { - bb.Expand(-g.FontSize - 1.0f); - rounding = window->WindowRounding; - } - draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha), rounding, 0, 3.0f); - draw_list->PopClipRect(); - } -} - // This is normally called by Render(). You may want to call it directly if you want to avoid calling Render() but the gain will be very minimal. void ImGui::EndFrame() { @@ -4673,13 +4428,11 @@ void ImGui::EndFrame() ErrorCheckEndFrameSanityChecks(); // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) - if (g.PlatformIO.Platform_SetImeInputPos && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImePos - g.PlatformImeLastPos) > 0.0001f)) - if (g.PlatformImePosViewport && g.PlatformImePosViewport->PlatformWindowCreated) - { - g.PlatformIO.Platform_SetImeInputPos(g.PlatformImePosViewport, g.PlatformImePos); - g.PlatformImeLastPos = g.PlatformImePos; - g.PlatformImePosViewport = NULL; - } + if (g.IO.ImeSetInputScreenPosFn && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImeLastPos - g.PlatformImePos) > 0.0001f)) + { + g.IO.ImeSetInputScreenPosFn((int)g.PlatformImePos.x, (int)g.PlatformImePos.y); + g.PlatformImeLastPos = g.PlatformImePos; + } // Hide implicit/fallback "Debug" window if it hasn't been used g.WithinFrameScopeWithImplicitWindow = false; @@ -4687,14 +4440,9 @@ void ImGui::EndFrame() g.CurrentWindow->Active = false; End(); - // Draw modal whitening background on _other_ viewports than the one the modal is one - EndFrameDrawDimmedBackgrounds(); - // Update navigation: CTRL+Tab, wrap-around requests NavEndFrame(); - SetCurrentViewport(NULL, NULL); - // Drag and Drop: Elapse payload (if delivered, or if source stops being submitted) if (g.DragDropActive) { @@ -4719,9 +4467,6 @@ void ImGui::EndFrame() // Initiate moving window + handle left-click and right-click focus UpdateMouseMovingWindowEndFrame(); - // Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some) - UpdateViewportsEndFrame(); - // Sort the window list so that all child windows are after their parent // We cannot do that on FocusWindow() because children may not exist yet g.WindowsTempSortBuffer.resize(0); @@ -4777,7 +4522,7 @@ void ImGui::Render() // Add ImDrawList to render ImGuiWindow* windows_to_render_top_most[2]; - windows_to_render_top_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindowDockTree : NULL; + windows_to_render_top_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL; windows_to_render_top_most[1] = (g.NavWindowingTarget ? g.NavWindowingListWindow : NULL); for (int n = 0; n != g.Windows.Size; n++) { @@ -4790,10 +4535,6 @@ void ImGui::Render() if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the top-most window AddRootWindowToDrawData(windows_to_render_top_most[n]); - ImVec2 mouse_cursor_offset, mouse_cursor_size, mouse_cursor_uv[4]; - if (g.IO.MouseDrawCursor && g.MouseCursor != ImGuiMouseCursor_None) - g.IO.Fonts->GetMouseCursorTexData(g.MouseCursor, &mouse_cursor_offset, &mouse_cursor_size, &mouse_cursor_uv[0], &mouse_cursor_uv[2]); - // Setup ImDrawData structures for end-user g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = 0; for (int n = 0; n < g.Viewports.Size; n++) @@ -4802,20 +4543,15 @@ void ImGui::Render() viewport->DrawDataBuilder.FlattenIntoSingleLayer(); // Draw software mouse cursor if requested by io.MouseDrawCursor flag - // (note we scale cursor by current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor) - if (mouse_cursor_size.x > 0.0f && mouse_cursor_size.y > 0.0f) - { - float scale = g.Style.MouseCursorScale * viewport->DpiScale; - if (viewport->GetMainRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale))) - RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, scale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); - } + if (g.IO.MouseDrawCursor) + RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); // Add foreground ImDrawList (for each active viewport) if (viewport->DrawLists[1] != NULL) AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetForegroundDrawList(viewport)); SetupViewportDrawData(viewport, &viewport->DrawDataBuilder.Layers[0]); - ImDrawData* draw_data = viewport->DrawData; + ImDrawData* draw_data = &viewport->DrawDataP; g.IO.MetricsRenderVertices += draw_data->TotalVtxCount; g.IO.MetricsRenderIndices += draw_data->TotalIdxCount; } @@ -4859,11 +4595,6 @@ static void FindHoveredWindow() { ImGuiContext& g = *GImGui; - // Special handling for the window being moved: Ignore the mouse viewport check (because it may reset/lose its viewport during the undocking frame) - ImGuiViewportP* moving_window_viewport = g.MovingWindow ? g.MovingWindow->Viewport : NULL; - if (g.MovingWindow) - g.MovingWindow->Viewport = g.MouseViewport; - ImGuiWindow* hovered_window = NULL; ImGuiWindow* hovered_window_ignoring_moving_window = NULL; if (g.MovingWindow && !(g.MovingWindow->Flags & ImGuiWindowFlags_NoMouseInputs)) @@ -4879,9 +4610,6 @@ static void FindHoveredWindow() continue; if (window->Flags & ImGuiWindowFlags_NoMouseInputs) continue; - IM_ASSERT(window->Viewport); - if (window->Viewport != g.MouseViewport) - continue; // Using the clipped AABB, a child window will typically be clipped by its parent (not always) ImRect bb(window->OuterRectClipped); @@ -4905,7 +4633,7 @@ static void FindHoveredWindow() if (hovered_window == NULL) hovered_window = window; IM_MSVC_WARNING_SUPPRESS(28182); // [Static Analyzer] Dereferencing NULL pointer. - if (hovered_window_ignoring_moving_window == NULL && (!g.MovingWindow || window->RootWindowDockTree != g.MovingWindow->RootWindowDockTree)) + if (hovered_window_ignoring_moving_window == NULL && (!g.MovingWindow || window->RootWindow != g.MovingWindow->RootWindow)) hovered_window_ignoring_moving_window = window; if (hovered_window && hovered_window_ignoring_moving_window) break; @@ -4913,9 +4641,6 @@ static void FindHoveredWindow() g.HoveredWindow = hovered_window; g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window; - - if (g.MovingWindow) - g.MovingWindow->Viewport = moving_window_viewport; } // Test if mouse cursor is hovering given rectangle @@ -4934,8 +4659,6 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); if (!rect_for_touch.Contains(g.IO.MousePos)) return false; - if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) - return false; return true; } @@ -5182,13 +4905,6 @@ bool ImGui::IsItemFocused() ImGuiContext& g = *GImGui; if (g.NavId != g.LastItemData.ID || g.NavId == 0) return false; - - // Special handling for the dummy item after Begin() which represent the title bar or tab. - // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case. - ImGuiWindow* window = g.CurrentWindow; - if (g.LastItemData.ID == window->ID && window->WriteAccessed) - return false; - return true; } @@ -5296,7 +5012,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b ImGuiContext& g = *GImGui; ImGuiWindow* parent_window = g.CurrentWindow; - flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoDocking; + flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow; flags |= (parent_window->Flags & ImGuiWindowFlags_NoMove); // Inherit the NoMove flag // Size @@ -5424,7 +5140,6 @@ static void SetWindowConditionAllowFlags(ImGuiWindow* window, ImGuiCond flags, b window->SetWindowPosAllowFlags = enabled ? (window->SetWindowPosAllowFlags | flags) : (window->SetWindowPosAllowFlags & ~flags); window->SetWindowSizeAllowFlags = enabled ? (window->SetWindowSizeAllowFlags | flags) : (window->SetWindowSizeAllowFlags & ~flags); window->SetWindowCollapsedAllowFlags = enabled ? (window->SetWindowCollapsedAllowFlags | flags) : (window->SetWindowCollapsedAllowFlags & ~flags); - window->SetWindowDockAllowFlags = enabled ? (window->SetWindowDockAllowFlags | flags) : (window->SetWindowDockAllowFlags & ~flags); } ImGuiWindow* ImGui::FindWindowByID(ImGuiID id) @@ -5441,19 +5156,10 @@ ImGuiWindow* ImGui::FindWindowByName(const char* name) static void ApplyWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* settings) { - const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); - window->ViewportPos = main_viewport->Pos; - if (settings->ViewportId) - { - window->ViewportId = settings->ViewportId; - window->ViewportPos = ImVec2(settings->ViewportPos.x, settings->ViewportPos.y); - } - window->Pos = ImFloor(ImVec2(settings->Pos.x + window->ViewportPos.x, settings->Pos.y + window->ViewportPos.y)); + window->Pos = ImFloor(ImVec2(settings->Pos.x, settings->Pos.y)); if (settings->Size.x > 0 && settings->Size.y > 0) window->Size = window->SizeFull = ImFloor(ImVec2(settings->Size.x, settings->Size.y)); window->Collapsed = settings->Collapsed; - window->DockId = settings->DockId; - window->DockOrder = settings->DockOrder; } static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) @@ -5469,7 +5175,6 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) // Default/arbitrary window position. Use SetNextWindowPos() with the appropriate condition flag to change the initial position of a window. const ImGuiViewport* main_viewport = ImGui::GetMainViewport(); window->Pos = main_viewport->Pos + ImVec2(60, 60); - window->ViewportPos = main_viewport->Pos; // User can disable loading and saving of settings. Tooltip and child windows also don't store settings. if (!(flags & ImGuiWindowFlags_NoSavedSettings)) @@ -5509,16 +5214,6 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) return window; } -static ImGuiWindow* GetWindowForTitleDisplay(ImGuiWindow* window) -{ - return window->DockNodeAsHost ? window->DockNodeAsHost->VisibleWindow : window; -} - -static ImGuiWindow* GetWindowForTitleAndMenuHeight(ImGuiWindow* window) -{ - return (window->DockNodeAsHost && window->DockNodeAsHost->VisibleWindow) ? window->DockNodeAsHost->VisibleWindow : window; -} - static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& size_desired) { ImGuiContext& g = *GImGui; @@ -5546,7 +5241,7 @@ static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, const ImVec2& s // Minimum size if (!(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize))) { - ImGuiWindow* window_for_height = GetWindowForTitleAndMenuHeight(window); + ImGuiWindow* window_for_height = window; const float decoration_up_height = window_for_height->TitleBarHeight() + window_for_height->MenuBarHeight(); new_size = ImMax(new_size, g.Style.WindowMinSize); new_size.y = ImMax(new_size.y, decoration_up_height + ImMax(0.0f, g.Style.WindowRounding - 1.0f)); // Reduce artifacts with very small windows @@ -5596,12 +5291,7 @@ static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_cont size_min = ImMin(size_min, ImVec2(4.0f, 4.0f)); // FIXME-VIEWPORT-WORKAREA: May want to use GetWorkSize() instead of Size depending on the type of windows? - ImVec2 avail_size = window->Viewport->Size; - if (window->ViewportOwned) - avail_size = ImVec2(FLT_MAX, FLT_MAX); - const int monitor_idx = window->ViewportAllowPlatformMonitorExtend; - if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size) - avail_size = g.PlatformIO.Monitors[monitor_idx].WorkSize; + ImVec2 avail_size = ImGui::GetMainViewport()->Size; ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - style.DisplaySafeAreaPadding * 2.0f)); // When the window cannot fit all contents (either because of constraints, either because screen is too small), @@ -5697,7 +5387,7 @@ static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_ ImGuiID ImGui::GetWindowResizeCornerID(ImGuiWindow* window, int n) { IM_ASSERT(n >= 0 && n < 4); - ImGuiID id = window->DockIsActive ? window->DockNode->HostWindow->ID : window->ID; + ImGuiID id = window->ID; id = ImHashStr("#RESIZE", 0, id); id = ImHashData(&n, sizeof(int), id); return id; @@ -5708,7 +5398,7 @@ ImGuiID ImGui::GetWindowResizeBorderID(ImGuiWindow* window, ImGuiDir dir) { IM_ASSERT(dir >= 0 && dir < 4); int n = (int)dir + 4; - ImGuiID id = window->DockIsActive ? window->DockNode->HostWindow->ID : window->ID; + ImGuiID id = window->ID; id = ImHashStr("#RESIZE", 0, id); id = ImHashData(&n, sizeof(int), id); return id; @@ -5735,16 +5425,6 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s ImVec2 pos_target(FLT_MAX, FLT_MAX); ImVec2 size_target(FLT_MAX, FLT_MAX); - // Clip mouse interaction rectangles within the viewport rectangle (in practice the narrowing is going to happen most of the time). - // - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits. - // This is however not the case with current backends under Win32, but a custom borderless window implementation would benefit from it. - // - When decoration are enabled we typically benefit from that distance, but then our resize elements would be conflicting with OS resize elements, so we also narrow. - // - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold). - // We only clip interaction so we overwrite window->ClipRect, cannot call PushClipRect() yet as DrawList is not yet setup. - const bool clip_with_viewport_rect = !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration); - if (clip_with_viewport_rect) - window->ClipRect = window->Viewport->GetMainRect(); - // Resize grips and borders are on layer 1 window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; @@ -5820,7 +5500,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s window->DC.NavLayerCurrent = ImGuiNavLayer_Main; // Navigation resize (keyboard/gamepad) - if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindowDockTree == window) + if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window) { ImVec2 nav_resize_delta; if (g.NavInputSource == ImGuiInputSource_Keyboard && g.IO.KeyShift) @@ -5882,7 +5562,7 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window) window->DrawList->PathArcTo(ImLerp(border_r.Min, border_r.Max, def.SegmentN2) + ImVec2(0.5f, 0.5f) + def.InnerDir * rounding, rounding, def.OuterAngle, def.OuterAngle + IM_PI * 0.25f); window->DrawList->PathStroke(GetColorU32(ImGuiCol_SeparatorActive), 0, ImMax(2.0f, border_size)); // Thicker than usual } - if (g.Style.FrameBorderSize > 0 && !(window->Flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive) + if (g.Style.FrameBorderSize > 0 && !(window->Flags & ImGuiWindowFlags_NoTitleBar)) { float y = window->Pos.y + window->TitleBarHeight() - 1; window->DrawList->AddLine(ImVec2(window->Pos.x + border_size, y), ImVec2(window->Pos.x + window->Size.x - border_size, y), GetColorU32(ImGuiCol_Border), g.Style.FrameBorderSize); @@ -5891,7 +5571,7 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window) // Draw background and borders // Draw and handle scrollbars -void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size) +void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size) { ImGuiContext& g = *GImGui; ImGuiStyle& style = g.Style; @@ -5919,44 +5599,21 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar // Window background if (!(flags & ImGuiWindowFlags_NoBackground)) { - bool is_docking_transparent_payload = false; - if (g.DragDropActive && (g.FrameCount - g.DragDropAcceptFrameCount) <= 1 && g.IO.ConfigDockingTransparentPayload) - if (g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && *(ImGuiWindow**)g.DragDropPayload.Data == window) - is_docking_transparent_payload = true; - ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags)); - if (window->ViewportOwned) + bool override_alpha = false; + float alpha = 1.0f; + if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasBgAlpha) { - // No alpha - bg_col = (bg_col | IM_COL32_A_MASK); - if (is_docking_transparent_payload) - window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA; - } - else - { - // Adjust alpha. For docking - bool override_alpha = false; - float alpha = 1.0f; - if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasBgAlpha) - { - alpha = g.NextWindowData.BgAlphaVal; - override_alpha = true; - } - if (is_docking_transparent_payload) - { - alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA; // FIXME-DOCK: Should that be an override? - override_alpha = true; - } - if (override_alpha) - bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT); + alpha = g.NextWindowData.BgAlphaVal; + override_alpha = true; } + if (override_alpha) + bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT); window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom); } // Title bar - // (when docked, DockNode are drawing their own title bar. Individual windows however do NOT set the _NoTitleBar flag, - // in order for their pos/size to be matching their undocking state.) - if (!(flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive) + if (!(flags & ImGuiWindowFlags_NoTitleBar)) { ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg); window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawFlags_RoundCornersTop); @@ -5972,25 +5629,6 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize); } - // Docking: Unhide tab bar (small triangle in the corner), drag from small triangle to quickly undock - ImGuiDockNode* node = window->DockNode; - if (window->DockIsActive && node->IsHiddenTabBar() && !node->IsNoTabBar()) - { - float unhide_sz_draw = ImFloor(g.FontSize * 0.70f); - float unhide_sz_hit = ImFloor(g.FontSize * 0.55f); - ImVec2 p = node->Pos; - ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit)); - bool hovered, held; - if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren)) - node->WantHiddenTabBarToggle = true; - else if (held && IsMouseDragging(0)) - StartMouseMovingWindowOrNode(window, node, true); - - // FIXME-DOCK: Ideally we'd use ImGuiCol_TitleBgActive/ImGuiCol_TitleBg here, but neither is guaranteed to be visible enough at this sort of size.. - ImU32 col = GetColorU32(((held && hovered) || (node->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); - window->DrawList->AddTriangleFilled(p, p + ImVec2(unhide_sz_draw, 0.0f), p + ImVec2(0.0f, unhide_sz_draw), col); - } - // Scrollbars if (window->ScrollbarX) Scrollbar(ImGuiAxis_X); @@ -5998,7 +5636,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar Scrollbar(ImGuiAxis_Y); // Render resize grips (after their input handling so we don't have a frame of latency) - if (handle_borders_and_resize_grips && !(flags & ImGuiWindowFlags_NoResize)) + if (!(flags & ImGuiWindowFlags_NoResize)) { for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++) { @@ -6011,14 +5649,12 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar } } - // Borders (for dock node host they will be rendered over after the tab bar) - if (handle_borders_and_resize_grips && !window->DockNodeAsHost) - RenderWindowOuterBorders(window); + // Borders + RenderWindowOuterBorders(window); } } // Render title text, collapse button, close button -// When inside a dock node, this is handled in DockNodeCalcTabBarLayout() instead. void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open) { ImGuiContext& g = *GImGui; @@ -6058,7 +5694,7 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl // Collapse button (submitting first so it gets priority when choosing a navigation init fallback) if (has_collapse_button) - if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos, NULL)) + if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos)) window->WantCollapseToggle = true; // Defer actual collapsing to next frame as we are too far in the Begin() function // Close button @@ -6109,13 +5745,9 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window) { window->ParentWindow = parent_window; - window->RootWindow = window->RootWindowDockTree = window->RootWindowForTitleBarHighlight = window->RootWindowForNav = window; + window->RootWindow = window->RootWindowForTitleBarHighlight = window->RootWindowForNav = window; if (parent_window && (flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Tooltip)) - { - window->RootWindowDockTree = parent_window->RootWindowDockTree; - if (!window->DockIsActive && !(parent_window->Flags & ImGuiWindowFlags_DockNodeHost)) - window->RootWindow = parent_window->RootWindow; - } + window->RootWindow = parent_window->RootWindow; if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) window->RootWindowForTitleBarHighlight = parent_window->RootWindowForTitleBarHighlight; while (window->RootWindowForNav->Flags & ImGuiWindowFlags_NavFlattened) @@ -6157,24 +5789,21 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const bool first_begin_of_the_frame = (window->LastFrameActive != current_frame); window->IsFallbackWindow = (g.CurrentWindowStack.Size == 0 && g.WithinFrameScopeWithImplicitWindow); - // Update the Appearing flag (note: the BeginDocked() path may also set this to true later) - bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on + // Update the Appearing flag + bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on if (flags & ImGuiWindowFlags_Popup) { ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size]; window_just_activated_by_user |= (window->PopupId != popup_ref.PopupId); // We recycle popups so treat window as activated if popup id changed window_just_activated_by_user |= (window != popup_ref.Window); } + window->Appearing = window_just_activated_by_user; + if (window->Appearing) + SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); // Update Flags, LastFrameActive, BeginOrderXXX fields - const bool window_was_appearing = window->Appearing; if (first_begin_of_the_frame) { - window->Appearing = window_just_activated_by_user; - if (window->Appearing) - SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); - - window->FlagsPreviousFrame = window->Flags; window->Flags = (ImGuiWindowFlags)flags; window->LastFrameActive = current_frame; window->LastTimeActive = (float)g.Time; @@ -6186,42 +5815,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) flags = window->Flags; } - // Docking - // (NB: during the frame dock nodes are created, it is possible that (window->DockIsActive == false) even though (window->DockNode->Windows.Size > 1) - IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL); // Cannot be both - if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasDock) - SetWindowDock(window, g.NextWindowData.DockId, g.NextWindowData.DockCond); - if (first_begin_of_the_frame) - { - bool has_dock_node = (window->DockId != 0 || window->DockNode != NULL); - bool new_auto_dock_node = !has_dock_node && GetWindowAlwaysWantOwnTabBar(window); - bool dock_node_was_visible = window->DockNodeIsVisible; - bool dock_tab_was_visible = window->DockTabIsVisible; - if (has_dock_node || new_auto_dock_node) - { - BeginDocked(window, p_open); - flags = window->Flags; - if (window->DockIsActive) - IM_ASSERT(window->DockNode != NULL); - - // Docking currently override constraints - g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint; - - // Amend the Appearing flag - if (window->DockTabIsVisible && !dock_tab_was_visible && dock_node_was_visible && !window->Appearing && !window_was_appearing) - { - window->Appearing = true; - SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); - } - } - else - { - window->DockIsActive = window->DockNodeIsVisible = window->DockTabIsVisible = false; - } - } - // Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack - ImGuiWindow* parent_window_in_stack = window->DockIsActive ? window->DockNode->HostWindow : g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; + ImGuiWindow* parent_window_in_stack = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow; IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow)); @@ -6294,8 +5889,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->ContentSizeExplicit = g.NextWindowData.ContentSizeVal; else if (first_begin_of_the_frame) window->ContentSizeExplicit = ImVec2(0.0f, 0.0f); - if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasWindowClass) - window->WindowClass = g.NextWindowData.WindowClass; if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasCollapsed) SetWindowCollapsed(window, g.NextWindowData.CollapsedVal, g.NextWindowData.CollapsedCond); if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasFocus) @@ -6322,9 +5915,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Update stored window name when it changes (which can _only_ happen with the "###" operator, so the ID would stay unchanged). // The title bar always display the 'name' parameter, so we only update the string storage if it needs to be visible to the end-user elsewhere. bool window_title_visible_elsewhere = false; - if ((window->Viewport && window->Viewport->Window == window) || (window->DockIsActive)) - window_title_visible_elsewhere = true; - else if (g.NavWindowingListWindow != NULL && (window->Flags & ImGuiWindowFlags_NoNavFocus) == 0) // Window titles visible when using CTRL+TAB + if (g.NavWindowingListWindow != NULL && (window->Flags & ImGuiWindowFlags_NoNavFocus) == 0) // Window titles visible when using CTRL+TAB window_title_visible_elsewhere = true; if (window_title_visible_elsewhere && !window_just_created && strcmp(name, window->Name) != 0) { @@ -6338,10 +5929,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Update contents size from last frame for auto-fitting (or use explicit size) const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0); CalcWindowContentSizes(window, &window->ContentSize, &window->ContentSizeIdeal); - - // FIXME: These flags are decremented before they are used. This means that in order to have these fields produce their intended behaviors - // for one frame we must set them to at least 2, which is counter-intuitive. HiddenFramesCannotSkipItems is a more complicated case because - // it has a single usage before this code block and may be set below before it is finally checked. if (window->HiddenFramesCanSkipItems > 0) window->HiddenFramesCanSkipItems--; if (window->HiddenFramesCannotSkipItems > 0) @@ -6369,25 +5956,18 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } // SELECT VIEWPORT - // We need to do this before using any style/font sizes, as viewport with a different DPI may affect font sizes. - - WindowSelectViewport(window); - SetCurrentViewport(window, window->Viewport); - window->FontDpiScale = (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleFonts) ? window->Viewport->DpiScale : 1.0f; + // FIXME-VIEWPORT: In the docking/viewport branch, this is the point where we select the current viewport (which may affect the style) SetCurrentWindow(window); - flags = window->Flags; // LOCK BORDER SIZE AND PADDING FOR THE FRAME (so that altering them doesn't cause inconsistencies) - // We read Style data after the call to UpdateSelectWindowViewport() which might be swapping the style. if (flags & ImGuiWindowFlags_ChildWindow) window->WindowBorderSize = style.ChildBorderSize; else window->WindowBorderSize = ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupBorderSize : style.WindowBorderSize; - if (!window->DockIsActive && (flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f) + window->WindowPadding = style.WindowPadding; + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f) window->WindowPadding = ImVec2(0.0f, (flags & ImGuiWindowFlags_MenuBar) ? style.WindowPadding.y : 0.0f); - else - window->WindowPadding = style.WindowPadding; // Lock menu offset so size calculation can use it as menu-bar windows need a minimum size. window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x); @@ -6395,7 +5975,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Collapse window by double-clicking on title bar // At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing - if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse) && !window->DockIsActive) + if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse)) { // We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar. ImRect title_bar_rect = window->TitleBarRect(); @@ -6488,57 +6068,24 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) else if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api && !window_is_child_tooltip) window->Pos = FindBestWindowPosForPopup(window); - // Late create viewport if we don't fit within our current host viewport. - if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_Minimized)) - if (!window->Viewport->GetMainRect().Contains(window->Rect())) - { - // This is based on the assumption that the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport) - //ImGuiViewport* old_viewport = window->Viewport; - window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing); - - // FIXME-DPI - //IM_ASSERT(old_viewport->DpiScale == window->Viewport->DpiScale); // FIXME-DPI: Something went wrong - SetCurrentViewport(window, window->Viewport); - window->FontDpiScale = (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleFonts) ? window->Viewport->DpiScale : 1.0f; - SetCurrentWindow(window); - } - - if (window->ViewportOwned) - WindowSyncOwnedViewport(window, parent_window_in_stack); - // Calculate the range of allowed position for that window (to be movable and visible past safe area padding) // When clamping to stay visible, we will enforce that window->Pos stays inside of visibility_rect. - ImRect viewport_rect(window->Viewport->GetMainRect()); - ImRect viewport_work_rect(window->Viewport->GetWorkRect()); + ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)GetMainViewport(); + ImRect viewport_rect(viewport->GetMainRect()); + ImRect viewport_work_rect(viewport->GetWorkRect()); ImVec2 visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding); ImRect visibility_rect(viewport_work_rect.Min + visibility_padding, viewport_work_rect.Max - visibility_padding); // Clamp position/size so window stays visible within its viewport or monitor // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. - // FIXME: Similar to code in GetWindowAllowedExtentRect() if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) - { - if (!window->ViewportOwned && viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f) - { + if (viewport_rect.GetWidth() > 0.0f && viewport_rect.GetHeight() > 0.0f) ClampWindowRect(window, visibility_rect); - } - else if (window->ViewportOwned && g.PlatformIO.Monitors.Size > 0) - { - // Lost windows (e.g. a monitor disconnected) will naturally moved to the fallback/dummy monitor aka the main viewport. - const ImGuiPlatformMonitor* monitor = GetViewportPlatformMonitor(window->Viewport); - visibility_rect.Min = monitor->WorkPos + visibility_padding; - visibility_rect.Max = monitor->WorkPos + monitor->WorkSize - visibility_padding; - ClampWindowRect(window, visibility_rect); - } - } window->Pos = ImFloor(window->Pos); // Lock window rounding for the frame (so that altering them doesn't cause inconsistencies) // Large values tend to lead to variety of artifacts and are not recommended. - if (window->ViewportOwned || window->DockIsActive) - window->WindowRounding = 0.0f; - else - window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; + window->WindowRounding = (flags & ImGuiWindowFlags_ChildWindow) ? style.ChildRounding : ((flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiWindowFlags_Modal)) ? style.PopupRounding : style.WindowRounding; // For windows with title bar or menu bar, we clamp to FrameHeight(FontSize + FramePadding.y * 2.0f) to completely hide artifacts. //if ((window->Flags & ImGuiWindowFlags_MenuBar) || !(window->Flags & ImGuiWindowFlags_NoTitleBar)) @@ -6550,37 +6097,20 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { if (flags & ImGuiWindowFlags_Popup) want_focus = true; - else if ((window->DockIsActive || (flags & ImGuiWindowFlags_ChildWindow) == 0) && !(flags & ImGuiWindowFlags_Tooltip)) + else if ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) want_focus = true; } - // Decide if we are going to handle borders and resize grips - const bool handle_borders_and_resize_grips = (window->DockNodeAsHost || !window->DockIsActive); - // Handle manual resize: Resize Grips, Borders, Gamepad int border_held = -1; ImU32 resize_grip_col[4] = {}; const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it. const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.10f, window->WindowRounding + 1.0f + g.FontSize * 0.2f)); - if (handle_borders_and_resize_grips && !window->Collapsed) + if (!window->Collapsed) if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0], visibility_rect)) use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true; window->ResizeBorderHeld = (signed char)border_held; - // Synchronize window --> viewport again and one last time (clamping and manual resize may have affected either) - if (window->ViewportOwned) - { - if (!window->Viewport->PlatformRequestMove) - window->Viewport->Pos = window->Pos; - if (!window->Viewport->PlatformRequestResize) - window->Viewport->Size = window->Size; - window->Viewport->UpdateWorkRect(); - viewport_rect = window->Viewport->GetMainRect(); - } - - // Save last known viewport position within the window itself (so it can be saved in .ini file and restored) - window->ViewportPos = window->Viewport->Pos; - // SCROLLBAR VISIBILITY // Update scrollbar visibility (based on the Size that was effective during last frame or the auto-resized Size). @@ -6614,8 +6144,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const ImRect outer_rect = window->Rect(); const ImRect title_bar_rect = window->TitleBarRect(); window->OuterRectClipped = outer_rect; - if (window->DockIsActive) - window->OuterRectClipped.Min.y += window->TitleBarHeight(); window->OuterRectClipped.ClipWith(host_rect); // Inner rectangle @@ -6668,10 +6196,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID); PushClipRect(host_rect.Min, host_rect.Max, false); - // Draw modal or window list full viewport dimming background (for other viewports we'll render them in EndFrame) - ImGuiWindow* window_window_list = g.NavWindowingListWindow; + // Draw modal window background (darkens what is behind them, all viewports) const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetTopMostPopupModal() && window->HiddenFramesCannotSkipItems <= 0; - const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && ((window == g.NavWindowingTargetAnim->RootWindowDockTree) || (window == window_window_list && window_window_list->Viewport != g.NavWindowingTargetAnim->Viewport)); + const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && (window == g.NavWindowingTargetAnim->RootWindow); if (dim_bg_for_modal || dim_bg_for_window_list) { const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio); @@ -6692,8 +6219,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping child. // We also disabled this when we have dimming overlay behind this specific one child. // FIXME: More code may rely on explicit sorting of overlapping child window and would need to disable this somehow. Please get in contact if you are affected. - const bool is_undocked_or_docked_visible = !window->DockIsActive || window->DockTabIsVisible; - if (is_undocked_or_docked_visible) { bool render_decorations_in_parent = false; if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) @@ -6704,8 +6229,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Handle title bar, scrollbar, resize grips and resize borders const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow; - const bool title_bar_is_highlight = want_focus || (window_to_highlight && (window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight || (window->DockNode && window->DockNode == window_to_highlight->DockNode))); - RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, handle_borders_and_resize_grips, resize_grip_count, resize_grip_col, resize_grip_draw_size); + const bool title_bar_is_highlight = want_focus || (window_to_highlight && window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight); + RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, resize_grip_count, resize_grip_col, resize_grip_draw_size); if (render_decorations_in_parent) window->DrawList = &window->DrawListInst; @@ -6798,20 +6323,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) NavInitWindow(window, false); // <-- this is in the way for us to be able to defer and sort reappearing FocusWindow() calls } - // Close requested by platform window - if (p_open != NULL && window->Viewport->PlatformRequestClose && window->Viewport != GetMainViewport()) - { - if (!window->DockIsActive || window->DockTabIsVisible) - { - window->Viewport->PlatformRequestClose = false; - g.NavWindowingToggleLayer = false; // Assume user mapped PlatformRequestClose on ALT-F4 so we disable ALT for menu toggle. False positive not an issue. - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' PlatformRequestClose\n", window->Name); - *p_open = false; - } - } - // Title bar - if (!(flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive) + if (!(flags & ImGuiWindowFlags_NoTitleBar)) RenderWindowTitleBarContents(window, ImRect(title_bar_rect.Min.x + window->WindowBorderSize, title_bar_rect.Min.y, title_bar_rect.Max.x - window->WindowBorderSize, title_bar_rect.Max.y), name, p_open); // Clear hit test shape every frame @@ -6827,27 +6340,12 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) LogToClipboard(); */ - if (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - // Docking: Dragging a dockable window (or any of its child) turns it into a drag and drop source. - // We need to do this _before_ we overwrite window->DC.LastItemId below because BeginDockableDragDropSource() also overwrites it. - if (g.MovingWindow == window && g.IO.KeyShift == false) - if ((window->RootWindowDockTree->Flags & ImGuiWindowFlags_NoDocking) == 0) - BeginDockableDragDropSource(window); - - // Docking: Any dockable window can act as a target. For dock node hosts we call BeginDockableDragDropTarget() in DockNodeUpdate() instead. - if (g.DragDropActive && !(flags & ImGuiWindowFlags_NoDocking)) - if (g.MovingWindow == NULL || g.MovingWindow->RootWindowDockTree != window) - if ((window == window->RootWindowDockTree) && !(window->Flags & ImGuiWindowFlags_DockNodeHost)) - BeginDockableDragDropTarget(window); - } - // We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin(). // This is useful to allow creating context menus on title bar only, etc. - if (window->DockIsActive) - SetLastItemData(window->ID, g.CurrentItemFlags, window->DockTabItemStatusFlags, window->DockTabItemRect); - else - SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, title_bar_rect); + g.LastItemData.ID = window->MoveId; + g.LastItemData.InFlags = g.CurrentItemFlags; + g.LastItemData.StatusFlags = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0; + g.LastItemData.Rect = title_bar_rect; #ifdef IMGUI_ENABLE_TEST_ENGINE if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) @@ -6857,15 +6355,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) else { // Append - SetCurrentViewport(window, window->Viewport); SetCurrentWindow(window); } // Pull/inherit current state window->DC.NavFocusScopeIdCurrent = (flags & ImGuiWindowFlags_ChildWindow) ? parent_window->DC.NavFocusScopeIdCurrent : window->GetID("#FOCUSSCOPE"); // Inherit from parent only // -V595 - if (!(flags & ImGuiWindowFlags_DockNodeHost)) - PushClipRect(window->InnerClipRect.Min, window->InnerClipRect.Max, true); + PushClipRect(window->InnerClipRect.Min, window->InnerClipRect.Max, true); // Clear 'accessed' flag last thing (After PushClipRect which will set the flag. We want the flag to stay false when the default "Debug" window is unused) window->WriteAccessed = false; @@ -6875,23 +6371,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Update visibility if (first_begin_of_the_frame) { - // When we are about to select this tab (which will only be visible on the _next frame_), flag it with a non-zero HiddenFramesCannotSkipItems. - // This will have the important effect of actually returning true in Begin() and not setting SkipItems, allowing an earlier submission of the window contents. - // This is analogous to regular windows being hidden from one frame. - // It is especially important as e.g. nested TabBars would otherwise generate flicker in the form of one empty frame, or focus requests won't be processed. - if (window->DockIsActive && !window->DockTabIsVisible) - { - if (window->LastFrameJustFocused == g.FrameCount) - window->HiddenFramesCannotSkipItems = 1; - else - window->HiddenFramesCanSkipItems = 1; - } - if (flags & ImGuiWindowFlags_ChildWindow) { // Child window can be out of sight and have "negative" clip windows. // Mark them as collapsed so commands are skipped earlier (we can't manually collapse them because they have no title bar). - IM_ASSERT((flags& ImGuiWindowFlags_NoTitleBar) != 0 || (window->DockIsActive)); + IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0); if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0) // FIXME: Doesn't make sense for ChildWindow?? if (!g.LogEnabled) if (window->OuterRectClipped.Min.x >= window->OuterRectClipped.Max.x || window->OuterRectClipped.Min.y >= window->OuterRectClipped.Max.y) @@ -6924,12 +6408,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesCannotSkipItems <= 0) skip_items = true; window->SkipItems = skip_items; - - // Sanity check: there are two spots which can set Appearing = true - // - when 'window_just_activated_by_user' is set -> HiddenFramesCannotSkipItems is set -> SkipItems always false - // - in BeginDocked() path when DockNodeIsVisible == DockTabIsVisible == true -> hidden _should_ be all zero // FIXME: Not formally proven, hence the assert. - if (window->SkipItems && !window->Appearing) - IM_ASSERT(window->Appearing == false); // Please report on GitHub if this triggers: https://github.com/ocornut/imgui/issues/4177 } return !window->SkipItems; @@ -6949,24 +6427,18 @@ void ImGui::End() IM_ASSERT(g.CurrentWindowStack.Size > 0); // Error checking: verify that user doesn't directly call End() on a child window. - if ((window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_DockNodeHost) && !window->DockIsActive) + if (window->Flags & ImGuiWindowFlags_ChildWindow) IM_ASSERT_USER_ERROR(g.WithinEndChild, "Must call EndChild() and not End()!"); // Close anything that is open if (window->DC.CurrentColumns) EndColumns(); - if (!(window->Flags & ImGuiWindowFlags_DockNodeHost)) // Pop inner window clip rectangle - PopClipRect(); + PopClipRect(); // Inner window clip rectangle // Stop logging if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging LogFinish(); - // Docking: report contents sizes to parent to allow for auto-resize - if (window->DockNode && window->DockTabIsVisible) - if (ImGuiWindow* host_window = window->DockNode->HostWindow) // FIXME-DOCK - host_window->DC.CursorMaxPos = window->DC.CursorMaxPos + window->WindowPadding - host_window->WindowPadding; - // Pop from window stack g.LastItemData = g.CurrentWindowStack.back().ParentLastItemDataBackup; g.CurrentWindowStack.pop_back(); @@ -6974,8 +6446,6 @@ void ImGui::End() g.BeginPopupStack.pop_back(); window->DC.StackSizesOnBegin.CompareWithCurrentState(); SetCurrentWindow(g.CurrentWindowStack.Size == 0 ? NULL : g.CurrentWindowStack.back().Window); - if (g.CurrentWindow) - SetCurrentViewport(g.CurrentWindow, g.CurrentWindow->Viewport); } void ImGui::BringWindowToFocusFront(ImGuiWindow* window) @@ -7003,7 +6473,7 @@ void ImGui::BringWindowToDisplayFront(ImGuiWindow* window) { ImGuiContext& g = *GImGui; ImGuiWindow* current_front_window = g.Windows.back(); - if (current_front_window == window || current_front_window->RootWindowDockTree == window) // Cheap early out (could be better) + if (current_front_window == window || current_front_window->RootWindow == window) // Cheap early out (could be better) return; for (int i = g.Windows.Size - 2; i >= 0; i--) // We can ignore the top-most window if (g.Windows[i] == window) @@ -7051,32 +6521,24 @@ void ImGui::FocusWindow(ImGuiWindow* window) ClosePopupsOverWindow(window, false); // Move the root window to the top of the pile - IM_ASSERT(window == NULL || window->RootWindowDockTree != NULL); - ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL; - ImGuiWindow* display_front_window = window ? window->RootWindowDockTree : NULL; - ImGuiDockNode* dock_node = window ? window->DockNode : NULL; - bool active_id_window_is_dock_node_host = (g.ActiveIdWindow && dock_node && dock_node->HostWindow == g.ActiveIdWindow); + IM_ASSERT(window == NULL || window->RootWindow != NULL); + ImGuiWindow* focus_front_window = window ? window->RootWindow : NULL; // NB: In docking branch this is window->RootWindowDockStop + ImGuiWindow* display_front_window = window ? window->RootWindow : NULL; // Steal active widgets. Some of the cases it triggers includes: // - Focus a window while an InputText in another window is active, if focus happens before the old InputText can run. // - When using Nav to activate menu items (due to timing of activating on press->new window appears->losing ActiveId) - // - Using dock host items (tab, collapse button) can trigger this before we redirect the ActiveIdWindow toward the child window. if (g.ActiveId != 0 && g.ActiveIdWindow && g.ActiveIdWindow->RootWindow != focus_front_window) - if (!g.ActiveIdNoClearOnFocusLoss && !active_id_window_is_dock_node_host) + if (!g.ActiveIdNoClearOnFocusLoss) ClearActiveID(); // Passing NULL allow to disable keyboard focus if (!window) return; - window->LastFrameJustFocused = g.FrameCount; - - // Select in dock node - if (dock_node && dock_node->TabBar) - dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->ID; // Bring to front BringWindowToFocusFront(focus_front_window); - if (((window->Flags | focus_front_window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) + if (((window->Flags | display_front_window->Flags) & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0) BringWindowToDisplayFront(display_front_window); } @@ -7093,10 +6555,6 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind if (window != ignore_window && window->WasActive) if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) { - // FIXME-DOCK: This is failing (lagging by one frame) for docked windows. - // If A and B are docked into window and B disappear, at the NewFrame() call site window->NavLastChildNavWindow will still point to B. - // We might leverage the tab order implicitly stored in window->DockNodeAsHost->TabBar (essentially the 'most_recently_selected_tab' code in tab bar will do that but on next update) - // to tell which is the "previous" window. Or we may leverage 'LastFrameFocused/LastFrameJustFocused' and have this function handle child window itself? ImGuiWindow* focus_window = NavRestoreLastChildNavWindow(window); FocusWindow(focus_window); return; @@ -7161,29 +6619,36 @@ void ImGui::PopItemFlag() g.CurrentItemFlags = g.ItemFlagsStack.back(); } -// PushDisabled()/PopDisabled() -// - Those can be nested but this cannot be used to enable an already disabled section (a single PushDisabled(true) in the stack is enough to keep things disabled) -// - Those are not yet exposed in imgui.h because we are unsure of how to alter the style in a way that works for everyone. -// We may rework this. Hypothetically, a future styling system may set a flag which make widgets use different colors. +// BeginDisabled()/EndDisabled() +// - Those can be nested but this cannot be used to enable an already disabled section (a single BeginDisabled(true) in the stack is enough to keep things disabled) +// - Visually this is currently altering alpha, but it is expected that in a future styling system this would work differently. // - Feedback welcome at https://github.com/ocornut/imgui/issues/211 -// - You may trivially implement your own variation of this if needed. -// Here we test (CurrentItemFlags & ImGuiItemFlags_Disabled) to allow nested PushDisabled() calls. -void ImGui::PushDisabled(bool disabled) +// - BeginDisabled(false) essentially does nothing but is provided to facilitate use of boolean expressions +// - Optimized shortcuts instead of PushStyleVar() + PushItemFlag() +void ImGui::BeginDisabled(bool disabled) { ImGuiContext& g = *GImGui; bool was_disabled = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; if (!was_disabled && disabled) - PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.6f); - PushItemFlag(ImGuiItemFlags_Disabled, was_disabled || disabled); + { + //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * g.Style.DisabledAlpha); + g.DisabledAlphaBackup = g.Style.Alpha; + g.Style.Alpha *= g.Style.DisabledAlpha; + } + //PushItemFlag(ImGuiItemFlags_Disabled, was_disabled || disabled); + g.CurrentItemFlags |= ImGuiItemFlags_Disabled; + g.ItemFlagsStack.push_back(g.CurrentItemFlags); } -void ImGui::PopDisabled() +void ImGui::EndDisabled() { ImGuiContext& g = *GImGui; bool was_disabled = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; - PopItemFlag(); + //PopItemFlag(); + g.ItemFlagsStack.pop_back(); + g.CurrentItemFlags &= ~ImGuiItemFlags_Disabled; if (was_disabled && (g.CurrentItemFlags & ImGuiItemFlags_Disabled) == 0) - PopStyleVar(); + g.Style.Alpha = g.DisabledAlphaBackup; //PopStyleVar(); } // FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system. @@ -7221,10 +6686,9 @@ void ImGui::PopTextWrapPos() window->DC.TextWrapPosStack.pop_back(); } -// FIXME: We are exposing the docking hierarchy to end-user here (via IsWindowHovered, IsWindowFocused) which is unusual. bool ImGui::IsWindowChildOf(ImGuiWindow* window, ImGuiWindow* potential_parent) { - if (window->RootWindowDockTree == potential_parent) + if (window->RootWindow == potential_parent) return true; while (window != NULL) { @@ -7309,18 +6773,6 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags) } } -ImGuiID ImGui::GetWindowDockID() -{ - ImGuiContext& g = *GImGui; - return g.CurrentWindow->DockId; -} - -bool ImGui::IsWindowDocked() -{ - ImGuiContext& g = *GImGui; - return g.CurrentWindow->DockIsActive; -} - // Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext) // Note that NoNavFocus makes the window not reachable with CTRL+TAB but it can still be focused with mouse or programmatically. // If you want a window to never be focused, you may use the e.g. NoInputs flag. @@ -7496,7 +6948,6 @@ void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pi g.NextWindowData.PosVal = pos; g.NextWindowData.PosPivotVal = pivot; g.NextWindowData.PosCond = cond ? cond : ImGuiCond_Always; - g.NextWindowData.PosUndock = true; } void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond) @@ -7555,48 +7006,12 @@ void ImGui::SetNextWindowBgAlpha(float alpha) g.NextWindowData.BgAlphaVal = alpha; } -void ImGui::SetNextWindowViewport(ImGuiID id) -{ - ImGuiContext& g = *GImGui; - g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasViewport; - g.NextWindowData.ViewportId = id; -} - -void ImGui::SetNextWindowDockID(ImGuiID id, ImGuiCond cond) -{ - ImGuiContext& g = *GImGui; - g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasDock; - g.NextWindowData.DockCond = cond ? cond : ImGuiCond_Always; - g.NextWindowData.DockId = id; -} - -void ImGui::SetNextWindowClass(const ImGuiWindowClass* window_class) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT((window_class->ViewportFlagsOverrideSet & window_class->ViewportFlagsOverrideClear) == 0); // Cannot set both set and clear for the same bit - g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasWindowClass; - g.NextWindowData.WindowClass = *window_class; -} - ImDrawList* ImGui::GetWindowDrawList() { ImGuiWindow* window = GetCurrentWindow(); return window->DrawList; } -float ImGui::GetWindowDpiScale() -{ - ImGuiContext& g = *GImGui; - return g.CurrentDpiScale; -} - -ImGuiViewport* ImGui::GetWindowViewport() -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(g.CurrentViewport != NULL && g.CurrentViewport == g.CurrentWindow->Viewport); - return g.CurrentViewport; -} - ImFont* ImGui::GetFont() { return GImGui->Font; @@ -7831,46 +7246,6 @@ static void ImGui::ErrorCheckNewFrameSanityChecks() // Check: the io.ConfigWindowsResizeFromEdges option requires backend to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly. if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors)) g.IO.ConfigWindowsResizeFromEdges = false; - - // Perform simple check: error if Docking or Viewport are enabled _exactly_ on frame 1 (instead of frame 0 or later), which is a common error leading to loss of .ini data. - if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_DockingEnable) == 0) - IM_ASSERT(0 && "Please set DockingEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!"); - if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable) == 0) - IM_ASSERT(0 && "Please set ViewportsEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!"); - - // Perform simple checks: multi-viewport and platform windows support - if (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - if ((g.IO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) - { - IM_ASSERT((g.FrameCount == 0 || g.FrameCount == g.FrameCountPlatformEnded) && "Forgot to call UpdatePlatformWindows() in main loop after EndFrame()? Check examples/ applications for reference."); - 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_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.PlatformIO.Monitors.Size > 0 && "Platform init didn't setup Monitors list?"); - IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport."); - if (g.IO.ConfigDockingTransparentPayload && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) - IM_ASSERT(g.PlatformIO.Platform_SetWindowAlpha != NULL && "Platform_SetWindowAlpha handler is required to use io.ConfigDockingTransparent!"); - } - else - { - // Disable feature, our backends do not support it - g.IO.ConfigFlags &= ~ImGuiConfigFlags_ViewportsEnable; - } - - // Perform simple checks on platform monitor data + compute a total bounding box for quick early outs - for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++) - { - ImGuiPlatformMonitor& mon = g.PlatformIO.Monitors[monitor_n]; - IM_UNUSED(mon); - IM_ASSERT(mon.MainSize.x > 0.0f && mon.MainSize.y > 0.0f && "Monitor main bounds not setup properly."); - IM_ASSERT(ImRect(mon.MainPos, mon.MainPos + mon.MainSize).Contains(ImRect(mon.WorkPos, mon.WorkPos + mon.WorkSize)) && "Monitor work bounds not setup properly. If you don't have work area information, just copy MainPos/MainSize into them."); - IM_ASSERT(mon.DpiScale != 0.0f); - } - } } static void ImGui::ErrorCheckEndFrameSanityChecks() @@ -8747,7 +8122,7 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags toolt window->HiddenFramesCanSkipItems = 1; // FIXME: This may not be necessary? ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount); } - ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking; + ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize; Begin(window_name, NULL, flags | extra_flags); } @@ -8914,12 +8289,12 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to // Trim the stack unless the popup is a direct parent of the reference window (the reference window is often the NavWindow) // - With this stack of window, clicking/focusing Popup1 will close Popup2 and Popup3: // Window -> Popup1 -> Popup2 -> Popup3 - // - Each popups may contain child windows, which is why we compare ->RootWindowDockTree! + // - Each popups may contain child windows, which is why we compare ->RootWindow! // Window -> Popup1 -> Popup1_Child -> Popup2 -> Popup2_Child bool ref_window_is_descendent_of_popup = false; for (int n = popup_count_to_keep; n < g.OpenPopupStack.Size; n++) if (ImGuiWindow* popup_window = g.OpenPopupStack[n].Window) - if (popup_window->RootWindowDockTree == ref_window->RootWindowDockTree) + if (popup_window->RootWindow == ref_window->RootWindow) { ref_window_is_descendent_of_popup = true; break; @@ -9009,7 +8384,7 @@ bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags) else ImFormatString(name, IM_ARRAYSIZE(name), "##Popup_%08x", id); // Not recycling, so we can close/open during the same frame - flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoDocking; + flags |= ImGuiWindowFlags_Popup; bool is_open = Begin(name, NULL, flags); if (!is_open) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display) EndPopup(); @@ -9047,11 +8422,11 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla // FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window. if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0) { - const ImGuiViewport* viewport = window->WasActive ? window->Viewport : GetMainViewport(); // FIXME-VIEWPORT: What may be our reference viewport? + const ImGuiViewport* viewport = GetMainViewport(); SetNextWindowPos(viewport->GetCenter(), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f)); } - flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking; + flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse; const bool is_open = Begin(name, p_open, flags); if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display) { @@ -9238,19 +8613,8 @@ ImVec2 ImGui::FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& s ImRect ImGui::GetPopupAllowedExtentRect(ImGuiWindow* window) { ImGuiContext& g = *GImGui; - ImRect r_screen; - if (window->ViewportAllowPlatformMonitorExtend >= 0) - { - // Extent with be in the frame of reference of the given viewport (so Min is likely to be negative here) - const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[window->ViewportAllowPlatformMonitorExtend]; - r_screen.Min = monitor.WorkPos; - r_screen.Max = monitor.WorkPos + monitor.WorkSize; - } - else - { - // Use the full viewport area (not work area) for popups - r_screen = window->Viewport->GetMainRect(); - } + IM_UNUSED(window); + ImRect r_screen = ((ImGuiViewportP*)(void*)GetMainViewport())->GetMainRect(); ImVec2 padding = g.Style.DisplaySafeAreaPadding; r_screen.Expand(ImVec2((r_screen.GetWidth() > padding.x * 2) ? -padding.x : 0.0f, (r_screen.GetHeight() > padding.y * 2) ? -padding.y : 0.0f)); return r_screen; @@ -9265,7 +8629,8 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) { // Child menus typically request _any_ position within the parent menu item, and then we move the new menu outside the parent bounds. // This is how we end up with child menus appearing (most-commonly) on the right of the parent menu. - ImGuiWindow* parent_window = window->ParentWindow; + IM_ASSERT(g.CurrentWindow == window); + ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.Size - 2].Window; float horizontal_overlap = g.Style.ItemInnerSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x). ImRect r_avoid; if (parent_window->DC.MenuBarAppending) @@ -9622,9 +8987,6 @@ static ImGuiWindow* ImGui::NavRestoreLastChildNavWindow(ImGuiWindow* window) { if (window->NavLastChildNavWindow && window->NavLastChildNavWindow->WasActive) return window->NavLastChildNavWindow; - if (window->DockNodeAsHost && window->DockNodeAsHost->TabBar) - if (ImGuiTabItem* tab = TabBarFindMostRecentlySelectedTabForActiveWindow(window->DockNodeAsHost->TabBar)) - return tab->Window; return window; } @@ -9658,7 +9020,6 @@ static inline void ImGui::NavUpdateAnyRequestFlag() // This needs to be called before we submit any widget (aka in or before Begin) void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit) { - // FIXME: ChildWindow test here is wrong for docking ImGuiContext& g = *GImGui; IM_ASSERT(window == g.NavWindow); @@ -9703,7 +9064,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() // When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item. const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer]; ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight())); - ImGuiViewport* viewport = g.NavWindow->Viewport; + ImGuiViewport* viewport = GetMainViewport(); return ImFloor(ImClamp(pos, viewport->Pos, viewport->Pos + viewport->Size)); // ImFloor() is important because non-integer mouse position application in backend might be lossy and result in undesirable non-zero delta. } } @@ -9999,7 +9360,7 @@ static void ImGui::NavUpdate() } // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items) - ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0); + ImRect nav_rect_rel = g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted() ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0); g.NavScoringRect = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : ImRect(0, 0, 0, 0); g.NavScoringRect.TranslateY(nav_scoring_rect_offset_y); g.NavScoringRect.Min.x = ImMin(g.NavScoringRect.Min.x + 1.0f, g.NavScoringRect.Max.x); @@ -10382,7 +9743,7 @@ static void ImGui::NavUpdateWindowing() { const float NAV_MOVE_SPEED = 800.0f; const float move_speed = ImFloor(NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y)); // FIXME: Doesn't handle variable framerate very well - ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindowDockTree; + ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindow; SetWindowPos(moving_window, moving_window->Pos + move_delta * move_speed, ImGuiCond_Always); MarkIniSettingsDirty(moving_window); g.NavDisableMouseHover = true; @@ -10392,7 +9753,6 @@ static void ImGui::NavUpdateWindowing() // Apply final focus if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindow)) { - ImGuiViewport* previous_viewport = g.NavWindow ? g.NavWindow->Viewport : NULL; ClearActiveID(); g.NavDisableHighlight = false; g.NavDisableMouseHover = true; @@ -10411,10 +9771,6 @@ static void ImGui::NavUpdateWindowing() // won't be valid. if (apply_focus_window->DC.NavLayersActiveMaskNext == (1 << ImGuiNavLayer_Menu)) g.NavLayer = ImGuiNavLayer_Menu; - - // Request OS level focus - if (apply_focus_window->Viewport != previous_viewport && g.PlatformIO.Platform_SetWindowFocus) - g.PlatformIO.Platform_SetWindowFocus(apply_focus_window->Viewport); } if (apply_focus_window) g.NavWindowingTarget = NULL; @@ -10442,8 +9798,7 @@ static void ImGui::NavUpdateWindowing() // Reinitialize navigation when entering menu bar with the Alt key. const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main; - const bool preserve_layer_1_nav_id = (new_nav_window->DockNodeAsHost != NULL); - if (new_nav_layer == ImGuiNavLayer_Menu && !preserve_layer_1_nav_id) + if (new_nav_layer == ImGuiNavLayer_Menu) g.NavWindow->NavLastIds[new_nav_layer] = 0; NavRestoreLayer(new_nav_layer); } @@ -10456,8 +9811,6 @@ static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window) return "(Popup)"; if ((window->Flags & ImGuiWindowFlags_MenuBar) && strcmp(window->Name, "##MainMenuBar") == 0) return "(Main menu bar)"; - if (window->DockNodeAsHost) - return "(Dock node)"; return "(Untitled)"; } @@ -10472,7 +9825,7 @@ void ImGui::NavUpdateWindowingOverlay() if (g.NavWindowingListWindow == NULL) g.NavWindowingListWindow = FindWindowByName("###NavWindowingList"); - const ImGuiViewport* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ GetMainViewport(); + const ImGuiViewport* viewport = GetMainViewport(); SetNextWindowSizeConstraints(ImVec2(viewport->Size.x * 0.20f, viewport->Size.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX)); SetNextWindowPos(viewport->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f); @@ -10698,7 +10051,7 @@ bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id) ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow; - if (hovered_window == NULL || window->RootWindowDockTree != hovered_window->RootWindowDockTree) + if (hovered_window == NULL || window->RootWindow != hovered_window->RootWindow) return false; IM_ASSERT(id != 0); if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId)) @@ -10727,7 +10080,7 @@ bool ImGui::BeginDragDropTarget() if (!(g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HoveredRect)) return false; ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow; - if (hovered_window == NULL || window->RootWindowDockTree != hovered_window->RootWindowDockTree) + if (hovered_window == NULL || window->RootWindow != hovered_window->RootWindow) return false; const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect; @@ -11303,15 +10656,9 @@ static void WindowSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry; int x, y; int i; - ImU32 u1; - if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) { settings->Pos = ImVec2ih((short)x, (short)y); } - else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) { settings->Size = ImVec2ih((short)x, (short)y); } - else if (sscanf(line, "ViewportId=0x%08X", &u1) == 1) { settings->ViewportId = u1; } - else if (sscanf(line, "ViewportPos=%i,%i", &x, &y) == 2){ settings->ViewportPos = ImVec2ih((short)x, (short)y); } - else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); } - else if (sscanf(line, "DockId=0x%X,%d", &u1, &i) == 2) { settings->DockId = u1; settings->DockOrder = (short)i; } - else if (sscanf(line, "DockId=0x%X", &u1) == 1) { settings->DockId = u1; settings->DockOrder = -1; } - else if (sscanf(line, "ClassId=0x%X", &u1) == 1) { settings->ClassId = u1; } + if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) { settings->Pos = ImVec2ih((short)x, (short)y); } + else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) { settings->Size = ImVec2ih((short)x, (short)y); } + else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); } } // Apply to existing windows (if any) @@ -11345,14 +10692,9 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl window->SettingsOffset = g.SettingsWindows.offset_from_ptr(settings); } IM_ASSERT(settings->ID == window->ID); - settings->Pos = ImVec2ih(window->Pos - window->ViewportPos); + settings->Pos = ImVec2ih(window->Pos); settings->Size = ImVec2ih(window->SizeFull); - settings->ViewportId = window->ViewportId; - settings->ViewportPos = ImVec2ih(window->ViewportPos); - IM_ASSERT(window->DockNode == NULL || window->DockNode->ID == window->DockId); - settings->DockId = window->DockId; - settings->ClassId = window->WindowClass.ClassId; - settings->DockOrder = window->DockOrder; + settings->Collapsed = window->Collapsed; } @@ -11362,25 +10704,9 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl { const char* settings_name = settings->GetName(); buf->appendf("[%s][%s]\n", handler->TypeName, settings_name); - if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID) - { - buf->appendf("ViewportPos=%d,%d\n", settings->ViewportPos.x, settings->ViewportPos.y); - buf->appendf("ViewportId=0x%08X\n", settings->ViewportId); - } - if (settings->Pos.x != 0 || settings->Pos.y != 0 || settings->ViewportId == ImGui::IMGUI_VIEWPORT_DEFAULT_ID) - buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y); - if (settings->Size.x != 0 || settings->Size.y != 0) - buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y); + buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y); + buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y); buf->appendf("Collapsed=%d\n", settings->Collapsed); - if (settings->DockId != 0) - { - if (settings->DockOrder == -1) - buf->appendf("DockId=0x%08X\n", settings->DockId); - else - buf->appendf("DockId=0x%08X,%d\n", settings->DockId, settings->DockOrder); - if (settings->ClassId != 0) - buf->appendf("ClassId=0x%08X\n", settings->ClassId); - } buf->append("\n"); } } @@ -11390,28 +10716,8 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl // [SECTION] VIEWPORTS, PLATFORM WINDOWS //----------------------------------------------------------------------------- // - GetMainViewport() -// - FindViewportByID() -// - FindViewportByPlatformHandle() -// - SetCurrentViewport() [Internal] -// - SetWindowViewport() [Internal] -// - GetWindowAlwaysWantOwnViewport() [Internal] -// - UpdateTryMergeWindowIntoHostViewport() [Internal] -// - UpdateTryMergeWindowIntoHostViewports() [Internal] -// - TranslateWindowsInViewport() [Internal] -// - ScaleWindowsInViewport() [Internal] -// - FindHoveredViewportFromPlatformWindowStack() [Internal] // - UpdateViewportsNewFrame() [Internal] -// - UpdateViewportsEndFrame() [Internal] -// - AddUpdateViewport() [Internal] -// - WindowSelectViewport() [Internal] -// - WindowSyncOwnedViewport() [Internal] -// - UpdatePlatformWindows() -// - RenderPlatformWindowsDefault() -// - FindPlatformMonitorForPos() [Internal] -// - FindPlatformMonitorForRect() [Internal] -// - UpdateViewportPlatformMonitor() [Internal] -// - DestroyPlatformWindow() [Internal] -// - DestroyPlatformWindows() +// (this section is more complete in the 'docking' branch) //----------------------------------------------------------------------------- ImGuiViewport* ImGui::GetMainViewport() @@ -11420,4641 +10726,36 @@ ImGuiViewport* ImGui::GetMainViewport() return g.Viewports[0]; } -// FIXME: This leaks access to viewports not listed in PlatformIO.Viewports[]. Problematic? (#4236) -ImGuiViewport* ImGui::FindViewportByID(ImGuiID id) -{ - ImGuiContext& g = *GImGui; - for (int n = 0; n < g.Viewports.Size; n++) - if (g.Viewports[n]->ID == id) - return g.Viewports[n]; - return NULL; -} - -ImGuiViewport* ImGui::FindViewportByPlatformHandle(void* platform_handle) -{ - ImGuiContext& g = *GImGui; - for (int i = 0; i != g.Viewports.Size; i++) - if (g.Viewports[i]->PlatformHandle == platform_handle) - return g.Viewports[i]; - return NULL; -} - -void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* viewport) -{ - ImGuiContext& g = *GImGui; - (void)current_window; - - if (viewport) - viewport->LastFrameActive = g.FrameCount; - if (g.CurrentViewport == viewport) - return; - g.CurrentDpiScale = viewport ? viewport->DpiScale : 1.0f; - g.CurrentViewport = viewport; - //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); - - // Notify platform layer of viewport changes - // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI - if (g.CurrentViewport && g.PlatformIO.Platform_OnChangedViewport) - g.PlatformIO.Platform_OnChangedViewport(g.CurrentViewport); -} - -static void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport) -{ - window->Viewport = viewport; - window->ViewportId = viewport->ID; - window->ViewportOwned = (viewport->Window == window); -} - -static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window) -{ - // Tooltips and menus are not automatically forced into their own viewport when the NoMerge flag is set, however the multiplication of viewports makes them more likely to protrude and create their own. - ImGuiContext& g = *GImGui; - if (g.IO.ConfigViewportsNoAutoMerge || (window->WindowClass.ViewportFlagsOverrideSet & ImGuiViewportFlags_NoAutoMerge)) - if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) - if (!window->DockIsActive) - if ((window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip)) == 0) - if ((window->Flags & ImGuiWindowFlags_Popup) == 0 || (window->Flags & ImGuiWindowFlags_Modal) != 0) - return true; - return false; -} - -static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport) -{ - ImGuiContext& g = *GImGui; - if (window->Viewport == viewport) - return false; - if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) == 0) - return false; - if ((viewport->Flags & ImGuiViewportFlags_Minimized) != 0) - return false; - if (!viewport->GetMainRect().Contains(window->Rect())) - return false; - if (GetWindowAlwaysWantOwnViewport(window)) - return false; - - for (int n = 0; n < g.Windows.Size; n++) - { - ImGuiWindow* window_behind = g.Windows[n]; - if (window_behind == window) - break; - if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow)) - if (window_behind->Viewport->GetMainRect().Overlaps(window->Rect())) - return false; - } - - // Move to the existing viewport, Move child/hosted windows as well (FIXME-OPT: iterate child) - ImGuiViewportP* old_viewport = window->Viewport; - if (window->ViewportOwned) - for (int n = 0; n < g.Windows.Size; n++) - if (g.Windows[n]->Viewport == old_viewport) - SetWindowViewport(g.Windows[n], viewport); - SetWindowViewport(window, viewport); - BringWindowToDisplayFront(window); - - return true; -} - -// FIXME: handle 0 to N host viewports -static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - return UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]); -} - -// Translate Dear ImGui windows when a Host Viewport has been moved -// (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!) -void ImGui::TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(viewport->Window == NULL && (viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows)); - - // 1) We test if ImGuiConfigFlags_ViewportsEnable was just toggled, which allows us to conveniently - // translate imgui windows from OS-window-local to absolute coordinates or vice-versa. - // 2) If it's not going to fit into the new size, keep it at same absolute position. - // One problem with this is that most Win32 applications doesn't update their render while dragging, - // and so the window will appear to teleport when releasing the mouse. - const bool translate_all_windows = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable); - ImRect test_still_fit_rect(old_pos, old_pos + viewport->Size); - ImVec2 delta_pos = new_pos - old_pos; - for (int window_n = 0; window_n < g.Windows.Size; window_n++) // FIXME-OPT - if (translate_all_windows || (g.Windows[window_n]->Viewport == viewport && test_still_fit_rect.Contains(g.Windows[window_n]->Rect()))) - TranslateWindow(g.Windows[window_n], delta_pos); -} - -// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!) -void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale) -{ - ImGuiContext& g = *GImGui; - if (viewport->Window) - { - ScaleWindow(viewport->Window, scale); - } - else - { - for (int i = 0; i != g.Windows.Size; i++) - if (g.Windows[i]->Viewport == viewport) - ScaleWindow(g.Windows[i], scale); - } -} - -// If the backend doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves. -// A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window. -// B) It requires Platform_GetWindowFocus to be implemented by backend. -static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 mouse_platform_pos) -{ - ImGuiContext& g = *GImGui; - ImGuiViewportP* best_candidate = NULL; - for (int n = 0; n < g.Viewports.Size; n++) - { - ImGuiViewportP* viewport = g.Viewports[n]; - if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetMainRect().Contains(mouse_platform_pos)) - if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount) - best_candidate = viewport; - } - return best_candidate; -} - // Update viewports and monitor infos -// Note that this is running even if 'ImGuiConfigFlags_ViewportsEnable' is not set, in order to clear unused viewports (if any) and update monitor info. static void ImGui::UpdateViewportsNewFrame() { ImGuiContext& g = *GImGui; - IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size); + IM_ASSERT(g.Viewports.Size == 1); - // Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport) - const bool viewports_enabled = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != 0; - if (viewports_enabled) - { - for (int n = 0; n < g.Viewports.Size; n++) - { - ImGuiViewportP* viewport = g.Viewports[n]; - const bool platform_funcs_available = viewport->PlatformWindowCreated; - if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available) - { - bool minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport); - if (minimized) - viewport->Flags |= ImGuiViewportFlags_Minimized; - else - viewport->Flags &= ~ImGuiViewportFlags_Minimized; - } - } - } - - // Create/update main viewport with current platform position. + // Update main viewport with current platform position. // FIXME-VIEWPORT: Size is driven by backend/user code for backward-compatibility but we should aim to make this more consistent. ImGuiViewportP* main_viewport = g.Viewports[0]; - IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID); - IM_ASSERT(main_viewport->Window == NULL); - ImVec2 main_viewport_pos = viewports_enabled ? g.PlatformIO.Platform_GetWindowPos(main_viewport) : ImVec2(0.0f, 0.0f); - ImVec2 main_viewport_size = g.IO.DisplaySize; - if (viewports_enabled && (main_viewport->Flags & ImGuiViewportFlags_Minimized)) - { - main_viewport_pos = main_viewport->Pos; // Preserve last pos/size when minimized (FIXME: We don't do the same for Size outside of the viewport path) - main_viewport_size = main_viewport->Size; - } - AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_pos, main_viewport_size, ImGuiViewportFlags_OwnedByApp | ImGuiViewportFlags_CanHostOtherWindows); + main_viewport->Flags = ImGuiViewportFlags_IsPlatformWindow | ImGuiViewportFlags_OwnedByApp; + main_viewport->Pos = ImVec2(0.0f, 0.0f); + main_viewport->Size = g.IO.DisplaySize; - g.CurrentDpiScale = 0.0f; - g.CurrentViewport = NULL; - g.MouseViewport = NULL; for (int n = 0; n < g.Viewports.Size; n++) { ImGuiViewportP* viewport = g.Viewports[n]; - viewport->Idx = n; - // Erase unused viewports - if (n > 0 && viewport->LastFrameActive < g.FrameCount - 2) - { - // Clear references to this viewport in windows (window->ViewportId becomes the master data) - for (int window_n = 0; window_n < g.Windows.Size; window_n++) - if (g.Windows[window_n]->Viewport == viewport) - { - g.Windows[window_n]->Viewport = NULL; - g.Windows[window_n]->ViewportOwned = false; - } - if (viewport == g.MouseLastHoveredViewport) - g.MouseLastHoveredViewport = NULL; - g.Viewports.erase(g.Viewports.Data + n); - - // Destroy - IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); - DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here. - IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); - IM_DELETE(viewport); - n--; - continue; - } - - const bool platform_funcs_available = viewport->PlatformWindowCreated; - if (viewports_enabled) - { - // Update 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. - if (!(viewport->Flags & ImGuiViewportFlags_Minimized) && platform_funcs_available) - { - // Viewport->WorkPos and WorkSize will be updated below - if (viewport->PlatformRequestMove) - viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport); - if (viewport->PlatformRequestResize) - viewport->Size = viewport->LastPlatformSize = g.PlatformIO.Platform_GetWindowSize(viewport); - } - } - - // Update/copy monitor info - UpdateViewportPlatformMonitor(viewport); - - // Lock down space taken by menu bars and status bars, reset the offset for functions like BeginMainMenuBar() to alter them again. + // Lock down space taken by menu bars and status bars, reset the offset for fucntions like BeginMainMenuBar() to alter them again. viewport->WorkOffsetMin = viewport->BuildWorkOffsetMin; viewport->WorkOffsetMax = viewport->BuildWorkOffsetMax; viewport->BuildWorkOffsetMin = viewport->BuildWorkOffsetMax = ImVec2(0.0f, 0.0f); viewport->UpdateWorkRect(); - - // Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back. - viewport->Alpha = 1.0f; - - // Translate imgui windows when a Host Viewport has been moved - // (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!) - const ImVec2 viewport_delta_pos = viewport->Pos - viewport->LastPos; - if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) && (viewport_delta_pos.x != 0.0f || viewport_delta_pos.y != 0.0f)) - TranslateWindowsInViewport(viewport, viewport->LastPos, viewport->Pos); - - // Update DPI scale - float new_dpi_scale; - if (g.PlatformIO.Platform_GetWindowDpiScale && platform_funcs_available) - new_dpi_scale = g.PlatformIO.Platform_GetWindowDpiScale(viewport); - else if (viewport->PlatformMonitor != -1) - new_dpi_scale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale; - else - new_dpi_scale = (viewport->DpiScale != 0.0f) ? viewport->DpiScale : 1.0f; - if (viewport->DpiScale != 0.0f && new_dpi_scale != viewport->DpiScale) - { - float scale_factor = new_dpi_scale / viewport->DpiScale; - if (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports) - ScaleWindowsInViewport(viewport, scale_factor); - //if (viewport == GetMainViewport()) - // g.PlatformInterface.SetWindowSize(viewport, viewport->Size * scale_factor); - - // Scale our window moving pivot so that the window will rescale roughly around the mouse position. - // FIXME-VIEWPORT: This currently creates a resizing feedback loop when a window is straddling a DPI transition border. - // (Minor: since our sizes do not perfectly linearly scale, deferring the click offset scale until we know the actual window scale ratio may get us slightly more precise mouse positioning.) - //if (g.MovingWindow != NULL && g.MovingWindow->Viewport == viewport) - // g.ActiveIdClickOffset = ImFloor(g.ActiveIdClickOffset * scale_factor); - } - viewport->DpiScale = new_dpi_scale; - } - - // Update fallback monitor - if (g.PlatformIO.Monitors.Size == 0) - { - ImGuiPlatformMonitor* monitor = &g.FallbackMonitor; - monitor->MainPos = main_viewport->Pos; - monitor->MainSize = main_viewport->Size; - monitor->WorkPos = main_viewport->WorkPos; - monitor->WorkSize = main_viewport->WorkSize; - monitor->DpiScale = main_viewport->DpiScale; - } - - if (!viewports_enabled) - { - g.MouseViewport = main_viewport; - return; - } - - // Mouse handling: decide on the actual mouse viewport for this frame between the active/focused viewport and the hovered viewport. - // Note that 'viewport_hovered' should skip over any viewport that has the ImGuiViewportFlags_NoInputs flags set. - ImGuiViewportP* viewport_hovered = NULL; - if (g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) - { - viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL; - if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs)) - { - // Backend failed at honoring its contract if it returned a viewport with the _NoInputs flag. - IM_ASSERT(0); - viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); - } - } - else - { - // If the backend doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search: - // A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window. - // B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO) - viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); - } - if (viewport_hovered != NULL) - g.MouseLastHoveredViewport = viewport_hovered; - else if (g.MouseLastHoveredViewport == NULL) - g.MouseLastHoveredViewport = g.Viewports[0]; - - // Update mouse reference viewport - // (when moving a window we aim at its viewport, but this will be overwritten below if we go in drag and drop mode) - if (g.MovingWindow) - g.MouseViewport = g.MovingWindow->Viewport; - else - g.MouseViewport = g.MouseLastHoveredViewport; - - // When dragging something, always refer to the last hovered viewport. - // - when releasing a moving window we will revert to aiming behind (at viewport_hovered) - // - when we are between viewports, our dragged preview will tend to show in the last viewport _even_ if we don't have tooltips in their viewports (when lacking monitor info) - // - consider the case of holding on a menu item to browse child menus: even thou a mouse button is held, there's no active id because menu items only react on mouse release. - // FIXME-VIEWPORT: This is essentially broken, when ImGuiBackendFlags_HasMouseHoveredViewport is set we want to trust when viewport_hovered==NULL and use that. - const bool is_mouse_dragging_with_an_expected_destination = g.DragDropActive; - if (is_mouse_dragging_with_an_expected_destination && viewport_hovered == NULL) - viewport_hovered = g.MouseLastHoveredViewport; - if (is_mouse_dragging_with_an_expected_destination || g.ActiveId == 0 || !IsAnyMouseDown()) - if (viewport_hovered != NULL && viewport_hovered != g.MouseViewport && !(viewport_hovered->Flags & ImGuiViewportFlags_NoInputs)) - g.MouseViewport = viewport_hovered; - - IM_ASSERT(g.MouseViewport != NULL); -} - -// Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some) -static void ImGui::UpdateViewportsEndFrame() -{ - ImGuiContext& g = *GImGui; - g.PlatformIO.Viewports.resize(0); - for (int i = 0; i < g.Viewports.Size; i++) - { - ImGuiViewportP* viewport = g.Viewports[i]; - viewport->LastPos = viewport->Pos; - if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f) - if (i > 0) // Always include main viewport in the list - continue; - if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)) - continue; - if (i > 0) - IM_ASSERT(viewport->Window != NULL); - g.PlatformIO.Viewports.push_back(viewport); - } - g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called -} - -// FIXME: We should ideally refactor the system to call this every frame (we currently don't) -ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(id != 0); - - flags |= ImGuiViewportFlags_IsPlatformWindow; - if (window != NULL) - { - if (g.MovingWindow && g.MovingWindow->RootWindowDockTree == window) - flags |= ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_NoFocusOnAppearing; - if ((window->Flags & ImGuiWindowFlags_NoMouseInputs) && (window->Flags & ImGuiWindowFlags_NoNavInputs)) - flags |= ImGuiViewportFlags_NoInputs; - if (window->Flags & ImGuiWindowFlags_NoFocusOnAppearing) - flags |= ImGuiViewportFlags_NoFocusOnAppearing; - } - - ImGuiViewportP* viewport = (ImGuiViewportP*)FindViewportByID(id); - if (viewport) - { - if (!viewport->PlatformRequestMove) - viewport->Pos = pos; - if (!viewport->PlatformRequestResize) - viewport->Size = size; - viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_Minimized); // Preserve existing flags - } - else - { - // New viewport - viewport = IM_NEW(ImGuiViewportP)(); - viewport->ID = id; - viewport->Idx = g.Viewports.Size; - viewport->Pos = viewport->LastPos = pos; - viewport->Size = size; - viewport->Flags = flags; - UpdateViewportPlatformMonitor(viewport); - g.Viewports.push_back(viewport); - IMGUI_DEBUG_LOG_VIEWPORT("Add Viewport %08X (%s)\n", id, window->Name); - - // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport. - // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame - g.DrawListSharedData.ClipRectFullscreen.x = ImMin(g.DrawListSharedData.ClipRectFullscreen.x, viewport->Pos.x); - g.DrawListSharedData.ClipRectFullscreen.y = ImMin(g.DrawListSharedData.ClipRectFullscreen.y, viewport->Pos.y); - g.DrawListSharedData.ClipRectFullscreen.z = ImMax(g.DrawListSharedData.ClipRectFullscreen.z, viewport->Pos.x + viewport->Size.x); - g.DrawListSharedData.ClipRectFullscreen.w = ImMax(g.DrawListSharedData.ClipRectFullscreen.w, viewport->Pos.y + viewport->Size.y); - - // Store initial DpiScale before the OS platform window creation, based on expected monitor data. - // This is so we can select an appropriate font size on the first frame of our window lifetime - if (viewport->PlatformMonitor != -1) - viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale; - } - - viewport->Window = window; - viewport->LastFrameActive = g.FrameCount; - viewport->UpdateWorkRect(); - IM_ASSERT(window == NULL || viewport->ID == window->ID); - - if (window != NULL) - window->ViewportOwned = true; - - return viewport; -} - -// FIXME-VIEWPORT: This is all super messy and ought to be clarified or rewritten. -static void ImGui::WindowSelectViewport(ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - ImGuiWindowFlags flags = window->Flags; - window->ViewportAllowPlatformMonitorExtend = -1; - - // Restore main viewport if multi-viewport is not supported by the backend - ImGuiViewportP* main_viewport = (ImGuiViewportP*)(void*)GetMainViewport(); - if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) - { - SetWindowViewport(window, main_viewport); - return; - } - window->ViewportOwned = false; - - // Appearing popups reset their viewport so they can inherit again - if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && window->Appearing) - { - window->Viewport = NULL; - window->ViewportId = 0; - } - - if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasViewport) == 0) - { - // By default inherit from parent window - if (window->Viewport == NULL && window->ParentWindow && (!window->ParentWindow->IsFallbackWindow || window->ParentWindow->WasActive)) - window->Viewport = window->ParentWindow->Viewport; - - // Attempt to restore saved viewport id (= window that hasn't been activated yet), try to restore the viewport based on saved 'window->ViewportPos' restored from .ini file - if (window->Viewport == NULL && window->ViewportId != 0) - { - window->Viewport = (ImGuiViewportP*)FindViewportByID(window->ViewportId); - 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_None); - } - } - - bool lock_viewport = false; - if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasViewport) - { - // Code explicitly request a viewport - window->Viewport = (ImGuiViewportP*)FindViewportByID(g.NextWindowData.ViewportId); - window->ViewportId = g.NextWindowData.ViewportId; // Store ID even if Viewport isn't resolved yet. - lock_viewport = true; - } - else if ((flags & ImGuiWindowFlags_ChildWindow) || (flags & ImGuiWindowFlags_ChildMenu)) - { - // Always inherit viewport from parent window - window->Viewport = window->ParentWindow->Viewport; - } - else if (flags & ImGuiWindowFlags_Tooltip) - { - window->Viewport = g.MouseViewport; - } - else if (GetWindowAlwaysWantOwnViewport(window)) - { - window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None); - } - else if (g.MovingWindow && g.MovingWindow->RootWindowDockTree == window && IsMousePosValid()) - { - if (window->Viewport != NULL && window->Viewport->Window == window) - window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None); - } - else - { - // Merge into host viewport? - // We cannot test window->ViewportOwned as it set lower in the function. - bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0); - if (try_to_merge_into_host_viewport) - UpdateTryMergeWindowIntoHostViewports(window); - } - - // Fallback: merge in default viewport if z-order matches, otherwise create a new viewport - if (window->Viewport == NULL) - if (!UpdateTryMergeWindowIntoHostViewport(window, main_viewport)) - 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 - if (!lock_viewport) - { - if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) - { - // We need to take account of the possibility that mouse may become invalid. - // Popups/Tooltip always set ViewportAllowPlatformMonitorExtend so GetWindowAllowedExtentRect() will return full monitor bounds. - ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos; - bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow); - bool mouse_valid = IsMousePosValid(&mouse_ref); - if ((window->Appearing || (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_ChildMenu))) && (!use_mouse_ref || mouse_valid)) - window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos()); - else - window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor; - } - else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow)) - { - // When called from Begin() we don't have access to a proper version of the Hidden flag yet, so we replicate this code. - const bool will_be_visible = (window->DockIsActive && !window->DockTabIsVisible) ? false : true; - if ((window->Flags & ImGuiWindowFlags_DockNodeHost) && window->Viewport->LastFrameActive < g.FrameCount && will_be_visible) - { - // Steal/transfer ownership - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name); - window->Viewport->Window = window; - window->Viewport->ID = window->ID; - window->Viewport->LastNameHash = 0; - } - else if (!UpdateTryMergeWindowIntoHostViewports(window)) // Merge? - { - // New viewport - window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing); - } - } - else if (window->ViewportAllowPlatformMonitorExtend < 0 && (flags & ImGuiWindowFlags_ChildWindow) == 0) - { - // Regular (non-child, non-popup) windows by default are also allowed to protrude - // Child windows are kept contained within their parent. - window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor; - } - } - - // Update flags - window->ViewportOwned = (window == window->Viewport->Window); - window->ViewportId = window->Viewport->ID; - - // If the OS window has a title bar, hide our imgui title bar - //if (window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration)) - // window->Flags |= ImGuiWindowFlags_NoTitleBar; -} - -void ImGui::WindowSyncOwnedViewport(ImGuiWindow* window, ImGuiWindow* parent_window_in_stack) -{ - ImGuiContext& g = *GImGui; - - bool viewport_rect_changed = false; - - // Synchronize window --> viewport in most situations - // Synchronize viewport -> window in case the platform window has been moved or resized from the OS/WM - if (window->Viewport->PlatformRequestMove) - { - window->Pos = window->Viewport->Pos; - MarkIniSettingsDirty(window); - } - else if (memcmp(&window->Viewport->Pos, &window->Pos, sizeof(window->Pos)) != 0) - { - viewport_rect_changed = true; - window->Viewport->Pos = window->Pos; - } - - if (window->Viewport->PlatformRequestResize) - { - window->Size = window->SizeFull = window->Viewport->Size; - MarkIniSettingsDirty(window); - } - else if (memcmp(&window->Viewport->Size, &window->Size, sizeof(window->Size)) != 0) - { - viewport_rect_changed = true; - window->Viewport->Size = window->Size; - } - window->Viewport->UpdateWorkRect(); - - // The viewport may have changed monitor since the global update in UpdateViewportsNewFrame() - // Either a SetNextWindowPos() call in the current frame or a SetWindowPos() call in the previous frame may have this effect. - if (viewport_rect_changed) - UpdateViewportPlatformMonitor(window->Viewport); - - // Update common viewport flags - const ImGuiViewportFlags viewport_flags_to_clear = ImGuiViewportFlags_TopMost | ImGuiViewportFlags_NoTaskBarIcon | ImGuiViewportFlags_NoDecoration | ImGuiViewportFlags_NoRendererClear; - ImGuiViewportFlags viewport_flags = window->Viewport->Flags & ~viewport_flags_to_clear; - ImGuiWindowFlags window_flags = window->Flags; - const bool is_modal = (window_flags & ImGuiWindowFlags_Modal) != 0; - const bool is_short_lived_floating_window = (window_flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0; - if (window_flags & ImGuiWindowFlags_Tooltip) - viewport_flags |= ImGuiViewportFlags_TopMost; - if ((g.IO.ConfigViewportsNoTaskBarIcon || is_short_lived_floating_window) && !is_modal) - viewport_flags |= ImGuiViewportFlags_NoTaskBarIcon; - if (g.IO.ConfigViewportsNoDecoration || is_short_lived_floating_window) - viewport_flags |= ImGuiViewportFlags_NoDecoration; - - // Not correct to set modal as topmost because: - // - Because other popups can be stacked above a modal (e.g. combo box in a modal) - // - ImGuiViewportFlags_TopMost is currently handled different in backends: in Win32 it is "appear top most" whereas in GLFW and SDL it is "stay topmost" - //if (flags & ImGuiWindowFlags_Modal) - // viewport_flags |= ImGuiViewportFlags_TopMost; - - // For popups and menus that may be protruding out of their parent viewport, we enable _NoFocusOnClick so that clicking on them - // won't steal the OS focus away from their parent window (which may be reflected in OS the title bar decoration). - // Setting _NoFocusOnClick would technically prevent us from bringing back to front in case they are being covered by an OS window from a different app, - // but it shouldn't be much of a problem considering those are already popups that are closed when clicking elsewhere. - if (is_short_lived_floating_window && !is_modal) - viewport_flags |= ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoFocusOnClick; - - // We can overwrite viewport flags using ImGuiWindowClass (advanced users) - if (window->WindowClass.ViewportFlagsOverrideSet) - viewport_flags |= window->WindowClass.ViewportFlagsOverrideSet; - if (window->WindowClass.ViewportFlagsOverrideClear) - viewport_flags &= ~window->WindowClass.ViewportFlagsOverrideClear; - - // We can also tell the backend that clearing the platform window won't be necessary, - // as our window background is filling the viewport and we have disabled BgAlpha. - // FIXME: Work on support for per-viewport transparency (#2766) - if (!(window_flags & ImGuiWindowFlags_NoBackground)) - viewport_flags |= ImGuiViewportFlags_NoRendererClear; - - window->Viewport->Flags = viewport_flags; - - // Update parent viewport ID - // (the !IsFallbackWindow test mimic the one done in WindowSelectViewport()) - if (window->WindowClass.ParentViewportId) - window->Viewport->ParentViewportId = window->WindowClass.ParentViewportId; - else if ((window_flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && parent_window_in_stack && (!parent_window_in_stack->IsFallbackWindow || parent_window_in_stack->WasActive)) - window->Viewport->ParentViewportId = parent_window_in_stack->Viewport->ID; - else - window->Viewport->ParentViewportId = g.IO.ConfigViewportsNoDefaultParent ? 0 : IMGUI_VIEWPORT_DEFAULT_ID; -} - -// Called by user at the end of the main loop, after EndFrame() -// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api. -void ImGui::UpdatePlatformWindows() -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?"); - IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount); - g.FrameCountPlatformEnded = g.FrameCount; - if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)) - return; - - // Create/resize/destroy platform windows to match each active viewport. - // Skip the main viewport (index 0), which is always fully handled by the application! - for (int i = 1; i < g.Viewports.Size; i++) - { - ImGuiViewportP* viewport = g.Viewports[i]; - - // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window - // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame) - bool destroy_platform_window = false; - destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1); - destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window)); - if (destroy_platform_window) - { - DestroyPlatformWindow(viewport); - continue; - } - - // New windows that appears directly in a new viewport won't always have a size on their first frame - if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0) - continue; - - // Create window - bool is_new_platform_window = (viewport->PlatformWindowCreated == false); - if (is_new_platform_window) - { - IMGUI_DEBUG_LOG_VIEWPORT("Create Platform Window %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); - g.PlatformIO.Platform_CreateWindow(viewport); - if (g.PlatformIO.Renderer_CreateWindow != NULL) - g.PlatformIO.Renderer_CreateWindow(viewport); - viewport->LastNameHash = 0; - viewport->LastPlatformPos = viewport->LastPlatformSize = ImVec2(FLT_MAX, FLT_MAX); // By clearing those we'll enforce a call to Platform_SetWindowPos/Size below, before Platform_ShowWindow (FIXME: Is that necessary?) - viewport->LastRendererSize = viewport->Size; // We don't need to call Renderer_SetWindowSize() as it is expected Renderer_CreateWindow() already did it. - viewport->PlatformWindowCreated = true; - } - - // Apply Position and Size (from ImGui to Platform/Renderer backends) - if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove) - g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos); - if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize) - g.PlatformIO.Platform_SetWindowSize(viewport, viewport->Size); - if ((viewport->LastRendererSize.x != viewport->Size.x || viewport->LastRendererSize.y != viewport->Size.y) && g.PlatformIO.Renderer_SetWindowSize) - g.PlatformIO.Renderer_SetWindowSize(viewport, viewport->Size); - viewport->LastPlatformPos = viewport->Pos; - viewport->LastPlatformSize = viewport->LastRendererSize = viewport->Size; - - // Update title bar (if it changed) - if (ImGuiWindow* window_for_title = GetWindowForTitleDisplay(viewport->Window)) - { - const char* title_begin = window_for_title->Name; - char* title_end = (char*)(intptr_t)FindRenderedTextEnd(title_begin); - const ImGuiID title_hash = ImHashStr(title_begin, title_end - title_begin); - if (viewport->LastNameHash != title_hash) - { - char title_end_backup_c = *title_end; - *title_end = 0; // Cut existing buffer short instead of doing an alloc/free, no small gain. - g.PlatformIO.Platform_SetWindowTitle(viewport, title_begin); - *title_end = title_end_backup_c; - viewport->LastNameHash = title_hash; - } - } - - // Update alpha (if it changed) - if (viewport->LastAlpha != viewport->Alpha && g.PlatformIO.Platform_SetWindowAlpha) - g.PlatformIO.Platform_SetWindowAlpha(viewport, viewport->Alpha); - viewport->LastAlpha = viewport->Alpha; - - // Optional, general purpose call to allow the backend to perform general book-keeping even if things haven't changed. - if (g.PlatformIO.Platform_UpdateWindow) - g.PlatformIO.Platform_UpdateWindow(viewport); - - if (is_new_platform_window) - { - // On startup ensure new platform window don't steal focus (give it a few frames, as nested contents may lead to viewport being created a few frames late) - if (g.FrameCount < 3) - viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing; - - // Show window - g.PlatformIO.Platform_ShowWindow(viewport); - - // Even without focus, we assume the window becomes front-most. - // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available. - if (viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) - viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; - } - - // Clear request flags - viewport->ClearRequestFlags(); - } - - // Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport. - // When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored. - // FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab. - if (g.PlatformIO.Platform_GetWindowFocus != NULL) - { - ImGuiViewportP* focused_viewport = NULL; - for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++) - { - ImGuiViewportP* viewport = g.Viewports[n]; - if (viewport->PlatformWindowCreated) - if (g.PlatformIO.Platform_GetWindowFocus(viewport)) - focused_viewport = viewport; - } - - // Store a tag so we can infer z-order easily from all our windows - // We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag - // will keep the front most stamp instead of losing it back to their parent viewport. - if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID) - { - if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount) - focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount; - g.PlatformLastFocusedViewportId = focused_viewport->ID; - } } } -// This is a default/basic function for performing the rendering/swap of multiple Platform Windows. -// Custom renderers may prefer to not call this function at all, and instead iterate the publicly exposed platform data and handle rendering/sync themselves. -// The Render/Swap functions stored in ImGuiPlatformIO are merely here to allow for this helper to exist, but you can do it yourself: -// -// ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); -// for (int i = 1; i < platform_io.Viewports.Size; i++) -// if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) -// MyRenderFunction(platform_io.Viewports[i], my_args); -// for (int i = 1; i < platform_io.Viewports.Size; i++) -// if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0) -// MySwapBufferFunction(platform_io.Viewports[i], my_args); -// -void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* renderer_render_arg) -{ - // Skip the main viewport (index 0), which is always fully handled by the application! - ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); - for (int i = 1; i < platform_io.Viewports.Size; i++) - { - ImGuiViewport* viewport = platform_io.Viewports[i]; - if (viewport->Flags & ImGuiViewportFlags_Minimized) - continue; - if (platform_io.Platform_RenderWindow) platform_io.Platform_RenderWindow(viewport, platform_render_arg); - if (platform_io.Renderer_RenderWindow) platform_io.Renderer_RenderWindow(viewport, renderer_render_arg); - } - for (int i = 1; i < platform_io.Viewports.Size; i++) - { - ImGuiViewport* viewport = platform_io.Viewports[i]; - if (viewport->Flags & ImGuiViewportFlags_Minimized) - continue; - if (platform_io.Platform_SwapBuffers) platform_io.Platform_SwapBuffers(viewport, platform_render_arg); - if (platform_io.Renderer_SwapBuffers) platform_io.Renderer_SwapBuffers(viewport, renderer_render_arg); - } -} - -static int ImGui::FindPlatformMonitorForPos(const ImVec2& pos) -{ - ImGuiContext& g = *GImGui; - for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++) - { - const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n]; - if (ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize).Contains(pos)) - return monitor_n; - } - return -1; -} - -// Search for the monitor with the largest intersection area with the given rectangle -// We generally try to avoid searching loops but the monitor count should be very small here -// FIXME-OPT: We could test the last monitor used for that viewport first, and early -static int ImGui::FindPlatformMonitorForRect(const ImRect& rect) -{ - ImGuiContext& g = *GImGui; - - const int monitor_count = g.PlatformIO.Monitors.Size; - if (monitor_count <= 1) - return monitor_count - 1; - - // Use a minimum threshold of 1.0f so a zero-sized rect won't false positive, and will still find the correct monitor given its position. - // This is necessary for tooltips which always resize down to zero at first. - const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f); - int best_monitor_n = -1; - float best_monitor_surface = 0.001f; - - for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++) - { - const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n]; - const ImRect monitor_rect = ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize); - if (monitor_rect.Contains(rect)) - return monitor_n; - ImRect overlapping_rect = rect; - overlapping_rect.ClipWithFull(monitor_rect); - float overlapping_surface = overlapping_rect.GetWidth() * overlapping_rect.GetHeight(); - if (overlapping_surface < best_monitor_surface) - continue; - best_monitor_surface = overlapping_surface; - best_monitor_n = monitor_n; - } - return best_monitor_n; -} - -// Update monitor from viewport rectangle (we'll use this info to clamp windows and save windows lost in a removed monitor) -static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport) -{ - viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetMainRect()); -} - -// Return value is always != NULL, but don't hold on it across frames. -const ImGuiPlatformMonitor* ImGui::GetViewportPlatformMonitor(ImGuiViewport* viewport_p) -{ - ImGuiContext& g = *GImGui; - ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)viewport_p; - int monitor_idx = viewport->PlatformMonitor; - if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size) - return &g.PlatformIO.Monitors[monitor_idx]; - return &g.FallbackMonitor; -} - -void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport) -{ - ImGuiContext& g = *GImGui; - if (viewport->PlatformWindowCreated) - { - if (g.PlatformIO.Renderer_DestroyWindow) - g.PlatformIO.Renderer_DestroyWindow(viewport); - if (g.PlatformIO.Platform_DestroyWindow) - g.PlatformIO.Platform_DestroyWindow(viewport); - IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL); - - // Don't clear PlatformWindowCreated for the main viewport, as we initially set that up to true in Initialize() - // The righter way may be to leave it to the backend to set this flag all-together, and made the flag public. - if (viewport->ID != IMGUI_VIEWPORT_DEFAULT_ID) - viewport->PlatformWindowCreated = false; - } - else - { - IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL); - } - viewport->RendererUserData = viewport->PlatformUserData = viewport->PlatformHandle = NULL; - viewport->ClearRequestFlags(); -} - -void ImGui::DestroyPlatformWindows() -{ - // We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the backend - // to clear any data they may have stored in e.g. PlatformUserData, RendererUserData. - // It is convenient for the platform backend code to store something in the main viewport, in order for e.g. the mouse handling - // code to operator a consistent manner. - // It is expected that the backend can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without - // crashing if it doesn't have data stored. - ImGuiContext& g = *GImGui; - for (int i = 0; i < g.Viewports.Size; i++) - DestroyPlatformWindow(g.Viewports[i]); -} - - //----------------------------------------------------------------------------- // [SECTION] DOCKING //----------------------------------------------------------------------------- -// Docking: Internal Types -// Docking: Forward Declarations -// Docking: ImGuiDockContext -// Docking: ImGuiDockContext Docking/Undocking functions -// Docking: ImGuiDockNode -// Docking: ImGuiDockNode Tree manipulation functions -// Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport) -// Docking: Builder Functions -// Docking: Begin/End Support Functions (called from Begin/End) -// Docking: Settings -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -// Typical Docking call flow: (root level is generally public API): -//----------------------------------------------------------------------------- -// - NewFrame() new dear imgui frame -// | DockContextNewFrameUpdateUndocking() - process queued undocking requests -// | - DockContextProcessUndockWindow() - process one window undocking request -// | - DockContextProcessUndockNode() - process one whole node undocking request -// | DockContextNewFrameUpdateUndocking() - process queue docking requests, create floating dock nodes -// | - update g.HoveredDockNode - [debug] update node hovered by mouse -// | - DockContextProcessDock() - process one docking request -// | - DockNodeUpdate() -// | - DockNodeUpdateForRootNode() -// | - DockNodeUpdateVisibleFlagAndInactiveChilds() -// | - DockNodeFindInfo() -// | - destroy unused node or tab bar -// | - create dock node host window -// | - Begin() etc. -// | - DockNodeStartMouseMovingWindow() -// | - DockNodeTreeUpdatePosSize() -// | - DockNodeTreeUpdateSplitter() -// | - draw node background -// | - DockNodeUpdateTabBar() - create/update tab bar for a docking node -// | - DockNodeAddTabBar() -// | - DockNodeUpdateWindowMenu() -// | - DockNodeCalcTabBarLayout() -// | - BeginTabBarEx() -// | - TabItemEx() calls -// | - EndTabBar() -// | - BeginDockableDragDropTarget() -// | - DockNodeUpdate() - recurse into child nodes... -//----------------------------------------------------------------------------- -// - DockSpace() user submit a dockspace into a window -// | Begin(Child) - create a child window -// | DockNodeUpdate() - call main dock node update function -// | End(Child) -// | ItemSize() -//----------------------------------------------------------------------------- -// - Begin() -// | BeginDocked() -// | BeginDockableDragDropSource() -// | BeginDockableDragDropTarget() -// | - DockNodePreviewDockRender() -//----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -// Docking: Internal Types -//----------------------------------------------------------------------------- -// - ImGuiDockRequestType -// - ImGuiDockRequest -// - ImGuiDockPreviewData -// - ImGuiDockNodeSettings -// - ImGuiDockContext -//----------------------------------------------------------------------------- - -enum ImGuiDockRequestType -{ - ImGuiDockRequestType_None = 0, - ImGuiDockRequestType_Dock, - ImGuiDockRequestType_Undock, - ImGuiDockRequestType_Split // Split is the same as Dock but without a DockPayload -}; - -struct ImGuiDockRequest -{ - ImGuiDockRequestType Type; - ImGuiWindow* DockTargetWindow; // Destination/Target Window to dock into (may be a loose window or a DockNode, might be NULL in which case DockTargetNode cannot be NULL) - ImGuiDockNode* DockTargetNode; // Destination/Target Node to dock into - ImGuiWindow* DockPayload; // Source/Payload window to dock (may be a loose window or a DockNode), [Optional] - ImGuiDir DockSplitDir; - float DockSplitRatio; - bool DockSplitOuter; - ImGuiWindow* UndockTargetWindow; - ImGuiDockNode* UndockTargetNode; - - ImGuiDockRequest() - { - Type = ImGuiDockRequestType_None; - DockTargetWindow = DockPayload = UndockTargetWindow = NULL; - DockTargetNode = UndockTargetNode = NULL; - DockSplitDir = ImGuiDir_None; - DockSplitRatio = 0.5f; - DockSplitOuter = false; - } -}; - -struct ImGuiDockPreviewData -{ - ImGuiDockNode FutureNode; - bool IsDropAllowed; - bool IsCenterAvailable; - bool IsSidesAvailable; // Hold your breath, grammar freaks.. - bool IsSplitDirExplicit; // Set when hovered the drop rect (vs. implicit SplitDir==None when hovered the window) - ImGuiDockNode* SplitNode; - ImGuiDir SplitDir; - float SplitRatio; - ImRect DropRectsDraw[ImGuiDir_COUNT + 1]; // May be slightly different from hit-testing drop rects used in DockNodeCalcDropRects() - - ImGuiDockPreviewData() : FutureNode(0) { IsDropAllowed = IsCenterAvailable = IsSidesAvailable = IsSplitDirExplicit = false; SplitNode = NULL; SplitDir = ImGuiDir_None; SplitRatio = 0.f; for (int n = 0; n < IM_ARRAYSIZE(DropRectsDraw); n++) DropRectsDraw[n] = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX); } -}; - -// Persistent Settings data, stored contiguously in SettingsNodes (sizeof() ~32 bytes) -struct ImGuiDockNodeSettings -{ - ImGuiID ID; - ImGuiID ParentNodeId; - ImGuiID ParentWindowId; - ImGuiID SelectedTabId; - signed char SplitAxis; - char Depth; - ImGuiDockNodeFlags Flags; // NB: We save individual flags one by one in ascii format (ImGuiDockNodeFlags_SavedFlagsMask_) - ImVec2ih Pos; - ImVec2ih Size; - ImVec2ih SizeRef; - ImGuiDockNodeSettings() { memset(this, 0, sizeof(*this)); SplitAxis = ImGuiAxis_None; } -}; - -//----------------------------------------------------------------------------- -// Docking: Forward Declarations -//----------------------------------------------------------------------------- - -namespace ImGui -{ - // ImGuiDockContext - static ImGuiDockNode* DockContextAddNode(ImGuiContext* ctx, ImGuiID id); - static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node); - static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node); - static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req); - static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true); - static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); - static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx); - static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id); - static ImGuiDockNode* DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window); - static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count); - static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all - - // ImGuiDockNode - static void DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar); - static void DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node); - static void DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node); - static ImGuiWindow* DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id); - static void DockNodeApplyPosSizeToWindows(ImGuiDockNode* node); - static void DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id); - static void DockNodeHideHostWindow(ImGuiDockNode* node); - static void DockNodeUpdate(ImGuiDockNode* node); - static void DockNodeUpdateForRootNode(ImGuiDockNode* node); - static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node); - static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window); - static void DockNodeAddTabBar(ImGuiDockNode* node); - static void DockNodeRemoveTabBar(ImGuiDockNode* node); - static ImGuiID DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar); - static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node); - static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window); - static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window); - static void DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking); - static void DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, const ImGuiDockPreviewData* preview_data); - static void DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos, ImVec2* out_close_button_pos); - static void DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired); - static bool DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir dir, ImRect& out_draw, bool outer_docking, ImVec2* test_mouse_pos); - static const char* DockNodeGetHostWindowTitle(ImGuiDockNode* node, char* buf, int buf_size) { ImFormatString(buf, buf_size, "##DockNode_%02X", node->ID); return buf; } - static int DockNodeGetTabOrder(ImGuiWindow* window); - - // ImGuiDockNode tree manipulations - static void DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_first_child, float split_ratio, ImGuiDockNode* new_node); - static void DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child); - static void DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size, bool only_write_to_marked_nodes = false); - static void DockNodeTreeUpdateSplitter(ImGuiDockNode* node); - static ImGuiDockNode* DockNodeTreeFindVisibleNodeByPos(ImGuiDockNode* node, ImVec2 pos); - static ImGuiDockNode* DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node); - - // Settings - static void DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id); - static void DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count); - static ImGuiDockNodeSettings* DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID node_id); - static void DockSettingsHandler_ClearAll(ImGuiContext*, ImGuiSettingsHandler*); - static void DockSettingsHandler_ApplyAll(ImGuiContext*, ImGuiSettingsHandler*); - static void* DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name); - static void DockSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line); - static void DockSettingsHandler_WriteAll(ImGuiContext* imgui_ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf); -} - -//----------------------------------------------------------------------------- -// Docking: ImGuiDockContext -//----------------------------------------------------------------------------- -// The lifetime model is different from the one of regular windows: we always create a ImGuiDockNode for each ImGuiDockNodeSettings, -// or we always hold the entire docking node tree. Nodes are frequently hidden, e.g. if the window(s) or child nodes they host are not active. -// At boot time only, we run a simple GC to remove nodes that have no references. -// Because dock node settings (which are small, contiguous structures) are always mirrored by their corresponding dock nodes (more complete structures), -// we can also very easily recreate the nodes from scratch given the settings data (this is what DockContextRebuild() does). -// This is convenient as docking reconfiguration can be implemented by mostly poking at the simpler settings data. -//----------------------------------------------------------------------------- -// - DockContextInitialize() -// - DockContextShutdown() -// - DockContextClearNodes() -// - DockContextRebuildNodes() -// - DockContextNewFrameUpdateUndocking() -// - DockContextNewFrameUpdateDocking() -// - DockContextFindNodeByID() -// - DockContextBindNodeToWindow() -// - DockContextGenNodeID() -// - DockContextAddNode() -// - DockContextRemoveNode() -// - ImGuiDockContextPruneNodeData -// - DockContextPruneUnusedSettingsNodes() -// - DockContextBuildNodesFromSettings() -// - DockContextBuildAddWindowsToNodes() -//----------------------------------------------------------------------------- - -void ImGui::DockContextInitialize(ImGuiContext* ctx) -{ - ImGuiContext& g = *ctx; - - // Add .ini handle for persistent docking data - ImGuiSettingsHandler ini_handler; - ini_handler.TypeName = "Docking"; - ini_handler.TypeHash = ImHashStr("Docking"); - ini_handler.ClearAllFn = DockSettingsHandler_ClearAll; - ini_handler.ReadInitFn = DockSettingsHandler_ClearAll; // Also clear on read - ini_handler.ReadOpenFn = DockSettingsHandler_ReadOpen; - ini_handler.ReadLineFn = DockSettingsHandler_ReadLine; - ini_handler.ApplyAllFn = DockSettingsHandler_ApplyAll; - ini_handler.WriteAllFn = DockSettingsHandler_WriteAll; - g.SettingsHandlers.push_back(ini_handler); -} - -void ImGui::DockContextShutdown(ImGuiContext* ctx) -{ - ImGuiDockContext* dc = &ctx->DockContext; - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - IM_DELETE(node); -} - -void ImGui::DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_settings_refs) -{ - IM_UNUSED(ctx); - IM_ASSERT(ctx == GImGui); - DockBuilderRemoveNodeDockedWindows(root_id, clear_settings_refs); - DockBuilderRemoveNodeChildNodes(root_id); -} - -// [DEBUG] This function also acts as a defacto test to make sure we can rebuild from scratch without a glitch -// (Different from DockSettingsHandler_ClearAll() + DockSettingsHandler_ApplyAll() because this reuses current settings!) -void ImGui::DockContextRebuildNodes(ImGuiContext* ctx) -{ - IMGUI_DEBUG_LOG_DOCKING("DockContextRebuild()\n"); - ImGuiDockContext* dc = &ctx->DockContext; - SaveIniSettingsToMemory(); - ImGuiID root_id = 0; // Rebuild all - DockContextClearNodes(ctx, root_id, false); - DockContextBuildNodesFromSettings(ctx, dc->NodesSettings.Data, dc->NodesSettings.Size); - DockContextBuildAddWindowsToNodes(ctx, root_id); -} - -// Docking context update function, called by NewFrame() -void ImGui::DockContextNewFrameUpdateUndocking(ImGuiContext* ctx) -{ - ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) - { - if (dc->Nodes.Data.Size > 0 || dc->Requests.Size > 0) - DockContextClearNodes(ctx, 0, true); - return; - } - - // Setting NoSplit at runtime merges all nodes - if (g.IO.ConfigDockingNoSplit) - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (node->IsRootNode() && node->IsSplitNode()) - { - DockBuilderRemoveNodeChildNodes(node->ID); - //dc->WantFullRebuild = true; - } - - // Process full rebuild -#if 0 - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_C))) - dc->WantFullRebuild = true; -#endif - if (dc->WantFullRebuild) - { - DockContextRebuildNodes(ctx); - dc->WantFullRebuild = false; - } - - // Process Undocking requests (we need to process them _before_ the UpdateMouseMovingWindowNewFrame call in NewFrame) - for (int n = 0; n < dc->Requests.Size; n++) - { - ImGuiDockRequest* req = &dc->Requests[n]; - if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetWindow) - DockContextProcessUndockWindow(ctx, req->UndockTargetWindow); - else if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetNode) - DockContextProcessUndockNode(ctx, req->UndockTargetNode); - } -} - -// Docking context update function, called by NewFrame() -void ImGui::DockContextNewFrameUpdateDocking(ImGuiContext* ctx) -{ - ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) - return; - - // [DEBUG] Store hovered dock node. - // We could in theory use DockNodeTreeFindVisibleNodeByPos() on the root host dock node, but using ->DockNode is a good shortcut. - // Note this is mostly a debug thing and isn't actually used for docking target, because docking involve more detailed filtering. - g.HoveredDockNode = NULL; - if (ImGuiWindow* hovered_window = g.HoveredWindowUnderMovingWindow) - { - if (hovered_window->DockNodeAsHost) - g.HoveredDockNode = DockNodeTreeFindVisibleNodeByPos(hovered_window->DockNodeAsHost, g.IO.MousePos); - else if (hovered_window->RootWindow->DockNode) - g.HoveredDockNode = hovered_window->RootWindow->DockNode; - } - - // Process Docking requests - for (int n = 0; n < dc->Requests.Size; n++) - if (dc->Requests[n].Type == ImGuiDockRequestType_Dock) - DockContextProcessDock(ctx, &dc->Requests[n]); - dc->Requests.resize(0); - - // Create windows for each automatic docking nodes - // We can have NULL pointers when we delete nodes, but because ID are recycled this should amortize nicely (and our node count will never be very high) - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (node->IsFloatingNode()) - DockNodeUpdate(node); -} - -static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id) -{ - return (ImGuiDockNode*)ctx->DockContext.Nodes.GetVoidPtr(id); -} - -ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx) -{ - // Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used) - // FIXME-OPT FIXME-DOCK: This is suboptimal, even if the node count is small enough not to be a worry.0 - // We should poke in ctx->Nodes to find a suitable ID faster. Even more so trivial that ctx->Nodes lookup is already sorted. - ImGuiID id = 0x0001; - while (DockContextFindNodeByID(ctx, id) != NULL) - id++; - return id; -} - -static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id) -{ - // Generate an ID for the new node (the exact ID value doesn't matter as long as it is not already used) and add the first window. - if (id == 0) - id = DockContextGenNodeID(ctx); - else - IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL); - - // We don't set node->LastFrameAlive on construction. Nodes are always created at all time to reflect .ini settings! - IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id); - ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id); - ctx->DockContext.Nodes.SetVoidPtr(node->ID, node); - return node; -} - -static void ImGui::DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node) -{ - ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; - - IMGUI_DEBUG_LOG_DOCKING("DockContextRemoveNode 0x%08X\n", node->ID); - IM_ASSERT(DockContextFindNodeByID(ctx, node->ID) == node); - IM_ASSERT(node->ChildNodes[0] == NULL && node->ChildNodes[1] == NULL); - IM_ASSERT(node->Windows.Size == 0); - - if (node->HostWindow) - node->HostWindow->DockNodeAsHost = NULL; - - ImGuiDockNode* parent_node = node->ParentNode; - const bool merge = (merge_sibling_into_parent_node && parent_node != NULL); - if (merge) - { - IM_ASSERT(parent_node->ChildNodes[0] == node || parent_node->ChildNodes[1] == node); - ImGuiDockNode* sibling_node = (parent_node->ChildNodes[0] == node ? parent_node->ChildNodes[1] : parent_node->ChildNodes[0]); - DockNodeTreeMerge(&g, parent_node, sibling_node); - } - else - { - for (int n = 0; parent_node && n < IM_ARRAYSIZE(parent_node->ChildNodes); n++) - if (parent_node->ChildNodes[n] == node) - node->ParentNode->ChildNodes[n] = NULL; - dc->Nodes.SetVoidPtr(node->ID, NULL); - IM_DELETE(node); - } -} - -static int IMGUI_CDECL DockNodeComparerDepthMostFirst(const void* lhs, const void* rhs) -{ - const ImGuiDockNode* a = *(const ImGuiDockNode* const*)lhs; - const ImGuiDockNode* b = *(const ImGuiDockNode* const*)rhs; - return ImGui::DockNodeGetDepth(b) - ImGui::DockNodeGetDepth(a); -} - -// Pre C++0x doesn't allow us to use a function-local type (without linkage) as template parameter, so we moved this here. -struct ImGuiDockContextPruneNodeData -{ - int CountWindows, CountChildWindows, CountChildNodes; - ImGuiID RootId; - ImGuiDockContextPruneNodeData() { CountWindows = CountChildWindows = CountChildNodes = 0; RootId = 0; } -}; - -// Garbage collect unused nodes (run once at init time) -static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) -{ - ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; - IM_ASSERT(g.Windows.Size == 0); - - ImPool pool; - pool.Reserve(dc->NodesSettings.Size); - - // Count child nodes and compute RootID - for (int settings_n = 0; settings_n < dc->NodesSettings.Size; settings_n++) - { - ImGuiDockNodeSettings* settings = &dc->NodesSettings[settings_n]; - ImGuiDockContextPruneNodeData* parent_data = settings->ParentNodeId ? pool.GetByKey(settings->ParentNodeId) : 0; - pool.GetOrAddByKey(settings->ID)->RootId = parent_data ? parent_data->RootId : settings->ID; - if (settings->ParentNodeId) - pool.GetOrAddByKey(settings->ParentNodeId)->CountChildNodes++; - } - - // Count reference to dock ids from dockspaces - // We track the 'auto-DockNode <- manual-Window <- manual-DockSpace' in order to avoid 'auto-DockNode' being ditched by DockContextPruneUnusedSettingsNodes() - for (int settings_n = 0; settings_n < dc->NodesSettings.Size; settings_n++) - { - ImGuiDockNodeSettings* settings = &dc->NodesSettings[settings_n]; - if (settings->ParentWindowId != 0) - if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->ParentWindowId)) - if (window_settings->DockId) - if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(window_settings->DockId)) - data->CountChildNodes++; - } - - // Count reference to dock ids from window settings - // We guard against the possibility of an invalid .ini file (RootID may point to a missing node) - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (ImGuiID dock_id = settings->DockId) - if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(dock_id)) - { - data->CountWindows++; - if (ImGuiDockContextPruneNodeData* data_root = (data->RootId == dock_id) ? data : pool.GetByKey(data->RootId)) - data_root->CountChildWindows++; - } - - // Prune - for (int settings_n = 0; settings_n < dc->NodesSettings.Size; settings_n++) - { - ImGuiDockNodeSettings* settings = &dc->NodesSettings[settings_n]; - ImGuiDockContextPruneNodeData* data = pool.GetByKey(settings->ID); - if (data->CountWindows > 1) - continue; - ImGuiDockContextPruneNodeData* data_root = (data->RootId == settings->ID) ? data : pool.GetByKey(data->RootId); - - bool remove = false; - remove |= (data->CountWindows == 1 && settings->ParentNodeId == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window - remove |= (data->CountWindows == 0 && settings->ParentNodeId == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window - remove |= (data_root->CountChildWindows == 0); - if (remove) - { - IMGUI_DEBUG_LOG_DOCKING("DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); - DockSettingsRemoveNodeReferences(&settings->ID, 1); - settings->ID = 0; - } - } -} - -static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count) -{ - // Build nodes - for (int node_n = 0; node_n < node_settings_count; node_n++) - { - ImGuiDockNodeSettings* settings = &node_settings_array[node_n]; - if (settings->ID == 0) - continue; - ImGuiDockNode* node = DockContextAddNode(ctx, settings->ID); - node->ParentNode = settings->ParentNodeId ? DockContextFindNodeByID(ctx, settings->ParentNodeId) : NULL; - node->Pos = ImVec2(settings->Pos.x, settings->Pos.y); - node->Size = ImVec2(settings->Size.x, settings->Size.y); - node->SizeRef = ImVec2(settings->SizeRef.x, settings->SizeRef.y); - node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_DockNode; - if (node->ParentNode && node->ParentNode->ChildNodes[0] == NULL) - node->ParentNode->ChildNodes[0] = node; - else if (node->ParentNode && node->ParentNode->ChildNodes[1] == NULL) - node->ParentNode->ChildNodes[1] = node; - node->SelectedTabId = settings->SelectedTabId; - node->SplitAxis = (ImGuiAxis)settings->SplitAxis; - node->SetLocalFlags(settings->Flags & ImGuiDockNodeFlags_SavedFlagsMask_); - - // Bind host window immediately if it already exist (in case of a rebuild) - // This is useful as the RootWindowForTitleBarHighlight links necessary to highlight the currently focused node requires node->HostWindow to be set. - char host_window_title[20]; - ImGuiDockNode* root_node = DockNodeGetRootNode(node); - node->HostWindow = FindWindowByName(DockNodeGetHostWindowTitle(root_node, host_window_title, IM_ARRAYSIZE(host_window_title))); - } -} - -void ImGui::DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id) -{ - // Rebind all windows to nodes (they can also lazily rebind but we'll have a visible glitch during the first frame) - ImGuiContext& g = *ctx; - for (int n = 0; n < g.Windows.Size; n++) - { - ImGuiWindow* window = g.Windows[n]; - if (window->DockId == 0 || window->LastFrameActive < g.FrameCount - 1) - continue; - if (window->DockNode != NULL) - continue; - - ImGuiDockNode* node = DockContextFindNodeByID(ctx, window->DockId); - IM_ASSERT(node != NULL); // This should have been called after DockContextBuildNodesFromSettings() - if (root_id == 0 || DockNodeGetRootNode(node)->ID == root_id) - DockNodeAddWindow(node, window, true); - } -} - -//----------------------------------------------------------------------------- -// Docking: ImGuiDockContext Docking/Undocking functions -//----------------------------------------------------------------------------- -// - DockContextQueueDock() -// - DockContextQueueUndockWindow() -// - DockContextQueueUndockNode() -// - DockContextQueueNotifyRemovedNode() -// - DockContextProcessDock() -// - DockContextProcessUndockWindow() -// - DockContextProcessUndockNode() -// - DockContextCalcDropPosForDocking() -//----------------------------------------------------------------------------- - -void ImGui::DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer) -{ - IM_ASSERT(target != payload); - ImGuiDockRequest req; - req.Type = ImGuiDockRequestType_Dock; - req.DockTargetWindow = target; - req.DockTargetNode = target_node; - req.DockPayload = payload; - req.DockSplitDir = split_dir; - req.DockSplitRatio = split_ratio; - req.DockSplitOuter = split_outer; - ctx->DockContext.Requests.push_back(req); -} - -void ImGui::DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window) -{ - ImGuiDockRequest req; - req.Type = ImGuiDockRequestType_Undock; - req.UndockTargetWindow = window; - ctx->DockContext.Requests.push_back(req); -} - -void ImGui::DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) -{ - ImGuiDockRequest req; - req.Type = ImGuiDockRequestType_Undock; - req.UndockTargetNode = node; - ctx->DockContext.Requests.push_back(req); -} - -void ImGui::DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node) -{ - ImGuiDockContext* dc = &ctx->DockContext; - for (int n = 0; n < dc->Requests.Size; n++) - if (dc->Requests[n].DockTargetNode == node) - dc->Requests[n].Type = ImGuiDockRequestType_None; -} - -void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) -{ - IM_ASSERT((req->Type == ImGuiDockRequestType_Dock && req->DockPayload != NULL) || (req->Type == ImGuiDockRequestType_Split && req->DockPayload == NULL)); - IM_ASSERT(req->DockTargetWindow != NULL || req->DockTargetNode != NULL); - - ImGuiContext& g = *ctx; - IM_UNUSED(g); - - ImGuiWindow* payload_window = req->DockPayload; // Optional - ImGuiWindow* target_window = req->DockTargetWindow; - ImGuiDockNode* node = req->DockTargetNode; - if (payload_window) - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window ? payload_window->Name : "NULL", req->DockSplitDir); - else - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir); - - // Decide which Tab will be selected at the end of the operation - ImGuiID next_selected_id = 0; - ImGuiDockNode* payload_node = NULL; - if (payload_window) - { - payload_node = payload_window->DockNodeAsHost; - payload_window->DockNodeAsHost = NULL; // Important to clear this as the node will have its life as a child which might be merged/deleted later. - if (payload_node && payload_node->IsLeafNode()) - next_selected_id = payload_node->TabBar->NextSelectedTabId ? payload_node->TabBar->NextSelectedTabId : payload_node->TabBar->SelectedTabId; - if (payload_node == NULL) - next_selected_id = payload_window->ID; - } - - // FIXME-DOCK: When we are trying to dock an existing single-window node into a loose window, transfer Node ID as well - // When processing an interactive split, usually LastFrameAlive will be < g.FrameCount. But DockBuilder operations can make it ==. - if (node) - IM_ASSERT(node->LastFrameAlive <= g.FrameCount); - if (node && target_window && node == target_window->DockNodeAsHost) - IM_ASSERT(node->Windows.Size > 0 || node->IsSplitNode() || node->IsCentralNode()); - - // Create new node and add existing window to it - if (node == NULL) - { - node = DockContextAddNode(ctx, 0); - node->Pos = target_window->Pos; - node->Size = target_window->Size; - if (target_window->DockNodeAsHost == NULL) - { - DockNodeAddWindow(node, target_window, true); - node->TabBar->Tabs[0].Flags &= ~ImGuiTabItemFlags_Unsorted; - target_window->DockIsActive = true; - } - } - - ImGuiDir split_dir = req->DockSplitDir; - if (split_dir != ImGuiDir_None) - { - // Split into two, one side will be our payload node unless we are dropping a loose window - const ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y; - const int split_inheritor_child_idx = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0; // Current contents will be moved to the opposite side - const float split_ratio = req->DockSplitRatio; - DockNodeTreeSplit(ctx, node, split_axis, split_inheritor_child_idx, split_ratio, payload_node); // payload_node may be NULL here! - ImGuiDockNode* new_node = node->ChildNodes[split_inheritor_child_idx ^ 1]; - new_node->HostWindow = node->HostWindow; - node = new_node; - } - node->SetLocalFlags(node->LocalFlags & ~ImGuiDockNodeFlags_HiddenTabBar); - - if (node != payload_node) - { - // Create tab bar before we call DockNodeMoveWindows (which would attempt to move the old tab-bar, which would lead us to payload tabs wrongly appearing before target tabs!) - if (node->Windows.Size > 0 && node->TabBar == NULL) - { - DockNodeAddTabBar(node); - for (int n = 0; n < node->Windows.Size; n++) - TabBarAddTab(node->TabBar, ImGuiTabItemFlags_None, node->Windows[n]); - } - - if (payload_node != NULL) - { - // Transfer full payload node (with 1+ child windows or child nodes) - if (payload_node->IsSplitNode()) - { - if (node->Windows.Size > 0) - { - // We can dock a split payload into a node that already has windows _only_ if our payload is a node tree with a single visible node. - // In this situation, we move the windows of the target node into the currently visible node of the payload. - // This allows us to preserve some of the underlying dock tree settings nicely. - IM_ASSERT(payload_node->OnlyNodeWithWindows != NULL); // The docking should have been blocked by DockNodePreviewDockSetup() early on and never submitted. - ImGuiDockNode* visible_node = payload_node->OnlyNodeWithWindows; - if (visible_node->TabBar) - IM_ASSERT(visible_node->TabBar->Tabs.Size > 0); - DockNodeMoveWindows(node, visible_node); - DockNodeMoveWindows(visible_node, node); - DockSettingsRenameNodeReferences(node->ID, visible_node->ID); - } - if (node->IsCentralNode()) - { - // Central node property needs to be moved to a leaf node, pick the last focused one. - // FIXME-DOCK: If we had to transfer other flags here, what would the policy be? - ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeId); - IM_ASSERT(last_focused_node != NULL); - ImGuiDockNode* last_focused_root_node = DockNodeGetRootNode(last_focused_node); - IM_ASSERT(last_focused_root_node == DockNodeGetRootNode(payload_node)); - last_focused_node->SetLocalFlags(last_focused_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode); - node->SetLocalFlags(node->LocalFlags & ~ImGuiDockNodeFlags_CentralNode); - last_focused_root_node->CentralNode = last_focused_node; - } - - IM_ASSERT(node->Windows.Size == 0); - DockNodeMoveChildNodes(node, payload_node); - } - else - { - const ImGuiID payload_dock_id = payload_node->ID; - DockNodeMoveWindows(node, payload_node); - DockSettingsRenameNodeReferences(payload_dock_id, node->ID); - } - DockContextRemoveNode(ctx, payload_node, true); - } - else if (payload_window) - { - // Transfer single window - const ImGuiID payload_dock_id = payload_window->DockId; - node->VisibleWindow = payload_window; - DockNodeAddWindow(node, payload_window, true); - if (payload_dock_id != 0) - DockSettingsRenameNodeReferences(payload_dock_id, node->ID); - } - } - else - { - // When docking a floating single window node we want to reevaluate auto-hiding of the tab bar - node->WantHiddenTabBarUpdate = true; - } - - // Update selection immediately - if (ImGuiTabBar* tab_bar = node->TabBar) - tab_bar->NextSelectedTabId = next_selected_id; - MarkIniSettingsDirty(); -} - -// Problem: -// Undocking a large (~full screen) window would leave it so large that the bottom right sizing corner would more -// than likely be off the screen and the window would be hard to resize to fit on screen. This can be particularly problematic -// with 'ConfigWindowsMoveFromTitleBarOnly=true' and/or with 'ConfigWindowsResizeFromEdges=false' as well (the later can be -// due to missing ImGuiBackendFlags_HasMouseCursors backend flag). -// Solution: -// When undocking a window we currently force its maximum size to 90% of the host viewport or monitor. -// Reevaluate this when we implement preserving docked/undocked size ("docking_wip/undocked_size" branch). -static ImVec2 FixLargeWindowsWhenUndocking(const ImVec2& size, ImGuiViewport* ref_viewport) -{ - if (ref_viewport == NULL) - return size; - - ImGuiContext& g = *GImGui; - ImVec2 max_size = ImFloor(ref_viewport->WorkSize * 0.90f); - if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) - { - const ImGuiPlatformMonitor* monitor = ImGui::GetViewportPlatformMonitor(ref_viewport); - max_size = ImFloor(monitor->WorkSize * 0.90f); - } - return ImMin(size, max_size); -} - -void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref) -{ - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); - IM_UNUSED(ctx); - if (window->DockNode) - DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId); - else - window->DockId = 0; - window->Collapsed = false; - window->DockIsActive = false; - window->DockNodeIsVisible = window->DockTabIsVisible = false; - window->Size = window->SizeFull = FixLargeWindowsWhenUndocking(window->SizeFull, window->Viewport); - - MarkIniSettingsDirty(); -} - -void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) -{ - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockNode node %08X\n", node->ID); - IM_ASSERT(node->IsLeafNode()); - IM_ASSERT(node->Windows.Size >= 1); - - if (node->IsRootNode() || node->IsCentralNode()) - { - // In the case of a root node or central node, the node will have to stay in place. Create a new node to receive the payload. - ImGuiDockNode* new_node = DockContextAddNode(ctx, 0); - new_node->Pos = node->Pos; - new_node->Size = node->Size; - new_node->SizeRef = node->SizeRef; - DockNodeMoveWindows(new_node, node); - DockSettingsRenameNodeReferences(node->ID, new_node->ID); - for (int n = 0; n < new_node->Windows.Size; n++) - UpdateWindowParentAndRootLinks(new_node->Windows[n], new_node->Windows[n]->Flags, NULL); - node = new_node; - } - else - { - // Otherwise extract our node and merge our sibling back into the parent node. - IM_ASSERT(node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node); - int index_in_parent = (node->ParentNode->ChildNodes[0] == node) ? 0 : 1; - node->ParentNode->ChildNodes[index_in_parent] = NULL; - DockNodeTreeMerge(ctx, node->ParentNode, node->ParentNode->ChildNodes[index_in_parent ^ 1]); - node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport - node->ParentNode = NULL; - } - node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_DockNode; - node->Size = FixLargeWindowsWhenUndocking(node->Size, node->Windows[0]->Viewport); - node->WantMouseMove = true; - MarkIniSettingsDirty(); -} - -// This is mostly used for automation. -bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos) -{ - // In DockNodePreviewDockSetup() for a root central node instead of showing both "inner" and "outer" drop rects - // (which would be functionally identical) we only show the outer one. Reflect this here. - if (target_node && target_node->ParentNode == NULL && target_node->IsCentralNode() && split_dir != ImGuiDir_None) - split_outer = true; - ImGuiDockPreviewData split_data; - DockNodePreviewDockSetup(target, target_node, payload, &split_data, false, split_outer); - if (split_data.DropRectsDraw[split_dir+1].IsInverted()) - return false; - *out_pos = split_data.DropRectsDraw[split_dir+1].GetCenter(); - return true; -} - -//----------------------------------------------------------------------------- -// Docking: ImGuiDockNode -//----------------------------------------------------------------------------- -// - DockNodeGetTabOrder() -// - DockNodeAddWindow() -// - DockNodeRemoveWindow() -// - DockNodeMoveChildNodes() -// - DockNodeMoveWindows() -// - DockNodeApplyPosSizeToWindows() -// - DockNodeHideHostWindow() -// - ImGuiDockNodeFindInfoResults -// - DockNodeFindInfo() -// - DockNodeFindWindowByID() -// - DockNodeUpdateVisibleFlagAndInactiveChilds() -// - DockNodeUpdateVisibleFlag() -// - DockNodeStartMouseMovingWindow() -// - DockNodeUpdate() -// - DockNodeUpdateWindowMenu() -// - DockNodeBeginAmendTabBar() -// - DockNodeEndAmendTabBar() -// - DockNodeUpdateTabBar() -// - DockNodeAddTabBar() -// - DockNodeRemoveTabBar() -// - DockNodeIsDropAllowedOne() -// - DockNodeIsDropAllowed() -// - DockNodeCalcTabBarLayout() -// - DockNodeCalcSplitRects() -// - DockNodeCalcDropRectsAndTestMousePos() -// - DockNodePreviewDockSetup() -// - DockNodePreviewDockRender() -//----------------------------------------------------------------------------- - -ImGuiDockNode::ImGuiDockNode(ImGuiID id) -{ - ID = id; - SharedFlags = LocalFlags = LocalFlagsInWindows = MergedFlags = ImGuiDockNodeFlags_None; - ParentNode = ChildNodes[0] = ChildNodes[1] = NULL; - TabBar = NULL; - SplitAxis = ImGuiAxis_None; - - State = ImGuiDockNodeState_Unknown; - HostWindow = VisibleWindow = NULL; - CentralNode = OnlyNodeWithWindows = NULL; - LastFrameAlive = LastFrameActive = LastFrameFocused = -1; - LastFocusedNodeId = 0; - SelectedTabId = 0; - WantCloseTabId = 0; - AuthorityForPos = AuthorityForSize = ImGuiDataAuthority_DockNode; - AuthorityForViewport = ImGuiDataAuthority_Auto; - IsVisible = true; - IsFocused = HasCloseButton = HasWindowMenuButton = false; - WantCloseAll = WantLockSizeOnce = WantMouseMove = WantHiddenTabBarUpdate = WantHiddenTabBarToggle = false; - MarkedForPosSizeWrite = false; -} - -ImGuiDockNode::~ImGuiDockNode() -{ - IM_DELETE(TabBar); - TabBar = NULL; - ChildNodes[0] = ChildNodes[1] = NULL; -} - -int ImGui::DockNodeGetTabOrder(ImGuiWindow* window) -{ - ImGuiTabBar* tab_bar = window->DockNode->TabBar; - if (tab_bar == NULL) - return -1; - ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->ID); - return tab ? tab_bar->GetTabOrder(tab) : -1; -} - -static void DockNodeHideWindowDuringHostWindowCreation(ImGuiWindow* window) -{ - window->Hidden = true; - window->HiddenFramesCanSkipItems = window->Active ? 1 : 2; -} - -static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar) -{ - ImGuiContext& g = *GImGui; (void)g; - if (window->DockNode) - { - // Can overwrite an existing window->DockNode (e.g. pointing to a disabled DockSpace node) - IM_ASSERT(window->DockNode->ID != node->ID); - DockNodeRemoveWindow(window->DockNode, window, 0); - } - IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL); - IMGUI_DEBUG_LOG_DOCKING("DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name); - - // If more than 2 windows appeared on the same frame leading to the creation of a new hosting window, - // we'll hide windows until the host window is ready. Hide the 1st window after its been output (so it is not visible for one frame). - // We will call DockNodeHideWindowDuringHostWindowCreation() on ourselves in Begin() - if (node->HostWindow == NULL && node->Windows.Size == 1 && node->Windows[0]->WasActive == false) - DockNodeHideWindowDuringHostWindowCreation(node->Windows[0]); - - node->Windows.push_back(window); - node->WantHiddenTabBarUpdate = true; - window->DockNode = node; - window->DockId = node->ID; - window->DockIsActive = (node->Windows.Size > 1); - window->DockTabWantClose = false; - - // When reactivating a node with one or two loose window, the window pos/size/viewport are authoritative over the node storage. - // In particular it is important we init the viewport from the first window so we don't create two viewports and drop one. - if (node->HostWindow == NULL && node->IsFloatingNode()) - { - if (node->AuthorityForPos == ImGuiDataAuthority_Auto) - node->AuthorityForPos = ImGuiDataAuthority_Window; - if (node->AuthorityForSize == ImGuiDataAuthority_Auto) - node->AuthorityForSize = ImGuiDataAuthority_Window; - if (node->AuthorityForViewport == ImGuiDataAuthority_Auto) - node->AuthorityForViewport = ImGuiDataAuthority_Window; - } - - // Add to tab bar if requested - if (add_to_tab_bar) - { - if (node->TabBar == NULL) - { - DockNodeAddTabBar(node); - node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabId; - - // Add existing windows - for (int n = 0; n < node->Windows.Size - 1; n++) - TabBarAddTab(node->TabBar, ImGuiTabItemFlags_None, node->Windows[n]); - } - TabBarAddTab(node->TabBar, ImGuiTabItemFlags_Unsorted, window); - } - - DockNodeUpdateVisibleFlag(node); - - // Update this without waiting for the next time we Begin() in the window, so our host window will have the proper title bar color on its first frame. - if (node->HostWindow) - UpdateWindowParentAndRootLinks(window, window->Flags | ImGuiWindowFlags_ChildWindow, node->HostWindow); -} - -static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(window->DockNode == node); - //IM_ASSERT(window->RootWindowDockTree == node->HostWindow); - //IM_ASSERT(window->LastFrameActive < g.FrameCount); // We may call this from Begin() - IM_ASSERT(save_dock_id == 0 || save_dock_id == node->ID); - IMGUI_DEBUG_LOG_DOCKING("DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name); - - window->DockNode = NULL; - window->DockIsActive = window->DockTabWantClose = false; - window->DockId = save_dock_id; - UpdateWindowParentAndRootLinks(window, window->Flags & ~ImGuiWindowFlags_ChildWindow, NULL); // Update immediately - - // Remove window - bool erased = false; - for (int n = 0; n < node->Windows.Size; n++) - if (node->Windows[n] == window) - { - node->Windows.erase(node->Windows.Data + n); - erased = true; - break; - } - IM_ASSERT(erased); - if (node->VisibleWindow == window) - node->VisibleWindow = NULL; - - // Remove tab and possibly tab bar - node->WantHiddenTabBarUpdate = true; - if (node->TabBar) - { - TabBarRemoveTab(node->TabBar, window->ID); - const int tab_count_threshold_for_tab_bar = node->IsCentralNode() ? 1 : 2; - if (node->Windows.Size < tab_count_threshold_for_tab_bar) - DockNodeRemoveTabBar(node); - } - - if (node->Windows.Size == 0 && !node->IsCentralNode() && !node->IsDockSpace() && window->DockId != node->ID) - { - // Automatic dock node delete themselves if they are not holding at least one tab - DockContextRemoveNode(&g, node, true); - return; - } - - if (node->Windows.Size == 1 && !node->IsCentralNode() && node->HostWindow) - { - ImGuiWindow* remaining_window = node->Windows[0]; - if (node->HostWindow->ViewportOwned && node->IsRootNode()) - { - // Transfer viewport back to the remaining loose window - IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow); - node->HostWindow->Viewport->Window = remaining_window; - node->HostWindow->Viewport->ID = remaining_window->ID; - } - remaining_window->Collapsed = node->HostWindow->Collapsed; - } - - // Update visibility immediately is required so the DockNodeUpdateRemoveInactiveChilds() processing can reflect changes up the tree - DockNodeUpdateVisibleFlag(node); -} - -static void ImGui::DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node) -{ - IM_ASSERT(dst_node->Windows.Size == 0); - dst_node->ChildNodes[0] = src_node->ChildNodes[0]; - dst_node->ChildNodes[1] = src_node->ChildNodes[1]; - if (dst_node->ChildNodes[0]) - dst_node->ChildNodes[0]->ParentNode = dst_node; - if (dst_node->ChildNodes[1]) - dst_node->ChildNodes[1]->ParentNode = dst_node; - dst_node->SplitAxis = src_node->SplitAxis; - dst_node->SizeRef = src_node->SizeRef; - src_node->ChildNodes[0] = src_node->ChildNodes[1] = NULL; -} - -static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node) -{ - // Insert tabs in the same orders as currently ordered (node->Windows isn't ordered) - IM_ASSERT(src_node && dst_node && dst_node != src_node); - ImGuiTabBar* src_tab_bar = src_node->TabBar; - if (src_tab_bar != NULL) - IM_ASSERT(src_node->Windows.Size <= src_node->TabBar->Tabs.Size); - - // If the dst_node is empty we can just move the entire tab bar (to preserve selection, scrolling, etc.) - bool move_tab_bar = (src_tab_bar != NULL) && (dst_node->TabBar == NULL); - if (move_tab_bar) - { - dst_node->TabBar = src_node->TabBar; - src_node->TabBar = NULL; - } - - for (int n = 0; n < src_node->Windows.Size; n++) - { - // DockNode's TabBar may have non-window Tabs manually appended by user - if (ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n]) - { - window->DockNode = NULL; - window->DockIsActive = false; - DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true); - } - } - src_node->Windows.clear(); - - if (!move_tab_bar && src_node->TabBar) - { - if (dst_node->TabBar) - dst_node->TabBar->SelectedTabId = src_node->TabBar->SelectedTabId; - DockNodeRemoveTabBar(src_node); - } -} - -static void ImGui::DockNodeApplyPosSizeToWindows(ImGuiDockNode* node) -{ - for (int n = 0; n < node->Windows.Size; n++) - { - SetWindowPos(node->Windows[n], node->Pos, ImGuiCond_Always); // We don't assign directly to Pos because it can break the calculation of SizeContents on next frame - SetWindowSize(node->Windows[n], node->Size, ImGuiCond_Always); - } -} - -static void ImGui::DockNodeHideHostWindow(ImGuiDockNode* node) -{ - if (node->HostWindow) - { - if (node->HostWindow->DockNodeAsHost == node) - node->HostWindow->DockNodeAsHost = NULL; - node->HostWindow = NULL; - } - - if (node->Windows.Size == 1) - { - node->VisibleWindow = node->Windows[0]; - node->Windows[0]->DockIsActive = false; - } - - if (node->TabBar) - DockNodeRemoveTabBar(node); -} - -// Search function called once by root node in DockNodeUpdate() -struct ImGuiDockNodeFindInfoResults -{ - ImGuiDockNode* CentralNode; - ImGuiDockNode* FirstNodeWithWindows; - int CountNodesWithWindows; - //ImGuiWindowClass WindowClassForMerges; - - ImGuiDockNodeFindInfoResults() { CentralNode = FirstNodeWithWindows = NULL; CountNodesWithWindows = 0; } -}; - -static void DockNodeFindInfo(ImGuiDockNode* node, ImGuiDockNodeFindInfoResults* results) -{ - if (node->Windows.Size > 0) - { - if (results->FirstNodeWithWindows == NULL) - results->FirstNodeWithWindows = node; - results->CountNodesWithWindows++; - } - if (node->IsCentralNode()) - { - IM_ASSERT(results->CentralNode == NULL); // Should be only one - IM_ASSERT(node->IsLeafNode() && "If you get this assert: please submit .ini file + repro of actions leading to this."); - results->CentralNode = node; - } - if (results->CountNodesWithWindows > 1 && results->CentralNode != NULL) - return; - if (node->ChildNodes[0]) - DockNodeFindInfo(node->ChildNodes[0], results); - if (node->ChildNodes[1]) - DockNodeFindInfo(node->ChildNodes[1], results); -} - -static ImGuiWindow* ImGui::DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id) -{ - IM_ASSERT(id != 0); - for (int n = 0; n < node->Windows.Size; n++) - if (node->Windows[n]->ID == id) - return node->Windows[n]; - return NULL; -} - -// - Remove inactive windows/nodes. -// - Update visibility flag. -static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(node->ParentNode == NULL || node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node); - - // Inherit most flags - if (node->ParentNode) - node->SharedFlags = node->ParentNode->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_; - - // Recurse into children - // There is the possibility that one of our child becoming empty will delete itself and moving its sibling contents into 'node'. - // If 'node->ChildNode[0]' delete itself, then 'node->ChildNode[1]->Windows' will be moved into 'node' - // If 'node->ChildNode[1]' delete itself, then 'node->ChildNode[0]->Windows' will be moved into 'node' and the "remove inactive windows" loop will have run twice on those windows (harmless) - if (node->ChildNodes[0]) - DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[0]); - if (node->ChildNodes[1]) - DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[1]); - - // Remove inactive windows - // Merge node flags overrides stored in windows - node->LocalFlagsInWindows = ImGuiDockNodeFlags_None; - for (int window_n = 0; window_n < node->Windows.Size; window_n++) - { - ImGuiWindow* window = node->Windows[window_n]; - IM_ASSERT(window->DockNode == node); - - bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount); - bool remove = false; - remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount); - remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame - remove |= (window->DockTabWantClose); - if (remove) - { - window->DockTabWantClose = false; - if (node->Windows.Size == 1 && !node->IsCentralNode()) - { - DockNodeHideHostWindow(node); - node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow; - DockNodeRemoveWindow(node, window, node->ID); // Will delete the node so it'll be invalid on return - return; - } - DockNodeRemoveWindow(node, window, node->ID); - window_n--; - } - else - { - // FIXME-DOCKING: Missing policies for conflict resolution, hence the "Experimental" tag on this. - //node->LocalFlagsInWindow &= ~window->WindowClass.DockNodeFlagsOverrideClear; - node->LocalFlagsInWindows |= window->WindowClass.DockNodeFlagsOverrideSet; - } - } - node->UpdateMergedFlags(); - - // Auto-hide tab bar option - ImGuiDockNodeFlags node_flags = node->MergedFlags; - if (node->WantHiddenTabBarUpdate && node->Windows.Size == 1 && (node_flags & ImGuiDockNodeFlags_AutoHideTabBar) && !node->IsHiddenTabBar()) - node->WantHiddenTabBarToggle = true; - node->WantHiddenTabBarUpdate = false; - - // Cancel toggling if we know our tab bar is enforced to be hidden at all times - if (node->WantHiddenTabBarToggle && node->VisibleWindow && (node->VisibleWindow->WindowClass.DockNodeFlagsOverrideSet & ImGuiDockNodeFlags_HiddenTabBar)) - node->WantHiddenTabBarToggle = false; - - // Apply toggles at a single point of the frame (here!) - if (node->Windows.Size > 1) - node->SetLocalFlags(node->LocalFlags & ~ImGuiDockNodeFlags_HiddenTabBar); - else if (node->WantHiddenTabBarToggle) - node->SetLocalFlags(node->LocalFlags ^ ImGuiDockNodeFlags_HiddenTabBar); - node->WantHiddenTabBarToggle = false; - - DockNodeUpdateVisibleFlag(node); -} - -static void ImGui::DockNodeUpdateVisibleFlag(ImGuiDockNode* node) -{ - // Update visibility flag - bool is_visible = (node->ParentNode == NULL) ? node->IsDockSpace() : node->IsCentralNode(); - is_visible |= (node->Windows.Size > 0); - is_visible |= (node->ChildNodes[0] && node->ChildNodes[0]->IsVisible); - is_visible |= (node->ChildNodes[1] && node->ChildNodes[1]->IsVisible); - node->IsVisible = is_visible; -} - -static void ImGui::DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(node->WantMouseMove == true); - StartMouseMovingWindow(window); - g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - node->Pos; - g.MovingWindow = window; // If we are docked into a non moveable root window, StartMouseMovingWindow() won't set g.MovingWindow. Override that decision. - node->WantMouseMove = false; -} - -// Update CentralNode, OnlyNodeWithWindows, LastFocusedNodeID. Copy window class. -static void ImGui::DockNodeUpdateForRootNode(ImGuiDockNode* node) -{ - DockNodeUpdateVisibleFlagAndInactiveChilds(node); - - // FIXME-DOCK: Merge this scan into the one above. - // - Setup central node pointers - // - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!) - ImGuiDockNodeFindInfoResults results; - DockNodeFindInfo(node, &results); - node->CentralNode = results.CentralNode; - node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL; - if (node->LastFocusedNodeId == 0 && results.FirstNodeWithWindows != NULL) - node->LastFocusedNodeId = results.FirstNodeWithWindows->ID; - - // Copy the window class from of our first window so it can be used for proper dock filtering. - // When node has mixed windows, prioritize the class with the most constraint (DockingAllowUnclassed = false) as the reference to copy. - // FIXME-DOCK: We don't recurse properly, this code could be reworked to work from DockNodeUpdateScanRec. - if (ImGuiDockNode* first_node_with_windows = results.FirstNodeWithWindows) - { - node->WindowClass = first_node_with_windows->Windows[0]->WindowClass; - for (int n = 1; n < first_node_with_windows->Windows.Size; n++) - if (first_node_with_windows->Windows[n]->WindowClass.DockingAllowUnclassed == false) - { - node->WindowClass = first_node_with_windows->Windows[n]->WindowClass; - break; - } - } -} - -static void DockNodeSetupHostWindow(ImGuiDockNode* node, ImGuiWindow* host_window) -{ - // Remove ourselves from any previous different host window - // This can happen if a user mistakenly does (see #4295 for details): - // - N+0: DockBuilderAddNode(id, 0) // missing ImGuiDockNodeFlags_DockSpace - // - N+1: NewFrame() // will create floating host window for that node - // - N+1: DockSpace(id) // requalify node as dockspace, moving host window - if (node->HostWindow && node->HostWindow != host_window && node->HostWindow->DockNodeAsHost == node) - node->HostWindow->DockNodeAsHost = NULL; - - host_window->DockNodeAsHost = node; - node->HostWindow = host_window; -} - -static void ImGui::DockNodeUpdate(ImGuiDockNode* node) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(node->LastFrameActive != g.FrameCount); - node->LastFrameAlive = g.FrameCount; - node->MarkedForPosSizeWrite = false; - - node->CentralNode = node->OnlyNodeWithWindows = NULL; - if (node->IsRootNode()) - DockNodeUpdateForRootNode(node); - - // Remove tab bar if not needed - if (node->TabBar && node->IsNoTabBar()) - DockNodeRemoveTabBar(node); - - // Early out for hidden root dock nodes (when all DockId references are in inactive windows, or there is only 1 floating window holding on the DockId) - bool want_to_hide_host_window = false; - if (node->Windows.Size <= 1 && node->IsFloatingNode() && node->IsLeafNode()) - if (!g.IO.ConfigDockingAlwaysTabBar && (node->Windows.Size == 0 || !node->Windows[0]->WindowClass.DockingAlwaysTabBar)) - want_to_hide_host_window = true; - if (want_to_hide_host_window) - { - if (node->Windows.Size == 1) - { - // Floating window pos/size is authoritative - ImGuiWindow* single_window = node->Windows[0]; - node->Pos = single_window->Pos; - node->Size = single_window->SizeFull; - node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window; - - // Transfer focus immediately so when we revert to a regular window it is immediately selected - if (node->HostWindow && g.NavWindow == node->HostWindow) - FocusWindow(single_window); - if (node->HostWindow) - { - single_window->Viewport = node->HostWindow->Viewport; - single_window->ViewportId = node->HostWindow->ViewportId; - if (node->HostWindow->ViewportOwned) - { - single_window->Viewport->Window = single_window; - single_window->ViewportOwned = true; - } - } - } - - DockNodeHideHostWindow(node); - node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow; - node->WantCloseAll = false; - node->WantCloseTabId = 0; - node->HasCloseButton = node->HasWindowMenuButton = false; - node->LastFrameActive = g.FrameCount; - - if (node->WantMouseMove && node->Windows.Size == 1) - DockNodeStartMouseMovingWindow(node, node->Windows[0]); - return; - } - - // In some circumstance we will defer creating the host window (so everything will be kept hidden), - // while the expected visible window is resizing itself. - // This is important for first-time (no ini settings restored) single window when io.ConfigDockingAlwaysTabBar is enabled, - // otherwise the node ends up using the minimum window size. Effectively those windows will take an extra frame to show up: - // N+0: Begin(): window created (with no known size), node is created - // N+1: DockNodeUpdate(): node skip creating host window / Begin(): window size applied, not visible - // N+2: DockNodeUpdate(): node can create host window / Begin(): window becomes visible - // We could remove this frame if we could reliably calculate the expected window size during node update, before the Begin() code. - // It would require a generalization of CalcWindowExpectedSize(), probably extracting code away from Begin(). - // In reality it isn't very important as user quickly ends up with size data in .ini file. - if (node->IsVisible && node->HostWindow == NULL && node->IsFloatingNode() && node->IsLeafNode()) - { - IM_ASSERT(node->Windows.Size > 0); - ImGuiWindow* ref_window = NULL; - if (node->SelectedTabId != 0) // Note that we prune single-window-node settings on .ini loading, so this is generally 0 for them! - ref_window = DockNodeFindWindowByID(node, node->SelectedTabId); - if (ref_window == NULL) - ref_window = node->Windows[0]; - if (ref_window->AutoFitFramesX > 0 || ref_window->AutoFitFramesY > 0) - { - node->State = ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing; - return; - } - } - - const ImGuiDockNodeFlags node_flags = node->MergedFlags; - - // Decide if the node will have a close button and a window menu button - node->HasWindowMenuButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0; - node->HasCloseButton = false; - for (int window_n = 0; window_n < node->Windows.Size; window_n++) - { - // FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call. - ImGuiWindow* window = node->Windows[window_n]; - node->HasCloseButton |= window->HasCloseButton; - window->DockIsActive = (node->Windows.Size > 1); - } - if (node_flags & ImGuiDockNodeFlags_NoCloseButton) - node->HasCloseButton = false; - - // Bind or create host window - ImGuiWindow* host_window = NULL; - bool beginned_into_host_window = false; - if (node->IsDockSpace()) - { - // [Explicit root dockspace node] - IM_ASSERT(node->HostWindow); - host_window = node->HostWindow; - } - else - { - // [Automatic root or child nodes] - if (node->IsRootNode() && node->IsVisible) - { - ImGuiWindow* ref_window = (node->Windows.Size > 0) ? node->Windows[0] : NULL; - - // Sync Pos - if (node->AuthorityForPos == ImGuiDataAuthority_Window && ref_window) - SetNextWindowPos(ref_window->Pos); - else if (node->AuthorityForPos == ImGuiDataAuthority_DockNode) - SetNextWindowPos(node->Pos); - - // Sync Size - if (node->AuthorityForSize == ImGuiDataAuthority_Window && ref_window) - SetNextWindowSize(ref_window->SizeFull); - else if (node->AuthorityForSize == ImGuiDataAuthority_DockNode) - SetNextWindowSize(node->Size); - - // Sync Collapsed - if (node->AuthorityForSize == ImGuiDataAuthority_Window && ref_window) - SetNextWindowCollapsed(ref_window->Collapsed); - - // Sync Viewport - if (node->AuthorityForViewport == ImGuiDataAuthority_Window && ref_window) - SetNextWindowViewport(ref_window->ViewportId); - - SetNextWindowClass(&node->WindowClass); - - // Begin into the host window - char window_label[20]; - DockNodeGetHostWindowTitle(node, window_label, IM_ARRAYSIZE(window_label)); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_DockNodeHost; - window_flags |= ImGuiWindowFlags_NoFocusOnAppearing; - window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoCollapse; - window_flags |= ImGuiWindowFlags_NoTitleBar; - - PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); - Begin(window_label, NULL, window_flags); - PopStyleVar(); - beginned_into_host_window = true; - - host_window = g.CurrentWindow; - DockNodeSetupHostWindow(node, host_window); - host_window->DC.CursorPos = host_window->Pos; - node->Pos = host_window->Pos; - node->Size = host_window->Size; - - // We set ImGuiWindowFlags_NoFocusOnAppearing because we don't want the host window to take full focus (e.g. steal NavWindow) - // But we still it bring it to the front of display. There's no way to choose this precise behavior via window flags. - // One simple case to ponder if: window A has a toggle to create windows B/C/D. Dock B/C/D together, clear the toggle and enable it again. - // When reappearing B/C/D will request focus and be moved to the top of the display pile, but they are not linked to the dock host window - // during the frame they appear. The dock host window would keep its old display order, and the sorting in EndFrame would move B/C/D back - // after the dock host window, losing their top-most status. - if (node->HostWindow->Appearing) - BringWindowToDisplayFront(node->HostWindow); - - node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Auto; - } - else if (node->ParentNode) - { - node->HostWindow = host_window = node->ParentNode->HostWindow; - node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Auto; - } - if (node->WantMouseMove && node->HostWindow) - DockNodeStartMouseMovingWindow(node, node->HostWindow); - } - - // Update focused node (the one whose title bar is highlight) within a node tree - if (node->IsSplitNode()) - IM_ASSERT(node->TabBar == NULL); - if (node->IsRootNode()) - if (g.NavWindow && g.NavWindow->RootWindow->DockNode && g.NavWindow->RootWindow->ParentWindow == host_window) - node->LastFocusedNodeId = g.NavWindow->RootWindow->DockNode->ID; - - // We need to draw a background at the root level if requested by ImGuiDockNodeFlags_PassthruCentralNode, but we will only know the correct pos/size - // _after_ processing the resizing splitters. So we are using the DrawList channel splitting facility to submit drawing primitives out of order! - const bool render_dockspace_bg = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0; - if (render_dockspace_bg) - { - host_window->DrawList->ChannelsSplit(2); - host_window->DrawList->ChannelsSetCurrent(1); - } - - // Register a hit-test hole in the window unless we are currently dragging a window that is compatible with our dockspace - ImGuiDockNode* central_node = node->CentralNode; - const bool central_node_hole = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0 && central_node != NULL && central_node->IsEmpty(); - bool central_node_hole_register_hit_test_hole = central_node_hole; - if (central_node_hole) - if (const ImGuiPayload* payload = ImGui::GetDragDropPayload()) - if (payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && DockNodeIsDropAllowed(host_window, *(ImGuiWindow**)payload->Data)) - central_node_hole_register_hit_test_hole = false; - if (central_node_hole_register_hit_test_hole) - { - // We add a little padding to match the "resize from edges" behavior and allow grabbing the splitter easily. - // (But we only add it if there's something else on the other side of the hole, otherwise for e.g. fullscreen - // covering passthru node we'd have a gap on the edge not covered by the hole) - IM_ASSERT(node->IsDockSpace()); // We cannot pass this flag without the DockSpace() api. Testing this because we also setup the hole in host_window->ParentNode - ImGuiDockNode* root_node = DockNodeGetRootNode(central_node); - ImRect root_rect(root_node->Pos, root_node->Pos + root_node->Size); - ImRect hole_rect(central_node->Pos, central_node->Pos + central_node->Size); - if (hole_rect.Min.x > root_rect.Min.x) { hole_rect.Min.x += WINDOWS_HOVER_PADDING; } - if (hole_rect.Max.x < root_rect.Max.x) { hole_rect.Max.x -= WINDOWS_HOVER_PADDING; } - if (hole_rect.Min.y > root_rect.Min.y) { hole_rect.Min.y += WINDOWS_HOVER_PADDING; } - if (hole_rect.Max.y < root_rect.Max.y) { hole_rect.Max.y -= WINDOWS_HOVER_PADDING; } - //GetForegroundDrawList()->AddRect(hole_rect.Min, hole_rect.Max, IM_COL32(255, 0, 0, 255)); - if (central_node_hole && !hole_rect.IsInverted()) - { - SetWindowHitTestHole(host_window, hole_rect.Min, hole_rect.Max - hole_rect.Min); - SetWindowHitTestHole(host_window->ParentWindow, hole_rect.Min, hole_rect.Max - hole_rect.Min); - } - } - - // Update position/size, process and draw resizing splitters - if (node->IsRootNode() && host_window) - { - DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size); - DockNodeTreeUpdateSplitter(node); - } - - // Draw empty node background (currently can only be the Central Node) - if (host_window && node->IsEmpty() && node->IsVisible && !(node_flags & ImGuiDockNodeFlags_PassthruCentralNode)) - host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_DockingEmptyBg)); - - // Draw whole dockspace background if ImGuiDockNodeFlags_PassthruCentralNode if set. - if (render_dockspace_bg && node->IsVisible) - { - host_window->DrawList->ChannelsSetCurrent(0); - if (central_node_hole) - RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f); - else - host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_WindowBg), 0.0f); - host_window->DrawList->ChannelsMerge(); - } - - // Draw and populate Tab Bar - if (host_window && node->Windows.Size > 0) - { - DockNodeUpdateTabBar(node, host_window); - } - else - { - node->WantCloseAll = false; - node->WantCloseTabId = 0; - node->IsFocused = false; - } - if (node->TabBar && node->TabBar->SelectedTabId) - node->SelectedTabId = node->TabBar->SelectedTabId; - else if (node->Windows.Size > 0) - node->SelectedTabId = node->Windows[0]->ID; - - // Draw payload drop target - if (host_window && node->IsVisible) - if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindowDockTree != host_window)) - BeginDockableDragDropTarget(host_window); - - // We update this after DockNodeUpdateTabBar() - node->LastFrameActive = g.FrameCount; - - // Recurse into children - // FIXME-DOCK FIXME-OPT: Should not need to recurse into children - if (host_window) - { - if (node->ChildNodes[0]) - DockNodeUpdate(node->ChildNodes[0]); - if (node->ChildNodes[1]) - DockNodeUpdate(node->ChildNodes[1]); - - // Render outer borders last (after the tab bar) - if (node->IsRootNode()) - RenderWindowOuterBorders(host_window); - } - - // End host window - if (beginned_into_host_window) //-V1020 - End(); -} - -// Compare TabItem nodes given the last known DockOrder (will persist in .ini file as hint), used to sort tabs when multiple tabs are added on the same frame. -static int IMGUI_CDECL TabItemComparerByDockOrder(const void* lhs, const void* rhs) -{ - ImGuiWindow* a = ((const ImGuiTabItem*)lhs)->Window; - ImGuiWindow* b = ((const ImGuiTabItem*)rhs)->Window; - if (int d = ((a->DockOrder == -1) ? INT_MAX : a->DockOrder) - ((b->DockOrder == -1) ? INT_MAX : b->DockOrder)) - return d; - return (a->BeginOrderWithinContext - b->BeginOrderWithinContext); -} - -static ImGuiID ImGui::DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar) -{ - // Try to position the menu so it is more likely to stays within the same viewport - ImGuiContext& g = *GImGui; - ImGuiID ret_tab_id = 0; - if (g.Style.WindowMenuButtonPosition == ImGuiDir_Left) - SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight()), ImGuiCond_Always, ImVec2(0.0f, 0.0f)); - else - SetNextWindowPos(ImVec2(node->Pos.x + node->Size.x, node->Pos.y + GetFrameHeight()), ImGuiCond_Always, ImVec2(1.0f, 0.0f)); - if (BeginPopup("#WindowMenu")) - { - node->IsFocused = true; - if (tab_bar->Tabs.Size == 1) - { - if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar())) - node->WantHiddenTabBarToggle = true; - } - else - { - for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) - { - ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; - if (tab->Flags & ImGuiTabItemFlags_Button) - continue; - if (Selectable(tab_bar->GetTabName(tab), tab->ID == tab_bar->SelectedTabId)) - ret_tab_id = tab->ID; - SameLine(); - Text(" "); - } - } - EndPopup(); - } - return ret_tab_id; -} - -// User helper to append/amend into a dock node tab bar. Most commonly used to add e.g. a "+" button. -bool ImGui::DockNodeBeginAmendTabBar(ImGuiDockNode* node) -{ - if (node->TabBar == NULL || node->HostWindow == NULL) - return false; - if (node->MergedFlags & ImGuiDockNodeFlags_KeepAliveOnly) - return false; - Begin(node->HostWindow->Name); - PushOverrideID(node->ID); - bool ret = BeginTabBarEx(node->TabBar, node->TabBar->BarRect, node->TabBar->Flags, node); - IM_UNUSED(ret); - IM_ASSERT(ret); - return true; -} - -void ImGui::DockNodeEndAmendTabBar() -{ - EndTabBar(); - PopID(); - End(); -} - -// Submit the tab bar corresponding to a dock node and various housekeeping details. -static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window) -{ - ImGuiContext& g = *GImGui; - ImGuiStyle& style = g.Style; - - const bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount); - const bool closed_all = node->WantCloseAll && node_was_active; - const ImGuiID closed_one = node->WantCloseTabId && node_was_active; - node->WantCloseAll = false; - node->WantCloseTabId = 0; - - // Decide if we should use a focused title bar color - bool is_focused = false; - ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (g.NavWindowingTarget) - is_focused = (g.NavWindowingTarget->DockNode == node); - else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID) - is_focused = true; - - // Hidden tab bar will show a triangle on the upper-left (in Begin) - if (node->IsHiddenTabBar() || node->IsNoTabBar()) - { - node->VisibleWindow = (node->Windows.Size > 0) ? node->Windows[0] : NULL; - node->IsFocused = is_focused; - if (is_focused) - node->LastFrameFocused = g.FrameCount; - if (node->VisibleWindow) - { - // Notify root of visible window (used to display title in OS task bar) - if (is_focused || root_node->VisibleWindow == NULL) - root_node->VisibleWindow = node->VisibleWindow; - if (node->TabBar) - node->TabBar->VisibleTabId = node->VisibleWindow->ID; - } - return; - } - - // Move ourselves to the Menu layer (so we can be accessed by tapping Alt) + undo SkipItems flag in order to draw over the title bar even if the window is collapsed - bool backup_skip_item = host_window->SkipItems; - if (!node->IsDockSpace()) - { - host_window->SkipItems = false; - host_window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; - } - - // Use PushOverrideID() instead of PushID() to use the node id _without_ the host window ID. - // This is to facilitate computing those ID from the outside, and will affect more or less only the ID of the collapse button, popup and tabs, - // as docked windows themselves will override the stack with their own root ID. - PushOverrideID(node->ID); - ImGuiTabBar* tab_bar = node->TabBar; - bool tab_bar_is_recreated = (tab_bar == NULL); // Tab bar are automatically destroyed when a node gets hidden - if (tab_bar == NULL) - { - DockNodeAddTabBar(node); - tab_bar = node->TabBar; - } - - ImGuiID focus_tab_id = 0; - node->IsFocused = is_focused; - - const ImGuiDockNodeFlags node_flags = node->MergedFlags; - const bool has_window_menu_button = (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0 && (style.WindowMenuButtonPosition != ImGuiDir_None); - - // In a dock node, the Collapse Button turns into the Window Menu button. - // FIXME-DOCK FIXME-OPT: Could we recycle popups id across multiple dock nodes? - if (has_window_menu_button && IsPopupOpen("#WindowMenu")) - { - if (ImGuiID tab_id = DockNodeUpdateWindowMenu(node, tab_bar)) - focus_tab_id = tab_bar->NextSelectedTabId = tab_id; - is_focused |= node->IsFocused; - } - - // Layout - ImRect title_bar_rect, tab_bar_rect; - ImVec2 window_menu_button_pos; - ImVec2 close_button_pos; - DockNodeCalcTabBarLayout(node, &title_bar_rect, &tab_bar_rect, &window_menu_button_pos, &close_button_pos); - - // Submit new tabs, they will be added as Unsorted and sorted below based on relative DockOrder value. - const int tabs_count_old = tab_bar->Tabs.Size; - for (int window_n = 0; window_n < node->Windows.Size; window_n++) - { - ImGuiWindow* window = node->Windows[window_n]; - if (TabBarFindTabByID(tab_bar, window->ID) == NULL) - TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window); - } - - // Title bar - if (is_focused) - node->LastFrameFocused = g.FrameCount; - ImU32 title_bar_col = GetColorU32(host_window->Collapsed ? ImGuiCol_TitleBgCollapsed : is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg); - host_window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, host_window->WindowRounding, ImDrawFlags_RoundCornersTop); - - // Docking/Collapse button - if (has_window_menu_button) - { - if (CollapseButton(host_window->GetID("#COLLAPSE"), window_menu_button_pos, node)) // == DockNodeGetWindowMenuButtonId(node) - OpenPopup("#WindowMenu"); - if (IsItemActive()) - focus_tab_id = tab_bar->SelectedTabId; - } - - // If multiple tabs are appearing on the same frame, sort them based on their persistent DockOrder value - int tabs_unsorted_start = tab_bar->Tabs.Size; - for (int tab_n = tab_bar->Tabs.Size - 1; tab_n >= 0 && (tab_bar->Tabs[tab_n].Flags & ImGuiTabItemFlags_Unsorted); tab_n--) - { - // FIXME-DOCK: Consider only clearing the flag after the tab has been alive for a few consecutive frames, allowing late comers to not break sorting? - tab_bar->Tabs[tab_n].Flags &= ~ImGuiTabItemFlags_Unsorted; - tabs_unsorted_start = tab_n; - } - if (tab_bar->Tabs.Size > tabs_unsorted_start) - { - IMGUI_DEBUG_LOG_DOCKING("In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : ""); - for (int tab_n = tabs_unsorted_start; tab_n < tab_bar->Tabs.Size; tab_n++) - IMGUI_DEBUG_LOG_DOCKING(" - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder); - if (tab_bar->Tabs.Size > tabs_unsorted_start + 1) - ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder); - } - - // Apply NavWindow focus back to the tab bar - if (g.NavWindow && g.NavWindow->RootWindow->DockNode == node) - tab_bar->SelectedTabId = g.NavWindow->RootWindow->ID; - - // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated - if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL) - tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId; - else if (tab_bar->Tabs.Size > tabs_count_old) - tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID; - - // Begin tab bar - ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs; // | ImGuiTabBarFlags_NoTabListScrollingButtons); - tab_bar_flags |= ImGuiTabBarFlags_SaveSettings | ImGuiTabBarFlags_DockNode; - if (!host_window->Collapsed && is_focused) - tab_bar_flags |= ImGuiTabBarFlags_IsFocused; - BeginTabBarEx(tab_bar, tab_bar_rect, tab_bar_flags, node); - //host_window->DrawList->AddRect(tab_bar_rect.Min, tab_bar_rect.Max, IM_COL32(255,0,255,255)); - - // Backup style colors - ImVec4 backup_style_cols[ImGuiWindowDockStyleCol_COUNT]; - for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) - backup_style_cols[color_n] = g.Style.Colors[GWindowDockStyleColors[color_n]]; - - // Submit actual tabs - node->VisibleWindow = NULL; - for (int window_n = 0; window_n < node->Windows.Size; window_n++) - { - ImGuiWindow* window = node->Windows[window_n]; - if ((closed_all || closed_one == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument)) - continue; - if (window->LastFrameActive + 1 >= g.FrameCount || !node_was_active) - { - ImGuiTabItemFlags tab_item_flags = 0; - tab_item_flags |= window->WindowClass.TabItemFlagsOverrideSet; - if (window->Flags & ImGuiWindowFlags_UnsavedDocument) - tab_item_flags |= ImGuiTabItemFlags_UnsavedDocument; - if (tab_bar->Flags & ImGuiTabBarFlags_NoCloseWithMiddleMouseButton) - tab_item_flags |= ImGuiTabItemFlags_NoCloseWithMiddleMouseButton; - - // Apply stored style overrides for the window - for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) - g.Style.Colors[GWindowDockStyleColors[color_n]] = ColorConvertU32ToFloat4(window->DockStyle.Colors[color_n]); - - bool tab_open = true; - TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window); - if (!tab_open) - node->WantCloseTabId = window->ID; - if (tab_bar->VisibleTabId == window->ID) - node->VisibleWindow = window; - - // Store last item data so it can be queried with IsItemXXX functions after the user Begin() call - window->DockTabItemStatusFlags = g.LastItemData.StatusFlags; - window->DockTabItemRect = g.LastItemData.Rect; - - // Update navigation ID on menu layer - if (g.NavWindow && g.NavWindow->RootWindow == window && (window->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) == 0) - host_window->NavLastIds[1] = window->ID; - } - } - - // Restore style colors - for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) - g.Style.Colors[GWindowDockStyleColors[color_n]] = backup_style_cols[color_n]; - - // Notify root of visible window (used to display title in OS task bar) - if (node->VisibleWindow) - if (is_focused || root_node->VisibleWindow == NULL) - root_node->VisibleWindow = node->VisibleWindow; - - // Close button (after VisibleWindow was updated) - // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->ID may be != from tab_bar->SelectedTabId - const bool close_button_is_enabled = node->HasCloseButton && node->VisibleWindow && node->VisibleWindow->HasCloseButton; - const bool close_button_is_visible = node->HasCloseButton; - //const bool close_button_is_visible = close_button_is_enabled; // Most people would expect this behavior of not even showing the button (leaving a hole since we can't claim that space as other windows in the tba bar have one) - if (close_button_is_visible) - { - if (!close_button_is_enabled) - { - PushItemFlag(ImGuiItemFlags_Disabled, true); - PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_Text] * ImVec4(1.0f,1.0f,1.0f,0.4f)); - } - if (CloseButton(host_window->GetID("#CLOSE"), close_button_pos)) - { - node->WantCloseAll = true; - for (int n = 0; n < tab_bar->Tabs.Size; n++) - TabBarCloseTab(tab_bar, &tab_bar->Tabs[n]); - } - //if (IsItemActive()) - // focus_tab_id = tab_bar->SelectedTabId; - if (!close_button_is_enabled) - { - PopStyleColor(); - PopItemFlag(); - } - } - - // When clicking on the title bar outside of tabs, we still focus the selected tab for that node - // FIXME: TabItem use AllowItemOverlap so we manually perform a more specific test for now (hovered || held) - ImGuiID title_bar_id = host_window->GetID("#TITLEBAR"); - if (g.HoveredId == 0 || g.HoveredId == title_bar_id || g.ActiveId == title_bar_id) - { - bool held; - ButtonBehavior(title_bar_rect, title_bar_id, NULL, &held, ImGuiButtonFlags_AllowItemOverlap); - if (g.HoveredId == title_bar_id) - { - // ImGuiButtonFlags_AllowItemOverlap + SetItemAllowOverlap() required for appending into dock node tab bar, - // otherwise dragging window will steal HoveredId and amended tabs cannot get them. - g.LastItemData.ID = title_bar_id; - SetItemAllowOverlap(); - } - if (held) - { - if (IsMouseClicked(0)) - focus_tab_id = tab_bar->SelectedTabId; - - // Forward moving request to selected window - if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId)) - StartMouseMovingWindowOrNode(tab->Window ? tab->Window : node->HostWindow, node, false); - } - } - - // Forward focus from host node to selected window - //if (is_focused && g.NavWindow == host_window && !g.NavWindowingTarget) - // focus_tab_id = tab_bar->SelectedTabId; - - // When clicked on a tab we requested focus to the docked child - // This overrides the value set by "forward focus from host node to selected window". - if (tab_bar->NextSelectedTabId) - focus_tab_id = tab_bar->NextSelectedTabId; - - // Apply navigation focus - if (focus_tab_id != 0) - if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id)) - if (tab->Window) - { - FocusWindow(tab->Window); - NavInitWindow(tab->Window, false); - } - - EndTabBar(); - PopID(); - - // Restore SkipItems flag - if (!node->IsDockSpace()) - { - host_window->DC.NavLayerCurrent = ImGuiNavLayer_Main; - host_window->SkipItems = backup_skip_item; - } -} - -static void ImGui::DockNodeAddTabBar(ImGuiDockNode* node) -{ - IM_ASSERT(node->TabBar == NULL); - node->TabBar = IM_NEW(ImGuiTabBar); -} - -static void ImGui::DockNodeRemoveTabBar(ImGuiDockNode* node) -{ - if (node->TabBar == NULL) - return; - IM_DELETE(node->TabBar); - node->TabBar = NULL; -} - -static bool DockNodeIsDropAllowedOne(ImGuiWindow* payload, ImGuiWindow* host_window) -{ - if (host_window->DockNodeAsHost && host_window->DockNodeAsHost->IsDockSpace() && payload->BeginOrderWithinContext < host_window->BeginOrderWithinContext) - return false; - - ImGuiWindowClass* host_class = host_window->DockNodeAsHost ? &host_window->DockNodeAsHost->WindowClass : &host_window->WindowClass; - ImGuiWindowClass* payload_class = &payload->WindowClass; - if (host_class->ClassId != payload_class->ClassId) - { - if (host_class->ClassId != 0 && host_class->DockingAllowUnclassed && payload_class->ClassId == 0) - return true; - if (payload_class->ClassId != 0 && payload_class->DockingAllowUnclassed && host_class->ClassId == 0) - return true; - return false; - } - - return true; -} - -static bool ImGui::DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* root_payload) -{ - if (root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode()) - return true; - - const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows.Size : 1; - for (int payload_n = 0; payload_n < payload_count; payload_n++) - { - ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows[payload_n] : root_payload; - if (DockNodeIsDropAllowedOne(payload, host_window)) - return true; - } - return false; -} - -// window menu button == collapse button when not in a dock node. -// FIXME: This is similar to RenderWindowTitleBarContents(), may want to share code. -static void ImGui::DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos, ImVec2* out_close_button_pos) -{ - ImGuiContext& g = *GImGui; - ImGuiStyle& style = g.Style; - - ImRect r = ImRect(node->Pos.x, node->Pos.y, node->Pos.x + node->Size.x, node->Pos.y + g.FontSize + g.Style.FramePadding.y * 2.0f); - if (out_title_rect) { *out_title_rect = r; } - - r.Min.x += style.WindowBorderSize; - r.Max.x -= style.WindowBorderSize; - - float button_sz = g.FontSize; - - ImVec2 window_menu_button_pos = r.Min; - r.Min.x += style.FramePadding.x; - r.Max.x -= style.FramePadding.x; - if (node->HasCloseButton) - { - r.Max.x -= button_sz; - if (out_close_button_pos) *out_close_button_pos = ImVec2(r.Max.x - style.FramePadding.x, r.Min.y); - } - if (node->HasWindowMenuButton && style.WindowMenuButtonPosition == ImGuiDir_Left) - { - r.Min.x += button_sz + style.ItemInnerSpacing.x; - } - else if (node->HasWindowMenuButton && style.WindowMenuButtonPosition == ImGuiDir_Right) - { - r.Max.x -= button_sz + style.FramePadding.x; - window_menu_button_pos = ImVec2(r.Max.x, r.Min.y); - } - if (out_tab_bar_rect) { *out_tab_bar_rect = r; } - if (out_window_menu_button_pos) { *out_window_menu_button_pos = window_menu_button_pos; } -} - -void ImGui::DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired) -{ - ImGuiContext& g = *GImGui; - const float dock_spacing = g.Style.ItemInnerSpacing.x; - const ImGuiAxis axis = (dir == ImGuiDir_Left || dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y; - pos_new[axis ^ 1] = pos_old[axis ^ 1]; - size_new[axis ^ 1] = size_old[axis ^ 1]; - - // Distribute size on given axis (with a desired size or equally) - const float w_avail = size_old[axis] - dock_spacing; - if (size_new_desired[axis] > 0.0f && size_new_desired[axis] <= w_avail * 0.5f) - { - size_new[axis] = size_new_desired[axis]; - size_old[axis] = IM_FLOOR(w_avail - size_new[axis]); - } - else - { - size_new[axis] = IM_FLOOR(w_avail * 0.5f); - size_old[axis] = IM_FLOOR(w_avail - size_new[axis]); - } - - // Position each node - if (dir == ImGuiDir_Right || dir == ImGuiDir_Down) - { - pos_new[axis] = pos_old[axis] + size_old[axis] + dock_spacing; - } - else if (dir == ImGuiDir_Left || dir == ImGuiDir_Up) - { - pos_new[axis] = pos_old[axis]; - pos_old[axis] = pos_new[axis] + size_new[axis] + dock_spacing; - } -} - -// Retrieve the drop rectangles for a given direction or for the center + perform hit testing. -bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir dir, ImRect& out_r, bool outer_docking, ImVec2* test_mouse_pos) -{ - ImGuiContext& g = *GImGui; - - const float parent_smaller_axis = ImMin(parent.GetWidth(), parent.GetHeight()); - const float hs_for_central_nodes = ImMin(g.FontSize * 1.5f, ImMax(g.FontSize * 0.5f, parent_smaller_axis / 8.0f)); - float hs_w; // Half-size, longer axis - float hs_h; // Half-size, smaller axis - ImVec2 off; // Distance from edge or center - if (outer_docking) - { - //hs_w = ImFloor(ImClamp(parent_smaller_axis - hs_for_central_nodes * 4.0f, g.FontSize * 0.5f, g.FontSize * 8.0f)); - //hs_h = ImFloor(hs_w * 0.15f); - //off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h)); - hs_w = ImFloor(hs_for_central_nodes * 1.50f); - hs_h = ImFloor(hs_for_central_nodes * 0.80f); - off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - hs_h), ImFloor(parent.GetHeight() * 0.5f - hs_h)); - } - else - { - hs_w = ImFloor(hs_for_central_nodes); - hs_h = ImFloor(hs_for_central_nodes * 0.90f); - off = ImVec2(ImFloor(hs_w * 2.40f), ImFloor(hs_w * 2.40f)); - } - - ImVec2 c = ImFloor(parent.GetCenter()); - if (dir == ImGuiDir_None) { out_r = ImRect(c.x - hs_w, c.y - hs_w, c.x + hs_w, c.y + hs_w); } - else if (dir == ImGuiDir_Up) { out_r = ImRect(c.x - hs_w, c.y - off.y - hs_h, c.x + hs_w, c.y - off.y + hs_h); } - else if (dir == ImGuiDir_Down) { out_r = ImRect(c.x - hs_w, c.y + off.y - hs_h, c.x + hs_w, c.y + off.y + hs_h); } - else if (dir == ImGuiDir_Left) { out_r = ImRect(c.x - off.x - hs_h, c.y - hs_w, c.x - off.x + hs_h, c.y + hs_w); } - else if (dir == ImGuiDir_Right) { out_r = ImRect(c.x + off.x - hs_h, c.y - hs_w, c.x + off.x + hs_h, c.y + hs_w); } - - if (test_mouse_pos == NULL) - return false; - - ImRect hit_r = out_r; - if (!outer_docking) - { - // Custom hit testing for the 5-way selection, designed to reduce flickering when moving diagonally between sides - hit_r.Expand(ImFloor(hs_w * 0.30f)); - ImVec2 mouse_delta = (*test_mouse_pos - c); - float mouse_delta_len2 = ImLengthSqr(mouse_delta); - float r_threshold_center = hs_w * 1.4f; - float r_threshold_sides = hs_w * (1.4f + 1.2f); - if (mouse_delta_len2 < r_threshold_center * r_threshold_center) - return (dir == ImGuiDir_None); - if (mouse_delta_len2 < r_threshold_sides * r_threshold_sides) - return (dir == ImGetDirQuadrantFromDelta(mouse_delta.x, mouse_delta.y)); - } - return hit_r.Contains(*test_mouse_pos); -} - -// host_node may be NULL if the window doesn't have a DockNode already. -// FIXME-DOCK: This is misnamed since it's also doing the filtering. -static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking) -{ - ImGuiContext& g = *GImGui; - - // There is an edge case when docking into a dockspace which only has inactive nodes. - // In this case DockNodeTreeFindNodeByPos() will have selected a leaf node which is inactive. - // Because the inactive leaf node doesn't have proper pos/size yet, we'll use the root node as reference. - ImGuiDockNode* root_payload_as_host = root_payload->DockNodeAsHost; - ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node; - if (ref_node_for_rect) - IM_ASSERT(ref_node_for_rect->IsVisible); - - // Filter, figure out where we are allowed to dock - ImGuiDockNodeFlags src_node_flags = root_payload_as_host ? root_payload_as_host->MergedFlags : root_payload->WindowClass.DockNodeFlagsOverrideSet; - ImGuiDockNodeFlags dst_node_flags = host_node ? host_node->MergedFlags : host_window->WindowClass.DockNodeFlagsOverrideSet; - data->IsCenterAvailable = true; - if (is_outer_docking) - data->IsCenterAvailable = false; - else if (dst_node_flags & ImGuiDockNodeFlags_NoDocking) - data->IsCenterAvailable = false; - else if (host_node && (dst_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode()) - data->IsCenterAvailable = false; - else if ((!host_node || !host_node->IsEmpty()) && root_payload_as_host && root_payload_as_host->IsSplitNode() && (root_payload_as_host->OnlyNodeWithWindows == NULL)) // Is _visibly_ split? - data->IsCenterAvailable = false; - else if (dst_node_flags & ImGuiDockNodeFlags_NoDockingOverMe) - data->IsCenterAvailable = false; - else if ((src_node_flags & ImGuiDockNodeFlags_NoDockingOverOther) && (!host_node || !host_node->IsEmpty())) - data->IsCenterAvailable = false; - else if ((src_node_flags & ImGuiDockNodeFlags_NoDockingOverEmpty) && host_node && host_node->IsEmpty()) - data->IsCenterAvailable = false; - - data->IsSidesAvailable = true; - if ((dst_node_flags & ImGuiDockNodeFlags_NoSplit) || g.IO.ConfigDockingNoSplit) - data->IsSidesAvailable = false; - else if (!is_outer_docking && host_node && host_node->ParentNode == NULL && host_node->IsCentralNode()) - data->IsSidesAvailable = false; - else if ((dst_node_flags & ImGuiDockNodeFlags_NoDockingSplitMe) || (src_node_flags & ImGuiDockNodeFlags_NoDockingSplitOther)) - data->IsSidesAvailable = false; - - // Build a tentative future node (reuse same structure because it is practical. Shape will be readjusted when previewing a split) - data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton); - data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0); - data->FutureNode.Pos = ref_node_for_rect ? ref_node_for_rect->Pos : host_window->Pos; - data->FutureNode.Size = ref_node_for_rect ? ref_node_for_rect->Size : host_window->Size; - - // Calculate drop shapes geometry for allowed splitting directions - IM_ASSERT(ImGuiDir_None == -1); - data->SplitNode = host_node; - data->SplitDir = ImGuiDir_None; - data->IsSplitDirExplicit = false; - if (!host_window->Collapsed) - for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++) - { - if (dir == ImGuiDir_None && !data->IsCenterAvailable) - continue; - if (dir != ImGuiDir_None && !data->IsSidesAvailable) - continue; - if (DockNodeCalcDropRectsAndTestMousePos(data->FutureNode.Rect(), (ImGuiDir)dir, data->DropRectsDraw[dir+1], is_outer_docking, &g.IO.MousePos)) - { - data->SplitDir = (ImGuiDir)dir; - data->IsSplitDirExplicit = true; - } - } - - // We only allow and preview docking when hovering over a drop rect or over the title bar - data->IsDropAllowed = (data->SplitDir != ImGuiDir_None) || (data->IsCenterAvailable); - if (!is_explicit_target && !data->IsSplitDirExplicit) - data->IsDropAllowed = false; - - // Calculate split area - data->SplitRatio = 0.0f; - if (data->SplitDir != ImGuiDir_None) - { - ImGuiDir split_dir = data->SplitDir; - ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y; - ImVec2 pos_new, pos_old = data->FutureNode.Pos; - ImVec2 size_new, size_old = data->FutureNode.Size; - DockNodeCalcSplitRects(pos_old, size_old, pos_new, size_new, split_dir, root_payload->Size); - - // Calculate split ratio so we can pass it down the docking request - float split_ratio = ImSaturate(size_new[split_axis] / data->FutureNode.Size[split_axis]); - data->FutureNode.Pos = pos_new; - data->FutureNode.Size = size_new; - data->SplitRatio = (split_dir == ImGuiDir_Right || split_dir == ImGuiDir_Down) ? (1.0f - split_ratio) : (split_ratio); - } -} - -static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, const ImGuiDockPreviewData* data) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(g.CurrentWindow == host_window); // Because we rely on font size to calculate tab sizes - - // With this option, we only display the preview on the target viewport, and the payload viewport is made transparent. - // To compensate for the single layer obstructed by the payload, we'll increase the alpha of the preview nodes. - const bool is_transparent_payload = g.IO.ConfigDockingTransparentPayload; - - // In case the two windows involved are on different viewports, we will draw the overlay on each of them. - int overlay_draw_lists_count = 0; - ImDrawList* overlay_draw_lists[2]; - overlay_draw_lists[overlay_draw_lists_count++] = GetForegroundDrawList(host_window->Viewport); - if (host_window->Viewport != root_payload->Viewport && !is_transparent_payload) - overlay_draw_lists[overlay_draw_lists_count++] = GetForegroundDrawList(root_payload->Viewport); - - // Draw main preview rectangle - const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.60f : 0.40f); - const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.90f : 0.70f); - const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 1.20f : 1.00f); - const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, is_transparent_payload ? 0.80f : 0.60f); - - // Display area preview - const bool can_preview_tabs = (root_payload->DockNodeAsHost == NULL || root_payload->DockNodeAsHost->Windows.Size > 0); - if (data->IsDropAllowed) - { - ImRect overlay_rect = data->FutureNode.Rect(); - if (data->SplitDir == ImGuiDir_None && can_preview_tabs) - overlay_rect.Min.y += GetFrameHeight(); - if (data->SplitDir != ImGuiDir_None || data->IsCenterAvailable) - for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++) - overlay_draw_lists[overlay_n]->AddRectFilled(overlay_rect.Min, overlay_rect.Max, overlay_col_main, host_window->WindowRounding); - } - - // Display tab shape/label preview unless we are splitting node (it generally makes the situation harder to read) - if (data->IsDropAllowed && can_preview_tabs && data->SplitDir == ImGuiDir_None && data->IsCenterAvailable) - { - // Compute target tab bar geometry so we can locate our preview tabs - ImRect tab_bar_rect; - DockNodeCalcTabBarLayout(&data->FutureNode, NULL, &tab_bar_rect, NULL, NULL); - ImVec2 tab_pos = tab_bar_rect.Min; - if (host_node && host_node->TabBar) - { - if (!host_node->IsHiddenTabBar() && !host_node->IsNoTabBar()) - tab_pos.x += host_node->TabBar->WidthAllTabs + g.Style.ItemInnerSpacing.x; // We don't use OffsetNewTab because when using non-persistent-order tab bar it is incremented with each Tab submission. - else - tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_node->Windows[0]->Name, host_node->Windows[0]->HasCloseButton).x; - } - else if (!(host_window->Flags & ImGuiWindowFlags_DockNodeHost)) - { - tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_window->Name, host_window->HasCloseButton).x; // Account for slight offset which will be added when changing from title bar to tab bar - } - - // Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows) - if (root_payload->DockNodeAsHost) - IM_ASSERT(root_payload->DockNodeAsHost->Windows.Size <= root_payload->DockNodeAsHost->TabBar->Tabs.Size); - ImGuiTabBar* tab_bar_with_payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar : NULL; - const int payload_count = tab_bar_with_payload ? tab_bar_with_payload->Tabs.Size : 1; - for (int payload_n = 0; payload_n < payload_count; payload_n++) - { - // DockNode's TabBar may have non-window Tabs manually appended by user - ImGuiWindow* payload_window = tab_bar_with_payload ? tab_bar_with_payload->Tabs[payload_n].Window : root_payload; - if (tab_bar_with_payload && payload_window == NULL) - continue; - if (!DockNodeIsDropAllowedOne(payload_window, host_window)) - continue; - - // Calculate the tab bounding box for each payload window - ImVec2 tab_size = TabItemCalcSize(payload_window->Name, payload_window->HasCloseButton); - ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y); - tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x; - const ImU32 overlay_col_text = GetColorU32(payload_window->DockStyle.Colors[ImGuiWindowDockStyleCol_Text]); - const ImU32 overlay_col_tabs = GetColorU32(payload_window->DockStyle.Colors[ImGuiWindowDockStyleCol_TabActive]); - PushStyleColor(ImGuiCol_Text, overlay_col_text); - for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++) - { - ImGuiTabItemFlags tab_flags = ImGuiTabItemFlags_Preview | ((payload_window->Flags & ImGuiWindowFlags_UnsavedDocument) ? ImGuiTabItemFlags_UnsavedDocument : 0); - if (!tab_bar_rect.Contains(tab_bb)) - overlay_draw_lists[overlay_n]->PushClipRect(tab_bar_rect.Min, tab_bar_rect.Max); - TabItemBackground(overlay_draw_lists[overlay_n], tab_bb, tab_flags, overlay_col_tabs); - TabItemLabelAndCloseButton(overlay_draw_lists[overlay_n], tab_bb, tab_flags, g.Style.FramePadding, payload_window->Name, 0, 0, false, NULL, NULL); - if (!tab_bar_rect.Contains(tab_bb)) - overlay_draw_lists[overlay_n]->PopClipRect(); - } - PopStyleColor(); - } - } - - // Display drop boxes - const float overlay_rounding = ImMax(3.0f, g.Style.FrameRounding); - for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++) - { - if (!data->DropRectsDraw[dir + 1].IsInverted()) - { - ImRect draw_r = data->DropRectsDraw[dir + 1]; - ImRect draw_r_in = draw_r; - draw_r_in.Expand(-2.0f); - ImU32 overlay_col = (data->SplitDir == (ImGuiDir)dir && data->IsSplitDirExplicit) ? overlay_col_drop_hovered : overlay_col_drop; - for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++) - { - ImVec2 center = ImFloor(draw_r_in.GetCenter()); - overlay_draw_lists[overlay_n]->AddRectFilled(draw_r.Min, draw_r.Max, overlay_col, overlay_rounding); - overlay_draw_lists[overlay_n]->AddRect(draw_r_in.Min, draw_r_in.Max, overlay_col_lines, overlay_rounding); - if (dir == ImGuiDir_Left || dir == ImGuiDir_Right) - overlay_draw_lists[overlay_n]->AddLine(ImVec2(center.x, draw_r_in.Min.y), ImVec2(center.x, draw_r_in.Max.y), overlay_col_lines); - if (dir == ImGuiDir_Up || dir == ImGuiDir_Down) - overlay_draw_lists[overlay_n]->AddLine(ImVec2(draw_r_in.Min.x, center.y), ImVec2(draw_r_in.Max.x, center.y), overlay_col_lines); - } - } - - // Stop after ImGuiDir_None - if ((host_node && (host_node->MergedFlags & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit) - return; - } -} - -//----------------------------------------------------------------------------- -// Docking: ImGuiDockNode Tree manipulation functions -//----------------------------------------------------------------------------- -// - DockNodeTreeSplit() -// - DockNodeTreeMerge() -// - DockNodeTreeUpdatePosSize() -// - DockNodeTreeUpdateSplitterFindTouchingNode() -// - DockNodeTreeUpdateSplitter() -// - DockNodeTreeFindFallbackLeafNode() -// - DockNodeTreeFindNodeByPos() -//----------------------------------------------------------------------------- - -void ImGui::DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_inheritor_child_idx, float split_ratio, ImGuiDockNode* new_node) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(split_axis != ImGuiAxis_None); - - ImGuiDockNode* child_0 = (new_node && split_inheritor_child_idx != 0) ? new_node : DockContextAddNode(ctx, 0); - child_0->ParentNode = parent_node; - - ImGuiDockNode* child_1 = (new_node && split_inheritor_child_idx != 1) ? new_node : DockContextAddNode(ctx, 0); - child_1->ParentNode = parent_node; - - ImGuiDockNode* child_inheritor = (split_inheritor_child_idx == 0) ? child_0 : child_1; - DockNodeMoveChildNodes(child_inheritor, parent_node); - parent_node->ChildNodes[0] = child_0; - parent_node->ChildNodes[1] = child_1; - parent_node->ChildNodes[split_inheritor_child_idx]->VisibleWindow = parent_node->VisibleWindow; - parent_node->SplitAxis = split_axis; - parent_node->VisibleWindow = NULL; - parent_node->AuthorityForPos = parent_node->AuthorityForSize = ImGuiDataAuthority_DockNode; - - float size_avail = (parent_node->Size[split_axis] - DOCKING_SPLITTER_SIZE); - size_avail = ImMax(size_avail, g.Style.WindowMinSize[split_axis] * 2.0f); - IM_ASSERT(size_avail > 0.0f); // If you created a node manually with DockBuilderAddNode(), you need to also call DockBuilderSetNodeSize() before splitting. - child_0->SizeRef = child_1->SizeRef = parent_node->Size; - child_0->SizeRef[split_axis] = ImFloor(size_avail * split_ratio); - child_1->SizeRef[split_axis] = ImFloor(size_avail - child_0->SizeRef[split_axis]); - - DockNodeMoveWindows(parent_node->ChildNodes[split_inheritor_child_idx], parent_node); - DockSettingsRenameNodeReferences(parent_node->ID, parent_node->ChildNodes[split_inheritor_child_idx]->ID); - DockNodeTreeUpdatePosSize(parent_node, parent_node->Pos, parent_node->Size); - - // Flags transfer (e.g. this is where we transfer the ImGuiDockNodeFlags_CentralNode property) - child_0->SharedFlags = parent_node->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_; - child_1->SharedFlags = parent_node->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_; - child_inheritor->LocalFlags = parent_node->LocalFlags & ImGuiDockNodeFlags_LocalFlagsTransferMask_; - parent_node->LocalFlags &= ~ImGuiDockNodeFlags_LocalFlagsTransferMask_; - child_0->UpdateMergedFlags(); - child_1->UpdateMergedFlags(); - parent_node->UpdateMergedFlags(); - if (child_inheritor->IsCentralNode()) - DockNodeGetRootNode(parent_node)->CentralNode = child_inheritor; -} - -void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child) -{ - // When called from DockContextProcessUndockNode() it is possible that one of the child is NULL. - ImGuiDockNode* child_0 = parent_node->ChildNodes[0]; - ImGuiDockNode* child_1 = parent_node->ChildNodes[1]; - IM_ASSERT(child_0 || child_1); - IM_ASSERT(merge_lead_child == child_0 || merge_lead_child == child_1); - if ((child_0 && child_0->Windows.Size > 0) || (child_1 && child_1->Windows.Size > 0)) - { - IM_ASSERT(parent_node->TabBar == NULL); - IM_ASSERT(parent_node->Windows.Size == 0); - } - IMGUI_DEBUG_LOG_DOCKING("DockNodeTreeMerge 0x%08X & 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID); - - ImVec2 backup_last_explicit_size = parent_node->SizeRef; - DockNodeMoveChildNodes(parent_node, merge_lead_child); - if (child_0) - { - DockNodeMoveWindows(parent_node, child_0); // Generally only 1 of the 2 child node will have windows - DockSettingsRenameNodeReferences(child_0->ID, parent_node->ID); - } - if (child_1) - { - DockNodeMoveWindows(parent_node, child_1); - DockSettingsRenameNodeReferences(child_1->ID, parent_node->ID); - } - DockNodeApplyPosSizeToWindows(parent_node); - parent_node->AuthorityForPos = parent_node->AuthorityForSize = parent_node->AuthorityForViewport = ImGuiDataAuthority_Auto; - parent_node->VisibleWindow = merge_lead_child->VisibleWindow; - parent_node->SizeRef = backup_last_explicit_size; - - // Flags transfer - parent_node->LocalFlags &= ~ImGuiDockNodeFlags_LocalFlagsTransferMask_; // Preserve Dockspace flag - parent_node->LocalFlags |= (child_0 ? child_0->LocalFlags : 0) & ImGuiDockNodeFlags_LocalFlagsTransferMask_; - parent_node->LocalFlags |= (child_1 ? child_1->LocalFlags : 0) & ImGuiDockNodeFlags_LocalFlagsTransferMask_; - parent_node->LocalFlagsInWindows = (child_0 ? child_0->LocalFlagsInWindows : 0) | (child_1 ? child_1->LocalFlagsInWindows : 0); // FIXME: Would be more consistent to update from actual windows - parent_node->UpdateMergedFlags(); - - if (child_0) - { - ctx->DockContext.Nodes.SetVoidPtr(child_0->ID, NULL); - IM_DELETE(child_0); - } - if (child_1) - { - ctx->DockContext.Nodes.SetVoidPtr(child_1->ID, NULL); - IM_DELETE(child_1); - } -} - -// Update Pos/Size for a node hierarchy (don't affect child Windows yet) -void ImGui::DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size, bool only_write_to_marked_nodes) -{ - // During the regular dock node update we write to all nodes. - // 'only_write_to_marked_nodes' is only set when turning a node visible mid-frame and we need its size right-away. - const bool write_to_node = (only_write_to_marked_nodes == false) || (node->MarkedForPosSizeWrite); - if (write_to_node) - { - node->Pos = pos; - node->Size = size; - } - - if (node->IsLeafNode()) - return; - - ImGuiDockNode* child_0 = node->ChildNodes[0]; - ImGuiDockNode* child_1 = node->ChildNodes[1]; - ImVec2 child_0_pos = pos, child_1_pos = pos; - ImVec2 child_0_size = size, child_1_size = size; - if (child_0->IsVisible && child_1->IsVisible) - { - const float spacing = DOCKING_SPLITTER_SIZE; - const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis; - const float size_avail = ImMax(size[axis] - spacing, 0.0f); - - // Size allocation policy - // 1) The first 0..WindowMinSize[axis]*2 are allocated evenly to both windows. - ImGuiContext& g = *GImGui; - const float size_min_each = ImFloor(ImMin(size_avail, g.Style.WindowMinSize[axis] * 2.0f) * 0.5f); - - // 2) Process locked absolute size (during a splitter resize we preserve the child of nodes not touching the splitter edge) - if (child_0->WantLockSizeOnce && !child_1->WantLockSizeOnce) - { - child_0_size[axis] = child_0->SizeRef[axis] = ImMin(size_avail - 1.0f, child_0->Size[axis]); - child_1_size[axis] = child_1->SizeRef[axis] = (size_avail - child_0_size[axis]); - IM_ASSERT(child_0->SizeRef[axis] > 0.0f && child_1->SizeRef[axis] > 0.0f); - } - else if (child_1->WantLockSizeOnce && !child_0->WantLockSizeOnce) - { - child_1_size[axis] = child_1->SizeRef[axis] = ImMin(size_avail - 1.0f, child_1->Size[axis]); - child_0_size[axis] = child_0->SizeRef[axis] = (size_avail - child_1_size[axis]); - IM_ASSERT(child_0->SizeRef[axis] > 0.0f && child_1->SizeRef[axis] > 0.0f); - } - else if (child_0->WantLockSizeOnce && child_1->WantLockSizeOnce) - { - // FIXME-DOCK: We cannot honor the requested size, so apply ratio. - // Currently this path will only be taken if code programmatically sets WantLockSizeOnce - float ratio_0 = child_0_size[axis] / (child_0_size[axis] + child_1_size[axis]); - child_0_size[axis] = child_0->SizeRef[axis] = ImFloor(size_avail * ratio_0); - child_1_size[axis] = child_1->SizeRef[axis] = (size_avail - child_0_size[axis]); - IM_ASSERT(child_0->SizeRef[axis] > 0.0f && child_1->SizeRef[axis] > 0.0f); - } - - // 3) If one window is the central node (~ use remaining space, should be made explicit!), use explicit size from the other, and remainder for the central node - else if (child_1->IsCentralNode() && child_0->SizeRef[axis] != 0.0f) - { - child_0_size[axis] = ImMin(size_avail - size_min_each, child_0->SizeRef[axis]); - child_1_size[axis] = (size_avail - child_0_size[axis]); - } - else if (child_0->IsCentralNode() && child_1->SizeRef[axis] != 0.0f) - { - child_1_size[axis] = ImMin(size_avail - size_min_each, child_1->SizeRef[axis]); - child_0_size[axis] = (size_avail - child_1_size[axis]); - } - else - { - // 4) Otherwise distribute according to the relative ratio of each SizeRef value - float split_ratio = child_0->SizeRef[axis] / (child_0->SizeRef[axis] + child_1->SizeRef[axis]); - child_0_size[axis] = ImMax(size_min_each, ImFloor(size_avail * split_ratio + 0.5F)); - child_1_size[axis] = (size_avail - child_0_size[axis]); - } - - child_1_pos[axis] += spacing + child_0_size[axis]; - } - child_0->WantLockSizeOnce = child_1->WantLockSizeOnce = false; - - if (child_0->IsVisible) - DockNodeTreeUpdatePosSize(child_0, child_0_pos, child_0_size); - if (child_1->IsVisible) - DockNodeTreeUpdatePosSize(child_1, child_1_pos, child_1_size); -} - -static void DockNodeTreeUpdateSplitterFindTouchingNode(ImGuiDockNode* node, ImGuiAxis axis, int side, ImVector* touching_nodes) -{ - if (node->IsLeafNode()) - { - touching_nodes->push_back(node); - return; - } - if (node->ChildNodes[0]->IsVisible) - if (node->SplitAxis != axis || side == 0 || !node->ChildNodes[1]->IsVisible) - DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[0], axis, side, touching_nodes); - if (node->ChildNodes[1]->IsVisible) - if (node->SplitAxis != axis || side == 1 || !node->ChildNodes[0]->IsVisible) - DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[1], axis, side, touching_nodes); -} - -void ImGui::DockNodeTreeUpdateSplitter(ImGuiDockNode* node) -{ - if (node->IsLeafNode()) - return; - - ImGuiContext& g = *GImGui; - - ImGuiDockNode* child_0 = node->ChildNodes[0]; - ImGuiDockNode* child_1 = node->ChildNodes[1]; - if (child_0->IsVisible && child_1->IsVisible) - { - // Bounding box of the splitter cover the space between both nodes (w = Spacing, h = Size[xy^1] for when splitting horizontally) - const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis; - IM_ASSERT(axis != ImGuiAxis_None); - ImRect bb; - bb.Min = child_0->Pos; - bb.Max = child_1->Pos; - bb.Min[axis] += child_0->Size[axis]; - bb.Max[axis ^ 1] += child_1->Size[axis ^ 1]; - //if (g.IO.KeyCtrl) GetForegroundDrawList(g.CurrentWindow->Viewport)->AddRect(bb.Min, bb.Max, IM_COL32(255,0,255,255)); - - const ImGuiDockNodeFlags merged_flags = child_0->MergedFlags | child_1->MergedFlags; // Merged flags for BOTH childs - const ImGuiDockNodeFlags no_resize_axis_flag = (axis == ImGuiAxis_X) ? ImGuiDockNodeFlags_NoResizeX : ImGuiDockNodeFlags_NoResizeY; - if ((merged_flags & ImGuiDockNodeFlags_NoResize) || (merged_flags & no_resize_axis_flag)) - { - ImGuiWindow* window = g.CurrentWindow; - window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Separator), g.Style.FrameRounding); - } - else - { - //bb.Min[axis] += 1; // Display a little inward so highlight doesn't connect with nearby tabs on the neighbor node. - //bb.Max[axis] -= 1; - PushID(node->ID); - - // Gather list of nodes that are touching the splitter line. Find resizing limits based on those nodes. - ImVector touching_nodes[2]; - float min_size = g.Style.WindowMinSize[axis]; - float resize_limits[2]; - resize_limits[0] = node->ChildNodes[0]->Pos[axis] + min_size; - resize_limits[1] = node->ChildNodes[1]->Pos[axis] + node->ChildNodes[1]->Size[axis] - min_size; - - ImGuiID splitter_id = GetID("##Splitter"); - if (g.ActiveId == splitter_id) - { - // Only process when splitter is active - DockNodeTreeUpdateSplitterFindTouchingNode(child_0, axis, 1, &touching_nodes[0]); - DockNodeTreeUpdateSplitterFindTouchingNode(child_1, axis, 0, &touching_nodes[1]); - for (int touching_node_n = 0; touching_node_n < touching_nodes[0].Size; touching_node_n++) - resize_limits[0] = ImMax(resize_limits[0], touching_nodes[0][touching_node_n]->Rect().Min[axis] + min_size); - for (int touching_node_n = 0; touching_node_n < touching_nodes[1].Size; touching_node_n++) - resize_limits[1] = ImMin(resize_limits[1], touching_nodes[1][touching_node_n]->Rect().Max[axis] - min_size); - - /* - // [DEBUG] Render limits - ImDrawList* draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList(GetMainViewport()); - for (int n = 0; n < 2; n++) - if (axis == ImGuiAxis_X) - draw_list->AddLine(ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y), ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y + node->ChildNodes[n]->Size.y), IM_COL32(255, 0, 255, 255), 3.0f); - else - draw_list->AddLine(ImVec2(node->ChildNodes[n]->Pos.x, resize_limits[n]), ImVec2(node->ChildNodes[n]->Pos.x + node->ChildNodes[n]->Size.x, resize_limits[n]), IM_COL32(255, 0, 255, 255), 3.0f); - */ - } - - // Use a short delay before highlighting the splitter (and changing the mouse cursor) in order for regular mouse movement to not highlight many splitters - float cur_size_0 = child_0->Size[axis]; - float cur_size_1 = child_1->Size[axis]; - float min_size_0 = resize_limits[0] - child_0->Pos[axis]; - float min_size_1 = child_1->Pos[axis] + child_1->Size[axis] - resize_limits[1]; - if (SplitterBehavior(bb, GetID("##Splitter"), axis, &cur_size_0, &cur_size_1, min_size_0, min_size_1, WINDOWS_HOVER_PADDING, WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER)) - { - if (touching_nodes[0].Size > 0 && touching_nodes[1].Size > 0) - { - child_0->Size[axis] = child_0->SizeRef[axis] = cur_size_0; - child_1->Pos[axis] -= cur_size_1 - child_1->Size[axis]; - child_1->Size[axis] = child_1->SizeRef[axis] = cur_size_1; - - // Lock the size of every node that is a sibling of the node we are touching - // This might be less desirable if we can merge sibling of a same axis into the same parental level. - for (int side_n = 0; side_n < 2; side_n++) - for (int touching_node_n = 0; touching_node_n < touching_nodes[side_n].Size; touching_node_n++) - { - ImGuiDockNode* touching_node = touching_nodes[side_n][touching_node_n]; - //ImDrawList* draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList(GetMainViewport()); - //draw_list->AddRect(touching_node->Pos, touching_node->Pos + touching_node->Size, IM_COL32(255, 128, 0, 255)); - while (touching_node->ParentNode != node) - { - if (touching_node->ParentNode->SplitAxis == axis) - { - // Mark other node so its size will be preserved during the upcoming call to DockNodeTreeUpdatePosSize(). - ImGuiDockNode* node_to_preserve = touching_node->ParentNode->ChildNodes[side_n]; - node_to_preserve->WantLockSizeOnce = true; - //draw_list->AddRect(touching_node->Pos, touching_node->Rect().Max, IM_COL32(255, 0, 0, 255)); - //draw_list->AddRectFilled(node_to_preserve->Pos, node_to_preserve->Rect().Max, IM_COL32(0, 255, 0, 100)); - } - touching_node = touching_node->ParentNode; - } - } - - DockNodeTreeUpdatePosSize(child_0, child_0->Pos, child_0->Size); - DockNodeTreeUpdatePosSize(child_1, child_1->Pos, child_1->Size); - MarkIniSettingsDirty(); - } - } - PopID(); - } - } - - if (child_0->IsVisible) - DockNodeTreeUpdateSplitter(child_0); - if (child_1->IsVisible) - DockNodeTreeUpdateSplitter(child_1); -} - -ImGuiDockNode* ImGui::DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node) -{ - if (node->IsLeafNode()) - return node; - if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[0])) - return leaf_node; - if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[1])) - return leaf_node; - return NULL; -} - -ImGuiDockNode* ImGui::DockNodeTreeFindVisibleNodeByPos(ImGuiDockNode* node, ImVec2 pos) -{ - if (!node->IsVisible) - return NULL; - - const float dock_spacing = 0.0f;// g.Style.ItemInnerSpacing.x; // FIXME: Relation to DOCKING_SPLITTER_SIZE? - ImRect r(node->Pos, node->Pos + node->Size); - r.Expand(dock_spacing * 0.5f); - bool inside = r.Contains(pos); - if (!inside) - return NULL; - - if (node->IsLeafNode()) - return node; - if (ImGuiDockNode* hovered_node = DockNodeTreeFindVisibleNodeByPos(node->ChildNodes[0], pos)) - return hovered_node; - if (ImGuiDockNode* hovered_node = DockNodeTreeFindVisibleNodeByPos(node->ChildNodes[1], pos)) - return hovered_node; - - return NULL; -} - -//----------------------------------------------------------------------------- -// Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport) -//----------------------------------------------------------------------------- -// - SetWindowDock() [Internal] -// - DockSpace() -// - DockSpaceOverViewport() -//----------------------------------------------------------------------------- - -// [Internal] Called via SetNextWindowDockID() -void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond) -{ - // Test condition (NB: bit 0 is always true) and clear flags for next time - if (cond && (window->SetWindowDockAllowFlags & cond) == 0) - return; - window->SetWindowDockAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); - - if (window->DockId == dock_id) - return; - - // If the user attempt to set a dock id that is a split node, we'll dig within to find a suitable docking spot - ImGuiContext* ctx = GImGui; - if (ImGuiDockNode* new_node = DockContextFindNodeByID(ctx, dock_id)) - if (new_node->IsSplitNode()) - { - // Policy: Find central node or latest focused node. We first move back to our root node. - new_node = DockNodeGetRootNode(new_node); - if (new_node->CentralNode) - { - IM_ASSERT(new_node->CentralNode->IsCentralNode()); - dock_id = new_node->CentralNode->ID; - } - else - { - dock_id = new_node->LastFocusedNodeId; - } - } - - if (window->DockId == dock_id) - return; - - if (window->DockNode) - DockNodeRemoveWindow(window->DockNode, window, 0); - window->DockId = dock_id; -} - -// Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default. -// The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors. -// DockSpace() needs to be submitted _before_ any window they can host. If you use a dockspace, submit it early in your app. -ImGuiID ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags flags, const ImGuiWindowClass* window_class) -{ - ImGuiContext* ctx = GImGui; - ImGuiContext& g = *ctx; - ImGuiWindow* window = GetCurrentWindow(); - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) - return 0; - - // Early out if parent window is hidden/collapsed - // This is faster but also DockNodeUpdateTabBar() relies on TabBarLayout() running (which won't if SkipItems=true) to set NextSelectedTabId = 0). See #2960. - // If for whichever reason this is causing problem we would need to ensure that DockNodeUpdateTabBar() ends up clearing NextSelectedTabId even if SkipItems=true. - if (window->SkipItems) - flags |= ImGuiDockNodeFlags_KeepAliveOnly; - - IM_ASSERT((flags & ImGuiDockNodeFlags_DockSpace) == 0); - IM_ASSERT(id != 0); - ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); - if (!node) - { - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X created\n", id); - node = DockContextAddNode(ctx, id); - node->SetLocalFlags(ImGuiDockNodeFlags_CentralNode); - } - if (window_class && window_class->ClassId != node->WindowClass.ClassId) - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId); - node->SharedFlags = flags; - node->WindowClass = window_class ? *window_class : ImGuiWindowClass(); - - // When a DockSpace transitioned form implicit to explicit this may be called a second time - // It is possible that the node has already been claimed by a docked window which appeared before the DockSpace() node, so we overwrite IsDockSpace again. - if (node->LastFrameActive == g.FrameCount && !(flags & ImGuiDockNodeFlags_KeepAliveOnly)) - { - IM_ASSERT(node->IsDockSpace() == false && "Cannot call DockSpace() twice a frame with the same ID"); - node->SetLocalFlags(node->LocalFlags | ImGuiDockNodeFlags_DockSpace); - return id; - } - node->SetLocalFlags(node->LocalFlags | ImGuiDockNodeFlags_DockSpace); - - // Keep alive mode, this is allow windows docked into this node so stay docked even if they are not visible - if (flags & ImGuiDockNodeFlags_KeepAliveOnly) - { - node->LastFrameAlive = g.FrameCount; - return id; - } - - const ImVec2 content_avail = GetContentRegionAvail(); - ImVec2 size = ImFloor(size_arg); - if (size.x <= 0.0f) - size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues) - if (size.y <= 0.0f) - size.y = ImMax(content_avail.y + size.y, 4.0f); - IM_ASSERT(size.x > 0.0f && size.y > 0.0f); - - node->Pos = window->DC.CursorPos; - node->Size = node->SizeRef = size; - SetNextWindowPos(node->Pos); - SetNextWindowSize(node->Size); - g.NextWindowData.PosUndock = false; - - // FIXME-DOCK: Why do we need a child window to host a dockspace, could we host it in the existing window? - // FIXME-DOCK: What is the reason for not simply calling BeginChild()? (OK to have a reason but should be commented) - ImGuiWindowFlags window_flags = ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_DockNodeHost; - window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar; - window_flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse; - window_flags |= ImGuiWindowFlags_NoBackground; - - char title[256]; - ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", window->Name, id); - - PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f); - Begin(title, NULL, window_flags); - PopStyleVar(); - - ImGuiWindow* host_window = g.CurrentWindow; - DockNodeSetupHostWindow(node, host_window); - host_window->ChildId = window->GetID(title); - node->OnlyNodeWithWindows = NULL; - - IM_ASSERT(node->IsRootNode()); - - // We need to handle the rare case were a central node is missing. - // This can happen if the node was first created manually with DockBuilderAddNode() but _without_ the ImGuiDockNodeFlags_Dockspace. - // Doing it correctly would set the _CentralNode flags, which would then propagate according to subsequent split. - // It would also be ambiguous to attempt to assign a central node while there are split nodes, so we wait until there's a single node remaining. - // The specific sub-property of _CentralNode we are interested in recovering here is the "Don't delete when empty" property, - // as it doesn't make sense for an empty dockspace to not have this property. - if (node->IsLeafNode() && !node->IsCentralNode()) - node->SetLocalFlags(node->LocalFlags | ImGuiDockNodeFlags_CentralNode); - - // Update the node - DockNodeUpdate(node); - - End(); - ItemSize(size); - return id; -} - -// Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode! -// The limitation with this call is that your window won't have a menu bar. -// Even though we could pass window flags, it would also require the user to be able to call BeginMenuBar() somehow meaning we can't Begin/End in a single function. -// But you can also use BeginMainMenuBar(). If you really want a menu bar inside the same window as the one hosting the dockspace, you will need to copy this code somewhere and tweak it. -ImGuiID ImGui::DockSpaceOverViewport(const ImGuiViewport* viewport, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class) -{ - if (viewport == NULL) - viewport = GetMainViewport(); - - SetNextWindowPos(viewport->WorkPos); - SetNextWindowSize(viewport->WorkSize); - SetNextWindowViewport(viewport->ID); - - ImGuiWindowFlags host_window_flags = 0; - host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking; - host_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; - if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) - host_window_flags |= ImGuiWindowFlags_NoBackground; - - char label[32]; - ImFormatString(label, IM_ARRAYSIZE(label), "DockSpaceViewport_%08X", viewport->ID); - - PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - Begin(label, NULL, host_window_flags); - PopStyleVar(3); - - ImGuiID dockspace_id = GetID("DockSpace"); - DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, window_class); - End(); - - return dockspace_id; -} - -//----------------------------------------------------------------------------- -// Docking: Builder Functions -//----------------------------------------------------------------------------- -// Very early end-user API to manipulate dock nodes. -// Only available in imgui_internal.h. Expect this API to change/break! -// It is expected that those functions are all called _before_ the dockspace node submission. -//----------------------------------------------------------------------------- -// - DockBuilderDockWindow() -// - DockBuilderGetNode() -// - DockBuilderSetNodePos() -// - DockBuilderSetNodeSize() -// - DockBuilderAddNode() -// - DockBuilderRemoveNode() -// - DockBuilderRemoveNodeChildNodes() -// - DockBuilderRemoveNodeDockedWindows() -// - DockBuilderSplitNode() -// - DockBuilderCopyNodeRec() -// - DockBuilderCopyNode() -// - DockBuilderCopyWindowSettings() -// - DockBuilderCopyDockSpace() -// - DockBuilderFinish() -//----------------------------------------------------------------------------- - -void ImGui::DockBuilderDockWindow(const char* window_name, ImGuiID node_id) -{ - // We don't preserve relative order of multiple docked windows (by clearing DockOrder back to -1) - ImGuiID window_id = ImHashStr(window_name); - if (ImGuiWindow* window = FindWindowByID(window_id)) - { - // Apply to created window - SetWindowDock(window, node_id, ImGuiCond_Always); - window->DockOrder = -1; - } - else - { - // Apply to settings - ImGuiWindowSettings* settings = FindWindowSettings(window_id); - if (settings == NULL) - settings = CreateNewWindowSettings(window_name); - settings->DockId = node_id; - settings->DockOrder = -1; - } -} - -ImGuiDockNode* ImGui::DockBuilderGetNode(ImGuiID node_id) -{ - ImGuiContext* ctx = GImGui; - return DockContextFindNodeByID(ctx, node_id); -} - -void ImGui::DockBuilderSetNodePos(ImGuiID node_id, ImVec2 pos) -{ - ImGuiContext* ctx = GImGui; - ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id); - if (node == NULL) - return; - node->Pos = pos; - node->AuthorityForPos = ImGuiDataAuthority_DockNode; -} - -void ImGui::DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size) -{ - ImGuiContext* ctx = GImGui; - ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id); - if (node == NULL) - return; - IM_ASSERT(size.x > 0.0f && size.y > 0.0f); - node->Size = node->SizeRef = size; - node->AuthorityForSize = ImGuiDataAuthority_DockNode; -} - -// Make sure to use the ImGuiDockNodeFlags_DockSpace flag to create a dockspace node! Otherwise this will create a floating node! -// - Floating node: you can then call DockBuilderSetNodePos()/DockBuilderSetNodeSize() to position and size the floating node. -// - Dockspace node: calling DockBuilderSetNodePos() is unnecessary. -// - If you intend to split a node immediately after creation using DockBuilderSplitNode(), make sure to call DockBuilderSetNodeSize() beforehand! -// For various reason, the splitting code currently needs a base size otherwise space may not be allocated as precisely as you would expect. -// - Use (id == 0) to let the system allocate a node identifier. -// - Existing node with a same id will be removed. -ImGuiID ImGui::DockBuilderAddNode(ImGuiID id, ImGuiDockNodeFlags flags) -{ - ImGuiContext* ctx = GImGui; - - if (id != 0) - DockBuilderRemoveNode(id); - - ImGuiDockNode* node = NULL; - if (flags & ImGuiDockNodeFlags_DockSpace) - { - DockSpace(id, ImVec2(0, 0), (flags & ~ImGuiDockNodeFlags_DockSpace) | ImGuiDockNodeFlags_KeepAliveOnly); - node = DockContextFindNodeByID(ctx, id); - } - else - { - node = DockContextAddNode(ctx, id); - node->SetLocalFlags(flags); - } - node->LastFrameAlive = ctx->FrameCount; // Set this otherwise BeginDocked will undock during the same frame. - return node->ID; -} - -void ImGui::DockBuilderRemoveNode(ImGuiID node_id) -{ - ImGuiContext* ctx = GImGui; - ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id); - if (node == NULL) - return; - DockBuilderRemoveNodeDockedWindows(node_id, true); - DockBuilderRemoveNodeChildNodes(node_id); - // Node may have moved or deleted if e.g. any merge happened - node = DockContextFindNodeByID(ctx, node_id); - if (node == NULL) - return; - if (node->IsCentralNode() && node->ParentNode) - node->ParentNode->SetLocalFlags(node->ParentNode->LocalFlags | ImGuiDockNodeFlags_CentralNode); - DockContextRemoveNode(ctx, node, true); -} - -// root_id = 0 to remove all, root_id != 0 to remove child of given node. -void ImGui::DockBuilderRemoveNodeChildNodes(ImGuiID root_id) -{ - ImGuiContext* ctx = GImGui; - ImGuiDockContext* dc = &ctx->DockContext; - - ImGuiDockNode* root_node = root_id ? DockContextFindNodeByID(ctx, root_id) : NULL; - if (root_id && root_node == NULL) - return; - bool has_central_node = false; - - ImGuiDataAuthority backup_root_node_authority_for_pos = root_node ? root_node->AuthorityForPos : ImGuiDataAuthority_Auto; - ImGuiDataAuthority backup_root_node_authority_for_size = root_node ? root_node->AuthorityForSize : ImGuiDataAuthority_Auto; - - // Process active windows - ImVector nodes_to_remove; - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - { - bool want_removal = (root_id == 0) || (node->ID != root_id && DockNodeGetRootNode(node)->ID == root_id); - if (want_removal) - { - if (node->IsCentralNode()) - has_central_node = true; - if (root_id != 0) - DockContextQueueNotifyRemovedNode(ctx, node); - if (root_node) - { - DockNodeMoveWindows(root_node, node); - DockSettingsRenameNodeReferences(node->ID, root_node->ID); - } - nodes_to_remove.push_back(node); - } - } - - // DockNodeMoveWindows->DockNodeAddWindow will normally set those when reaching two windows (which is only adequate during interactive merge) - // Make sure we don't lose our current pos/size. (FIXME-DOCK: Consider tidying up that code in DockNodeAddWindow instead) - if (root_node) - { - root_node->AuthorityForPos = backup_root_node_authority_for_pos; - root_node->AuthorityForSize = backup_root_node_authority_for_size; - } - - // Apply to settings - for (ImGuiWindowSettings* settings = ctx->SettingsWindows.begin(); settings != NULL; settings = ctx->SettingsWindows.next_chunk(settings)) - if (ImGuiID window_settings_dock_id = settings->DockId) - for (int n = 0; n < nodes_to_remove.Size; n++) - if (nodes_to_remove[n]->ID == window_settings_dock_id) - { - settings->DockId = root_id; - break; - } - - // Not really efficient, but easier to destroy a whole hierarchy considering DockContextRemoveNode is attempting to merge nodes - if (nodes_to_remove.Size > 1) - ImQsort(nodes_to_remove.Data, nodes_to_remove.Size, sizeof(ImGuiDockNode*), DockNodeComparerDepthMostFirst); - for (int n = 0; n < nodes_to_remove.Size; n++) - DockContextRemoveNode(ctx, nodes_to_remove[n], false); - - if (root_id == 0) - { - dc->Nodes.Clear(); - dc->Requests.clear(); - } - else if (has_central_node) - { - root_node->CentralNode = root_node; - root_node->SetLocalFlags(root_node->LocalFlags | ImGuiDockNodeFlags_CentralNode); - } -} - -void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_settings_refs) -{ - // Clear references in settings - ImGuiContext* ctx = GImGui; - ImGuiContext& g = *ctx; - if (clear_settings_refs) - { - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - { - bool want_removal = (root_id == 0) || (settings->DockId == root_id); - if (!want_removal && settings->DockId != 0) - if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, settings->DockId)) - if (DockNodeGetRootNode(node)->ID == root_id) - want_removal = true; - if (want_removal) - settings->DockId = 0; - } - } - - // Clear references in windows - for (int n = 0; n < g.Windows.Size; n++) - { - ImGuiWindow* window = g.Windows[n]; - bool want_removal = (root_id == 0) || (window->DockNode && DockNodeGetRootNode(window->DockNode)->ID == root_id) || (window->DockNodeAsHost && window->DockNodeAsHost->ID == root_id); - if (want_removal) - { - const ImGuiID backup_dock_id = window->DockId; - IM_UNUSED(backup_dock_id); - DockContextProcessUndockWindow(ctx, window, clear_settings_refs); - if (!clear_settings_refs) - IM_ASSERT(window->DockId == backup_dock_id); - } - } -} - -// If 'out_id_at_dir' or 'out_id_at_opposite_dir' are non NULL, the function will write out the ID of the two new nodes created. -// Return value is ID of the node at the specified direction, so same as (*out_id_at_dir) if that pointer is set. -// FIXME-DOCK: We are not exposing nor using split_outer. -ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir) -{ - ImGuiContext* ctx = GImGui; - IM_ASSERT(split_dir != ImGuiDir_None); - IMGUI_DEBUG_LOG_DOCKING("DockBuilderSplitNode node 0x%08X, split_dir %d\n", id, split_dir); - - ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); - if (node == NULL) - { - IM_ASSERT(node != NULL); - return 0; - } - - IM_ASSERT(!node->IsSplitNode()); // Assert if already Split - - ImGuiDockRequest req; - req.Type = ImGuiDockRequestType_Split; - req.DockTargetWindow = NULL; - req.DockTargetNode = node; - req.DockPayload = NULL; - req.DockSplitDir = split_dir; - req.DockSplitRatio = ImSaturate((split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? size_ratio_for_node_at_dir : 1.0f - size_ratio_for_node_at_dir); - req.DockSplitOuter = false; - DockContextProcessDock(ctx, &req); - - ImGuiID id_at_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 0 : 1]->ID; - ImGuiID id_at_opposite_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0]->ID; - if (out_id_at_dir) - *out_id_at_dir = id_at_dir; - if (out_id_at_opposite_dir) - *out_id_at_opposite_dir = id_at_opposite_dir; - return id_at_dir; -} - -static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID dst_node_id_if_known, ImVector* out_node_remap_pairs) -{ - ImGuiContext* ctx = GImGui; - ImGuiDockNode* dst_node = ImGui::DockContextAddNode(ctx, dst_node_id_if_known); - dst_node->SharedFlags = src_node->SharedFlags; - dst_node->LocalFlags = src_node->LocalFlags; - dst_node->LocalFlagsInWindows = ImGuiDockNodeFlags_None; - dst_node->Pos = src_node->Pos; - dst_node->Size = src_node->Size; - dst_node->SizeRef = src_node->SizeRef; - dst_node->SplitAxis = src_node->SplitAxis; - dst_node->UpdateMergedFlags(); - - out_node_remap_pairs->push_back(src_node->ID); - out_node_remap_pairs->push_back(dst_node->ID); - - for (int child_n = 0; child_n < IM_ARRAYSIZE(src_node->ChildNodes); child_n++) - if (src_node->ChildNodes[child_n]) - { - dst_node->ChildNodes[child_n] = DockBuilderCopyNodeRec(src_node->ChildNodes[child_n], 0, out_node_remap_pairs); - dst_node->ChildNodes[child_n]->ParentNode = dst_node; - } - - IMGUI_DEBUG_LOG_DOCKING("Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0); - return dst_node; -} - -void ImGui::DockBuilderCopyNode(ImGuiID src_node_id, ImGuiID dst_node_id, ImVector* out_node_remap_pairs) -{ - ImGuiContext* ctx = GImGui; - IM_ASSERT(src_node_id != 0); - IM_ASSERT(dst_node_id != 0); - IM_ASSERT(out_node_remap_pairs != NULL); - - DockBuilderRemoveNode(dst_node_id); - - ImGuiDockNode* src_node = DockContextFindNodeByID(ctx, src_node_id); - IM_ASSERT(src_node != NULL); - - out_node_remap_pairs->clear(); - DockBuilderCopyNodeRec(src_node, dst_node_id, out_node_remap_pairs); - - IM_ASSERT((out_node_remap_pairs->Size % 2) == 0); -} - -void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name) -{ - ImGuiWindow* src_window = FindWindowByName(src_name); - if (src_window == NULL) - return; - if (ImGuiWindow* dst_window = FindWindowByName(dst_name)) - { - dst_window->Pos = src_window->Pos; - dst_window->Size = src_window->Size; - dst_window->SizeFull = src_window->SizeFull; - dst_window->Collapsed = src_window->Collapsed; - } - else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name)) - { - ImVec2ih window_pos_2ih = ImVec2ih(src_window->Pos); - if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID) - { - dst_settings->ViewportPos = window_pos_2ih; - dst_settings->ViewportId = src_window->ViewportId; - dst_settings->Pos = ImVec2ih(0, 0); - } - else - { - dst_settings->Pos = window_pos_2ih; - } - dst_settings->Size = ImVec2ih(src_window->SizeFull); - dst_settings->Collapsed = src_window->Collapsed; - } -} - -// FIXME: Will probably want to change this signature, in particular how the window remapping pairs are passed. -void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs) -{ - IM_ASSERT(src_dockspace_id != 0); - IM_ASSERT(dst_dockspace_id != 0); - IM_ASSERT(in_window_remap_pairs != NULL); - IM_ASSERT((in_window_remap_pairs->Size % 2) == 0); - - // Duplicate entire dock - // FIXME: When overwriting dst_dockspace_id, windows that aren't part of our dockspace window class but that are docked in a same node will be split apart, - // whereas we could attempt to at least keep them together in a new, same floating node. - ImVector node_remap_pairs; - DockBuilderCopyNode(src_dockspace_id, dst_dockspace_id, &node_remap_pairs); - - // Attempt to transition all the upcoming windows associated to dst_dockspace_id into the newly created hierarchy of dock nodes - // (The windows associated to src_dockspace_id are staying in place) - ImVector src_windows; - for (int remap_window_n = 0; remap_window_n < in_window_remap_pairs->Size; remap_window_n += 2) - { - const char* src_window_name = (*in_window_remap_pairs)[remap_window_n]; - const char* dst_window_name = (*in_window_remap_pairs)[remap_window_n + 1]; - ImGuiID src_window_id = ImHashStr(src_window_name); - src_windows.push_back(src_window_id); - - // Search in the remapping tables - ImGuiID src_dock_id = 0; - if (ImGuiWindow* src_window = FindWindowByID(src_window_id)) - src_dock_id = src_window->DockId; - else if (ImGuiWindowSettings* src_window_settings = FindWindowSettings(src_window_id)) - src_dock_id = src_window_settings->DockId; - ImGuiID dst_dock_id = 0; - for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2) - if (node_remap_pairs[dock_remap_n] == src_dock_id) - { - dst_dock_id = node_remap_pairs[dock_remap_n + 1]; - //node_remap_pairs[dock_remap_n] = node_remap_pairs[dock_remap_n + 1] = 0; // Clear - break; - } - - if (dst_dock_id != 0) - { - // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id); - DockBuilderDockWindow(dst_window_name, dst_dock_id); - } - else - { - // Floating windows gets their settings transferred (regardless of whether the new window already exist or not) - // When this is leading to a Copy and not a Move, we would get two overlapping floating windows. Could we possibly dock them together? - IMGUI_DEBUG_LOG_DOCKING("Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name); - DockBuilderCopyWindowSettings(src_window_name, dst_window_name); - } - } - - // Anything else in the source nodes of 'node_remap_pairs' are windows that were docked in src_dockspace_id but are not owned by it (unaffiliated windows, e.g. "ImGui Demo") - // Find those windows and move to them to the cloned dock node. This may be optional? - for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2) - if (ImGuiID src_dock_id = node_remap_pairs[dock_remap_n]) - { - ImGuiID dst_dock_id = node_remap_pairs[dock_remap_n + 1]; - ImGuiDockNode* node = DockBuilderGetNode(src_dock_id); - for (int window_n = 0; window_n < node->Windows.Size; window_n++) - { - ImGuiWindow* window = node->Windows[window_n]; - if (src_windows.contains(window->ID)) - continue; - - // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); - DockBuilderDockWindow(window->Name, dst_dock_id); - } - } -} - -void ImGui::DockBuilderFinish(ImGuiID root_id) -{ - ImGuiContext* ctx = GImGui; - //DockContextRebuild(ctx); - DockContextBuildAddWindowsToNodes(ctx, root_id); -} - -//----------------------------------------------------------------------------- -// Docking: Begin/End Support Functions (called from Begin/End) -//----------------------------------------------------------------------------- -// - GetWindowAlwaysWantOwnTabBar() -// - DockContextBindNodeToWindow() -// - BeginDocked() -// - BeginDockableDragDropSource() -// - BeginDockableDragDropTarget() -//----------------------------------------------------------------------------- - -bool ImGui::GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - if (g.IO.ConfigDockingAlwaysTabBar || window->WindowClass.DockingAlwaysTabBar) - if ((window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking)) == 0) - if (!window->IsFallbackWindow) // We don't support AlwaysTabBar on the fallback/implicit window to avoid unused dock-node overhead/noise - return true; - return false; -} - -static ImGuiDockNode* ImGui::DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window) -{ - ImGuiContext& g = *ctx; - ImGuiDockNode* node = DockContextFindNodeByID(ctx, window->DockId); - IM_ASSERT(window->DockNode == NULL); - - // We should not be docking into a split node (SetWindowDock should avoid this) - if (node && node->IsSplitNode()) - { - DockContextProcessUndockWindow(ctx, window); - return NULL; - } - - // Create node - if (node == NULL) - { - node = DockContextAddNode(ctx, window->DockId); - node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window; - node->LastFrameAlive = g.FrameCount; - } - - // If the node just turned visible and is part of a hierarchy, it doesn't have a Size assigned by DockNodeTreeUpdatePosSize() yet, - // so we're forcing a Pos/Size update from the first ancestor that is already visible (often it will be the root node). - // If we don't do this, the window will be assigned a zero-size on its first frame, which won't ideally warm up the layout. - // This is a little wonky because we don't normally update the Pos/Size of visible node mid-frame. - if (!node->IsVisible) - { - ImGuiDockNode* ancestor_node = node; - while (!ancestor_node->IsVisible) - { - ancestor_node->IsVisible = true; - ancestor_node->MarkedForPosSizeWrite = true; - if (ancestor_node->ParentNode) - ancestor_node = ancestor_node->ParentNode; - } - IM_ASSERT(ancestor_node->Size.x > 0.0f && ancestor_node->Size.y > 0.0f); - DockNodeTreeUpdatePosSize(ancestor_node, ancestor_node->Pos, ancestor_node->Size, true); - } - - // Add window to node - DockNodeAddWindow(node, window, true); - IM_ASSERT(node == window->DockNode); - return node; -} - -void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) -{ - ImGuiContext* ctx = GImGui; - ImGuiContext& g = *ctx; - - // Clear fields ahead so most early-out paths don't have to do it - window->DockIsActive = window->DockNodeIsVisible = window->DockTabIsVisible = false; - - const bool auto_dock_node = GetWindowAlwaysWantOwnTabBar(window); - if (auto_dock_node) - { - if (window->DockId == 0) - { - IM_ASSERT(window->DockNode == NULL); - window->DockId = DockContextGenNodeID(ctx); - } - } - else - { - // Calling SetNextWindowPos() undock windows by default (by setting PosUndock) - bool want_undock = false; - want_undock |= (window->Flags & ImGuiWindowFlags_NoDocking) != 0; - want_undock |= (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) && (window->SetWindowPosAllowFlags & g.NextWindowData.PosCond) && g.NextWindowData.PosUndock; - if (want_undock) - { - DockContextProcessUndockWindow(ctx, window); - return; - } - } - - // Bind to our dock node - ImGuiDockNode* node = window->DockNode; - if (node != NULL) - IM_ASSERT(window->DockId == node->ID); - if (window->DockId != 0 && node == NULL) - { - node = DockContextBindNodeToWindow(ctx, window); - if (node == NULL) - return; - } - -#if 0 - // Undock if the ImGuiDockNodeFlags_NoDockingInCentralNode got set - if (node->IsCentralNode && (node->Flags & ImGuiDockNodeFlags_NoDockingInCentralNode)) - { - DockContextProcessUndockWindow(ctx, window); - return; - } -#endif - - // Undock if our dockspace node disappeared - // Note how we are testing for LastFrameAlive and NOT LastFrameActive. A DockSpace node can be maintained alive while being inactive with ImGuiDockNodeFlags_KeepAliveOnly. - if (node->LastFrameAlive < g.FrameCount) - { - // If the window has been orphaned, transition the docknode to an implicit node processed in DockContextNewFrameUpdateDocking() - ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (root_node->LastFrameAlive < g.FrameCount) - DockContextProcessUndockWindow(ctx, window); - else - window->DockIsActive = true; - return; - } - - // Store style overrides - for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) - window->DockStyle.Colors[color_n] = ColorConvertFloat4ToU32(g.Style.Colors[GWindowDockStyleColors[color_n]]); - - // Fast path return. It is common for windows to hold on a persistent DockId but be the only visible window, - // and never create neither a host window neither a tab bar. - // FIXME-DOCK: replace ->HostWindow NULL compare with something more explicit (~was initially intended as a first frame test) - if (node->HostWindow == NULL) - { - if (node->State == ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing) - window->DockIsActive = true; - if (node->Windows.Size > 1) - DockNodeHideWindowDuringHostWindowCreation(window); - return; - } - - // We can have zero-sized nodes (e.g. children of a small-size dockspace) - IM_ASSERT(node->HostWindow); - IM_ASSERT(node->IsLeafNode()); - IM_ASSERT(node->Size.x >= 0.0f && node->Size.y >= 0.0f); - node->State = ImGuiDockNodeState_HostWindowVisible; - - // Undock if we are submitted earlier than the host window - if (window->BeginOrderWithinContext < node->HostWindow->BeginOrderWithinContext) - { - DockContextProcessUndockWindow(ctx, window); - return; - } - - // Position/Size window - SetNextWindowPos(node->Pos); - SetNextWindowSize(node->Size); - g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos() - window->DockIsActive = true; - window->DockNodeIsVisible = true; - window->DockTabIsVisible = false; - if (node->MergedFlags & ImGuiDockNodeFlags_KeepAliveOnly) - return; - - // When the window is selected we mark it as visible. - if (node->VisibleWindow == window) - window->DockTabIsVisible = true; - - // Update window flag - IM_ASSERT((window->Flags & ImGuiWindowFlags_ChildWindow) == 0); - window->Flags |= ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoResize; - if (node->IsHiddenTabBar() || node->IsNoTabBar()) - window->Flags |= ImGuiWindowFlags_NoTitleBar; - else - window->Flags &= ~ImGuiWindowFlags_NoTitleBar; // Clear the NoTitleBar flag in case the user set it: confusingly enough we need a title bar height so we are correctly offset, but it won't be displayed! - - // Save new dock order only if the window has been visible once already - // This allows multiple windows to be created in the same frame and have their respective dock orders preserved. - if (node->TabBar && window->WasActive) - window->DockOrder = (short)DockNodeGetTabOrder(window); - - if ((node->WantCloseAll || node->WantCloseTabId == window->ID) && p_open != NULL) - *p_open = false; - - // Update ChildId to allow returning from Child to Parent with Escape - ImGuiWindow* parent_window = window->DockNode->HostWindow; - window->ChildId = parent_window->GetID(window->Name); -} - -void ImGui::BeginDockableDragDropSource(ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(g.ActiveId == window->MoveId); - IM_ASSERT(g.MovingWindow == window); - IM_ASSERT(g.CurrentWindow == window); - - g.LastItemData.ID = window->MoveId; - window = window->RootWindowDockTree; - IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0); - bool is_drag_docking = ImRect(0, 0, window->SizeFull.x, GetFrameHeight()).Contains(g.ActiveIdClickOffset); // FIXME-DOCKING: Need to make this stateful and explicit - if (is_drag_docking && BeginDragDropSource(ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers | ImGuiDragDropFlags_SourceAutoExpirePayload)) - { - SetDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, &window, sizeof(window)); - EndDragDropSource(); - - // Store style overrides - for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) - window->DockStyle.Colors[color_n] = ColorConvertFloat4ToU32(g.Style.Colors[GWindowDockStyleColors[color_n]]); - } -} - -void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) -{ - ImGuiContext* ctx = GImGui; - ImGuiContext& g = *ctx; - - //IM_ASSERT(window->RootWindowDockTree == window); // May also be a DockSpace - IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0); - if (!g.DragDropActive) - return; - //GetForegroundDrawList(window)->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255)); - if (!BeginDragDropTargetCustom(window->Rect(), window->ID)) - return; - - // Peek into the payload before calling AcceptDragDropPayload() so we can handle overlapping dock nodes with filtering - // (this is a little unusual pattern, normally most code would call AcceptDragDropPayload directly) - const ImGuiPayload* payload = &g.DragDropPayload; - if (!payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) || !DockNodeIsDropAllowed(window, *(ImGuiWindow**)payload->Data)) - { - EndDragDropTarget(); - return; - } - - ImGuiWindow* payload_window = *(ImGuiWindow**)payload->Data; - if (AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect)) - { - // Select target node - // (Important: we cannot use g.HoveredDockNode here! Because each of our target node have filters based on payload, each candidate drop target will do its own evaluation) - bool dock_into_floating_window = false; - ImGuiDockNode* node = NULL; - if (window->DockNodeAsHost) - { - // Cannot assume that node will != NULL even though we passed the rectangle test: it depends on padding/spacing handled by DockNodeTreeFindVisibleNodeByPos(). - node = DockNodeTreeFindVisibleNodeByPos(window->DockNodeAsHost, g.IO.MousePos); - - // There is an edge case when docking into a dockspace which only has _inactive_ nodes (because none of the windows are active) - // In this case we need to fallback into any leaf mode, possibly the central node. - // FIXME-20181220: We should not have to test for IsLeafNode() here but we have another bug to fix first. - if (node && node->IsDockSpace() && node->IsRootNode()) - node = (node->CentralNode && node->IsLeafNode()) ? node->CentralNode : DockNodeTreeFindFallbackLeafNode(node); - } - else - { - if (window->DockNode) - node = window->DockNode; - else - dock_into_floating_window = true; // Dock into a regular window - } - - const ImRect explicit_target_rect = (node && node->TabBar && !node->IsHiddenTabBar() && !node->IsNoTabBar()) ? node->TabBar->BarRect : ImRect(window->Pos, window->Pos + ImVec2(window->Size.x, GetFrameHeight())); - const bool is_explicit_target = IsMouseHoveringRect(explicit_target_rect.Min, explicit_target_rect.Max); - - // Preview docking request and find out split direction/ratio - //const bool do_preview = true; // Ignore testing for payload->IsPreview() which removes one frame of delay, but breaks overlapping drop targets within the same window. - const bool do_preview = payload->IsPreview() || payload->IsDelivery(); - if (do_preview && (node != NULL || dock_into_floating_window)) - { - ImGuiDockPreviewData split_inner; - ImGuiDockPreviewData split_outer; - ImGuiDockPreviewData* split_data = &split_inner; - if (node && (node->ParentNode || node->IsCentralNode())) - if (ImGuiDockNode* root_node = DockNodeGetRootNode(node)) - { - DockNodePreviewDockSetup(window, root_node, payload_window, &split_outer, is_explicit_target, true); - if (split_outer.IsSplitDirExplicit) - split_data = &split_outer; - } - DockNodePreviewDockSetup(window, node, payload_window, &split_inner, is_explicit_target, false); - if (split_data == &split_outer) - split_inner.IsDropAllowed = false; - - // Draw inner then outer, so that previewed tab (in inner data) will be behind the outer drop boxes - DockNodePreviewDockRender(window, node, payload_window, &split_inner); - DockNodePreviewDockRender(window, node, payload_window, &split_outer); - - // Queue docking request - if (split_data->IsDropAllowed && payload->IsDelivery()) - DockContextQueueDock(ctx, window, split_data->SplitNode, payload_window, split_data->SplitDir, split_data->SplitRatio, split_data == &split_outer); - } - } - EndDragDropTarget(); -} - -//----------------------------------------------------------------------------- -// Docking: Settings -//----------------------------------------------------------------------------- -// - DockSettingsRenameNodeReferences() -// - DockSettingsRemoveNodeReferences() -// - DockSettingsFindNodeSettings() -// - DockSettingsHandler_ApplyAll() -// - DockSettingsHandler_ReadOpen() -// - DockSettingsHandler_ReadLine() -// - DockSettingsHandler_DockNodeToSettings() -// - DockSettingsHandler_WriteAll() -//----------------------------------------------------------------------------- - -static void ImGui::DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id) -{ - ImGuiContext& g = *GImGui; - IMGUI_DEBUG_LOG_DOCKING("DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id); - for (int window_n = 0; window_n < g.Windows.Size; window_n++) - { - ImGuiWindow* window = g.Windows[window_n]; - if (window->DockId == old_node_id && window->DockNode == NULL) - window->DockId = new_node_id; - } - //// FIXME-OPT: We could remove this loop by storing the index in the map - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (settings->DockId == old_node_id) - settings->DockId = new_node_id; -} - -// Remove references stored in ImGuiWindowSettings to the given ImGuiDockNodeSettings -static void ImGui::DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count) -{ - ImGuiContext& g = *GImGui; - int found = 0; - //// FIXME-OPT: We could remove this loop by storing the index in the map - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - for (int node_n = 0; node_n < node_ids_count; node_n++) - if (settings->DockId == node_ids[node_n]) - { - settings->DockId = 0; - settings->DockOrder = -1; - if (++found < node_ids_count) - break; - return; - } -} - -static ImGuiDockNodeSettings* ImGui::DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID id) -{ - // FIXME-OPT - ImGuiDockContext* dc = &ctx->DockContext; - for (int n = 0; n < dc->NodesSettings.Size; n++) - if (dc->NodesSettings[n].ID == id) - return &dc->NodesSettings[n]; - return NULL; -} - -// Clear settings data -static void ImGui::DockSettingsHandler_ClearAll(ImGuiContext* ctx, ImGuiSettingsHandler*) -{ - ImGuiDockContext* dc = &ctx->DockContext; - dc->NodesSettings.clear(); - DockContextClearNodes(ctx, 0, true); -} - -// Recreate nodes based on settings data -static void ImGui::DockSettingsHandler_ApplyAll(ImGuiContext* ctx, ImGuiSettingsHandler*) -{ - // Prune settings at boot time only - ImGuiDockContext* dc = &ctx->DockContext; - if (ctx->Windows.Size == 0) - DockContextPruneUnusedSettingsNodes(ctx); - DockContextBuildNodesFromSettings(ctx, dc->NodesSettings.Data, dc->NodesSettings.Size); - DockContextBuildAddWindowsToNodes(ctx, 0); -} - -static void* ImGui::DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name) -{ - if (strcmp(name, "Data") != 0) - return NULL; - return (void*)1; -} - -static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler*, void*, const char* line) -{ - char c = 0; - int x = 0, y = 0; - int r = 0; - - // Parsing, e.g. - // " DockNode ID=0x00000001 Pos=383,193 Size=201,322 Split=Y,0.506 " - // " DockNode ID=0x00000002 Parent=0x00000001 " - // Important: this code expect currently fields in a fixed order. - ImGuiDockNodeSettings node; - line = ImStrSkipBlank(line); - if (strncmp(line, "DockNode", 8) == 0) { line = ImStrSkipBlank(line + strlen("DockNode")); } - else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.Flags |= ImGuiDockNodeFlags_DockSpace; } - else return; - if (sscanf(line, "ID=0x%08X%n", &node.ID, &r) == 1) { line += r; } else return; - if (sscanf(line, " Parent=0x%08X%n", &node.ParentNodeId, &r) == 1) { line += r; if (node.ParentNodeId == 0) return; } - if (sscanf(line, " Window=0x%08X%n", &node.ParentWindowId, &r) ==1) { line += r; if (node.ParentWindowId == 0) return; } - if (node.ParentNodeId == 0) - { - if (sscanf(line, " Pos=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Pos = ImVec2ih((short)x, (short)y); } else return; - if (sscanf(line, " Size=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Size = ImVec2ih((short)x, (short)y); } else return; - } - else - { - if (sscanf(line, " SizeRef=%i,%i%n", &x, &y, &r) == 2) { line += r; node.SizeRef = ImVec2ih((short)x, (short)y); } - } - if (sscanf(line, " Split=%c%n", &c, &r) == 1) { line += r; if (c == 'X') node.SplitAxis = ImGuiAxis_X; else if (c == 'Y') node.SplitAxis = ImGuiAxis_Y; } - if (sscanf(line, " NoResize=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoResize; } - if (sscanf(line, " CentralNode=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_CentralNode; } - if (sscanf(line, " NoTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoTabBar; } - if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_HiddenTabBar; } - if (sscanf(line, " NoWindowMenuButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoWindowMenuButton; } - if (sscanf(line, " NoCloseButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoCloseButton; } - if (sscanf(line, " Selected=0x%08X%n", &node.SelectedTabId,&r) == 1) { line += r; } - if (node.ParentNodeId != 0) - if (ImGuiDockNodeSettings* parent_settings = DockSettingsFindNodeSettings(ctx, node.ParentNodeId)) - node.Depth = parent_settings->Depth + 1; - ctx->DockContext.NodesSettings.push_back(node); -} - -static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDockNode* node, int depth) -{ - ImGuiDockNodeSettings node_settings; - IM_ASSERT(depth < (1 << (sizeof(node_settings.Depth) << 3))); - node_settings.ID = node->ID; - node_settings.ParentNodeId = node->ParentNode ? node->ParentNode->ID : 0; - node_settings.ParentWindowId = (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) ? node->HostWindow->ParentWindow->ID : 0; - node_settings.SelectedTabId = node->SelectedTabId; - node_settings.SplitAxis = (signed char)(node->IsSplitNode() ? node->SplitAxis : ImGuiAxis_None); - node_settings.Depth = (char)depth; - node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_); - node_settings.Pos = ImVec2ih(node->Pos); - node_settings.Size = ImVec2ih(node->Size); - node_settings.SizeRef = ImVec2ih(node->SizeRef); - dc->NodesSettings.push_back(node_settings); - if (node->ChildNodes[0]) - DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[0], depth + 1); - if (node->ChildNodes[1]) - DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[1], depth + 1); -} - -static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf) -{ - ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; - if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) - return; - - // Gather settings data - // (unlike our windows settings, because nodes are always built we can do a full rewrite of the SettingsNode buffer) - dc->NodesSettings.resize(0); - dc->NodesSettings.reserve(dc->Nodes.Data.Size); - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (node->IsRootNode()) - DockSettingsHandler_DockNodeToSettings(dc, node, 0); - - int max_depth = 0; - for (int node_n = 0; node_n < dc->NodesSettings.Size; node_n++) - max_depth = ImMax((int)dc->NodesSettings[node_n].Depth, max_depth); - - // Write to text buffer - buf->appendf("[%s][Data]\n", handler->TypeName); - for (int node_n = 0; node_n < dc->NodesSettings.Size; node_n++) - { - const int line_start_pos = buf->size(); (void)line_start_pos; - const ImGuiDockNodeSettings* node_settings = &dc->NodesSettings[node_n]; - buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", (node_settings->Flags & ImGuiDockNodeFlags_DockSpace) ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file - buf->appendf(" ID=0x%08X", node_settings->ID); - if (node_settings->ParentNodeId) - { - buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentNodeId, node_settings->SizeRef.x, node_settings->SizeRef.y); - } - else - { - if (node_settings->ParentWindowId) - buf->appendf(" Window=0x%08X", node_settings->ParentWindowId); - buf->appendf(" Pos=%d,%d Size=%d,%d", node_settings->Pos.x, node_settings->Pos.y, node_settings->Size.x, node_settings->Size.y); - } - if (node_settings->SplitAxis != ImGuiAxis_None) - buf->appendf(" Split=%c", (node_settings->SplitAxis == ImGuiAxis_X) ? 'X' : 'Y'); - if (node_settings->Flags & ImGuiDockNodeFlags_NoResize) - buf->appendf(" NoResize=1"); - if (node_settings->Flags & ImGuiDockNodeFlags_CentralNode) - buf->appendf(" CentralNode=1"); - if (node_settings->Flags & ImGuiDockNodeFlags_NoTabBar) - buf->appendf(" NoTabBar=1"); - if (node_settings->Flags & ImGuiDockNodeFlags_HiddenTabBar) - buf->appendf(" HiddenTabBar=1"); - if (node_settings->Flags & ImGuiDockNodeFlags_NoWindowMenuButton) - buf->appendf(" NoWindowMenuButton=1"); - if (node_settings->Flags & ImGuiDockNodeFlags_NoCloseButton) - buf->appendf(" NoCloseButton=1"); - if (node_settings->SelectedTabId) - buf->appendf(" Selected=0x%08X", node_settings->SelectedTabId); - -#if IMGUI_DEBUG_INI_SETTINGS - // [DEBUG] Include comments in the .ini file to ease debugging - if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_settings->ID)) - { - buf->appendf("%*s", ImMax(2, (line_start_pos + 92) - buf->size()), ""); // Align everything - if (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) - buf->appendf(" ; in '%s'", node->HostWindow->ParentWindow->Name); - // Iterate settings so we can give info about windows that didn't exist during the session. - int contains_window = 0; - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (settings->DockId == node_settings->ID) - { - if (contains_window++ == 0) - buf->appendf(" ; contains "); - buf->appendf("'%s' ", settings->GetName()); - } - } -#endif - buf->appendf("\n"); - } - buf->appendf("\n"); -} +// (this section is filled in the 'docking' branch) //----------------------------------------------------------------------------- @@ -16187,6 +10888,36 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) #endif +// Win32 API IME support (for Asian languages, etc.) +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) + +#include +#ifdef _MSC_VER +#pragma comment(lib, "imm32") +#endif + +static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y) +{ + // Notify OS Input Method Editor of text input position + ImGuiIO& io = ImGui::GetIO(); + if (HWND hwnd = (HWND)io.ImeWindowHandle) + if (HIMC himc = ::ImmGetContext(hwnd)) + { + COMPOSITIONFORM cf; + cf.ptCurrentPos.x = x; + cf.ptCurrentPos.y = y; + cf.dwStyle = CFS_FORCE_POSITION; + ::ImmSetCompositionWindow(himc, &cf); + ::ImmReleaseContext(hwnd, himc); + } +} + +#else + +static void ImeSetInputScreenPosFn_DefaultImpl(int, int) {} + +#endif + //----------------------------------------------------------------------------- // [SECTION] METRICS/DEBUGGER WINDOW //----------------------------------------------------------------------------- @@ -16195,7 +10926,6 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) // - MetricsHelpMarker() [Internal] // - ShowMetricsWindow() // - DebugNodeColumns() [Internal] -// - DebugNodeDockNode() [Internal] // - DebugNodeDrawList() [Internal] // - DebugNodeDrawCmdShowMeshAndBoundingBox() [Internal] // - DebugNodeStorage() [Internal] @@ -16215,15 +10945,13 @@ void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* ImVec2 scale = bb.GetSize() / viewport->Size; ImVec2 off = bb.Min - viewport->Pos * scale; - float alpha_mul = (viewport->Flags & ImGuiViewportFlags_Minimized) ? 0.30f : 1.00f; - window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_Border, alpha_mul * 0.40f)); + float alpha_mul = 1.0f; + window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Border, alpha_mul * 0.40f)); for (int i = 0; i != g.Windows.Size; i++) { ImGuiWindow* thumb_window = g.Windows[i]; if (!thumb_window->WasActive || (thumb_window->Flags & ImGuiWindowFlags_ChildWindow)) continue; - if (thumb_window->Viewport != viewport) - continue; ImRect thumb_r = thumb_window->Rect(); ImRect title_r = thumb_window->TitleBarRect(); @@ -16261,13 +10989,6 @@ static void RenderViewportsThumbnails() ImGui::Dummy(bb_full.GetSize() * SCALE); } -static int IMGUI_CDECL ViewportComparerByFrontMostStampCount(const void* lhs, const void* rhs) -{ - const ImGuiViewportP* a = *(const ImGuiViewportP* const *)lhs; - const ImGuiViewportP* b = *(const ImGuiViewportP* const *)rhs; - return b->LastFrontMostStampCount - a->LastFrontMostStampCount; -} - // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. static void MetricsHelpMarker(const char* desc) { @@ -16443,15 +11164,9 @@ void ImGui::ShowMetricsWindow(bool* p_open) for (int viewport_i = 0; viewport_i < g.Viewports.Size; viewport_i++) { ImGuiViewportP* viewport = g.Viewports[viewport_i]; - bool viewport_has_drawlist = false; for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++) for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++) - { - if (!viewport_has_drawlist) - Text("Active DrawLists in Viewport #%d, ID: 0x%08X", viewport->Idx, viewport->ID); - viewport_has_drawlist = true; - DebugNodeDrawList(NULL, viewport, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList"); - } + DebugNodeDrawList(NULL, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList"); } TreePop(); } @@ -16462,35 +11177,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) Indent(GetTreeNodeToLabelSpacing()); RenderViewportsThumbnails(); Unindent(GetTreeNodeToLabelSpacing()); - - bool open = TreeNode("Monitors", "Monitors (%d)", g.PlatformIO.Monitors.Size); - SameLine(); - MetricsHelpMarker("Dear ImGui uses monitor data:\n- to query DPI settings on a per monitor basis\n- to position popup/tooltips so they don't straddle monitors."); - if (open) - { - for (int i = 0; i < g.PlatformIO.Monitors.Size; i++) - { - const ImGuiPlatformMonitor& mon = g.PlatformIO.Monitors[i]; - BulletText("Monitor #%d: DPI %.0f%%\n MainMin (%.0f,%.0f), MainMax (%.0f,%.0f), MainSize (%.0f,%.0f)\n WorkMin (%.0f,%.0f), WorkMax (%.0f,%.0f), WorkSize (%.0f,%.0f)", - i, mon.DpiScale * 100.0f, - mon.MainPos.x, mon.MainPos.y, mon.MainPos.x + mon.MainSize.x, mon.MainPos.y + mon.MainSize.y, mon.MainSize.x, mon.MainSize.y, - mon.WorkPos.x, mon.WorkPos.y, mon.WorkPos.x + mon.WorkSize.x, mon.WorkPos.y + mon.WorkSize.y, mon.WorkSize.x, mon.WorkSize.y); - } - TreePop(); - } - - if (TreeNode("Inferred order (front-to-back)")) - { - static ImVector viewports; - viewports.resize(g.Viewports.Size); - memcpy(viewports.Data, g.Viewports.Data, g.Viewports.size_in_bytes()); - if (viewports.Size > 1) - ImQsort(viewports.Data, viewports.Size, sizeof(ImGuiViewport*), ViewportComparerByFrontMostStampCount); - for (int i = 0; i < viewports.Size; i++) - BulletText("Viewport #%d, ID: 0x%08X, FrontMostStampCount = %08d, Window: \"%s\"", viewports[i]->Idx, viewports[i]->ID, viewports[i]->LastFrontMostStampCount, viewports[i]->Window ? viewports[i]->Window->Name : "N/A"); - TreePop(); - } - for (int i = 0; i < g.Viewports.Size; i++) DebugNodeViewport(g.Viewports[i]); TreePop(); @@ -16543,17 +11229,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) #ifdef IMGUI_HAS_DOCK if (TreeNode("Docking")) { - static bool root_nodes_only = true; - ImGuiDockContext* dc = &g.DockContext; - Checkbox("List root nodes", &root_nodes_only); - Checkbox("Ctrl shows window dock info", &cfg->ShowDockingNodes); - if (SmallButton("Clear nodes")) { DockContextClearNodes(&g, 0, true); } - SameLine(); - if (SmallButton("Rebuild all")) { dc->WantFullRebuild = true; } - for (int n = 0; n < dc->Nodes.Data.Size; n++) - if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (!root_nodes_only || node->IsRootNode()) - DebugNodeDockNode(node, "Node"); TreePop(); } #endif // #ifdef IMGUI_HAS_DOCK @@ -16596,29 +11271,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) } #ifdef IMGUI_HAS_DOCK - if (TreeNode("SettingsDocking", "Settings packed data: Docking")) - { - ImGuiDockContext* dc = &g.DockContext; - Text("In SettingsWindows:"); - for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (settings->DockId != 0) - BulletText("Window '%s' -> DockId %08X", settings->GetName(), settings->DockId); - Text("In SettingsNodes:"); - for (int n = 0; n < dc->NodesSettings.Size; n++) - { - ImGuiDockNodeSettings* settings = &dc->NodesSettings[n]; - const char* selected_tab_name = NULL; - if (settings->SelectedTabId) - { - if (ImGuiWindow* window = FindWindowByID(settings->SelectedTabId)) - selected_tab_name = window->Name; - else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedTabId)) - selected_tab_name = window_settings->GetName(); - } - BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeId, settings->SelectedTabId, selected_tab_name ? selected_tab_name : settings->SelectedTabId ? "N/A" : ""); - } - TreePop(); - } #endif // #ifdef IMGUI_HAS_DOCK if (TreeNode("SettingsIniData", "Settings unpacked data (.ini): %d bytes", g.SettingsIniData.size())) @@ -16637,11 +11289,9 @@ void ImGui::ShowMetricsWindow(bool* p_open) Text("WINDOWING"); Indent(); Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL"); - Text("HoveredWindow->Root: '%s'", g.HoveredWindow ? g.HoveredWindow->RootWindowDockTree->Name : "NULL"); + Text("HoveredWindow->Root: '%s'", g.HoveredWindow ? g.HoveredWindow->RootWindow->Name : "NULL"); Text("HoveredWindowUnderMovingWindow: '%s'", g.HoveredWindowUnderMovingWindow ? g.HoveredWindowUnderMovingWindow->Name : "NULL"); - Text("HoveredDockNode: 0x%08X", g.HoveredDockNode ? g.HoveredDockNode->ID : 0); Text("MovingWindow: '%s'", g.MovingWindow ? g.MovingWindow->Name : "NULL"); - Text("MouseViewport: 0x%08X (UserHovered 0x%08X, LastHovered 0x%08X)", g.MouseViewport->ID, g.IO.MouseHoveredViewport, g.MouseLastHoveredViewport ? g.MouseLastHoveredViewport->ID : 0); Unindent(); Text("ITEMS"); @@ -16722,21 +11372,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) #ifdef IMGUI_HAS_DOCK // Overlay: Display Docking info - if (cfg->ShowDockingNodes && g.IO.KeyCtrl && g.HoveredDockNode) + if (show_docking_nodes && g.IO.KeyCtrl) { - char buf[64] = ""; - char* p = buf; - ImGuiDockNode* node = g.HoveredDockNode; - ImDrawList* overlay_draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList(GetMainViewport()); - p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "DockId: %X%s\n", node->ID, node->IsCentralNode() ? " *CentralNode*" : ""); - p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "WindowClass: %08X\n", node->WindowClass.ClassId); - p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "Size: (%.0f, %.0f)\n", node->Size.x, node->Size.y); - p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "SizeRef: (%.0f, %.0f)\n", node->SizeRef.x, node->SizeRef.y); - int depth = DockNodeGetDepth(node); - overlay_draw_list->AddRect(node->Pos + ImVec2(3, 3) * (float)depth, node->Pos + node->Size - ImVec2(3, 3) * (float)depth, IM_COL32(200, 100, 100, 255)); - ImVec2 pos = node->Pos + ImVec2(3, 3) * (float)depth; - overlay_draw_list->AddRectFilled(pos - ImVec2(1, 1), pos + CalcTextSize(buf) + ImVec2(1, 1), IM_COL32(200, 100, 100, 255)); - overlay_draw_list->AddText(NULL, 0.0f, pos, IM_COL32(255, 255, 255, 255), buf); } #endif // #ifdef IMGUI_HAS_DOCK @@ -16773,91 +11410,8 @@ void ImGui::DebugNodeColumns(ImGuiOldColumns* columns) TreePop(); } -static void DebugNodeDockNodeFlags(ImGuiDockNodeFlags* p_flags, const char* label, bool enabled) -{ - using namespace ImGui; - PushID(label); - PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f)); - Text("%s:", label); - if (!enabled) - PushDisabled(); - CheckboxFlags("NoSplit", p_flags, ImGuiDockNodeFlags_NoSplit); - CheckboxFlags("NoResize", p_flags, ImGuiDockNodeFlags_NoResize); - CheckboxFlags("NoResizeX", p_flags, ImGuiDockNodeFlags_NoResizeX); - CheckboxFlags("NoResizeY",p_flags, ImGuiDockNodeFlags_NoResizeY); - CheckboxFlags("NoTabBar", p_flags, ImGuiDockNodeFlags_NoTabBar); - CheckboxFlags("HiddenTabBar", p_flags, ImGuiDockNodeFlags_HiddenTabBar); - CheckboxFlags("NoWindowMenuButton", p_flags, ImGuiDockNodeFlags_NoWindowMenuButton); - CheckboxFlags("NoCloseButton", p_flags, ImGuiDockNodeFlags_NoCloseButton); - CheckboxFlags("NoDocking", p_flags, ImGuiDockNodeFlags_NoDocking); - CheckboxFlags("NoDockingSplitMe", p_flags, ImGuiDockNodeFlags_NoDockingSplitMe); - CheckboxFlags("NoDockingSplitOther", p_flags, ImGuiDockNodeFlags_NoDockingSplitOther); - CheckboxFlags("NoDockingOverMe", p_flags, ImGuiDockNodeFlags_NoDockingOverMe); - CheckboxFlags("NoDockingOverOther", p_flags, ImGuiDockNodeFlags_NoDockingOverOther); - CheckboxFlags("NoDockingOverEmpty", p_flags, ImGuiDockNodeFlags_NoDockingOverEmpty); - if (!enabled) - PopDisabled(); - PopStyleVar(); - PopID(); -} - -// [DEBUG] Display contents of ImDockNode -void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) -{ - ImGuiContext& g = *GImGui; - const bool is_alive = (g.FrameCount - node->LastFrameAlive < 2); // Submitted with ImGuiDockNodeFlags_KeepAliveOnly - const bool is_active = (g.FrameCount - node->LastFrameActive < 2); // Submitted - if (!is_alive) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } - bool open; - if (node->Windows.Size > 0) - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); - else - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); - if (!is_alive) { PopStyleColor(); } - if (is_active && IsItemHovered()) - if (ImGuiWindow* window = node->HostWindow ? node->HostWindow : node->VisibleWindow) - GetForegroundDrawList(window)->AddRect(node->Pos, node->Pos + node->Size, IM_COL32(255, 255, 0, 255)); - if (open) - { - IM_ASSERT(node->ChildNodes[0] == NULL || node->ChildNodes[0]->ParentNode == node); - IM_ASSERT(node->ChildNodes[1] == NULL || node->ChildNodes[1]->ParentNode == node); - BulletText("Pos (%.0f,%.0f), Size (%.0f, %.0f) Ref (%.0f, %.0f)", - node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y); - DebugNodeWindow(node->HostWindow, "HostWindow"); - DebugNodeWindow(node->VisibleWindow, "VisibleWindow"); - BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabId, node->LastFocusedNodeId); - BulletText("Misc:%s%s%s%s%s", - node->IsDockSpace() ? " IsDockSpace" : "", - node->IsCentralNode() ? " IsCentralNode" : "", - is_alive ? " IsAlive" : "", is_active ? " IsActive" : "", - node->WantLockSizeOnce ? " WantLockSizeOnce" : ""); - if (TreeNode("flags", "Flags Merged: 0x%04X, Local: 0x%04X, InWindows: 0x%04X, Shared: 0x%04X", node->MergedFlags, node->LocalFlags, node->LocalFlagsInWindows, node->SharedFlags)) - { - if (BeginTable("flags", 4)) - { - TableNextColumn(); DebugNodeDockNodeFlags(&node->MergedFlags, "MergedFlags", false); - TableNextColumn(); DebugNodeDockNodeFlags(&node->LocalFlags, "LocalFlags", true); - TableNextColumn(); DebugNodeDockNodeFlags(&node->LocalFlagsInWindows, "LocalFlagsInWindows", false); - TableNextColumn(); DebugNodeDockNodeFlags(&node->SharedFlags, "SharedFlags", true); - EndTable(); - } - TreePop(); - } - if (node->ParentNode) - DebugNodeDockNode(node->ParentNode, "ParentNode"); - if (node->ChildNodes[0]) - DebugNodeDockNode(node->ChildNodes[0], "Child[0]"); - if (node->ChildNodes[1]) - DebugNodeDockNode(node->ChildNodes[1], "Child[1]"); - if (node->TabBar) - DebugNodeTabBar(node->TabBar, "TabBar"); - TreePop(); - } -} - // [DEBUG] Display contents of ImDrawList -// Note that both 'window' and 'viewport' may be NULL here. Viewport is generally null of destroyed popups which previously owned a viewport. -void ImGui::DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, const ImDrawList* draw_list, const char* label) +void ImGui::DebugNodeDrawList(ImGuiWindow* window, const ImDrawList* draw_list, const char* label) { ImGuiContext& g = *GImGui; ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig; @@ -16874,8 +11428,8 @@ void ImGui::DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, con return; } - ImDrawList* fg_draw_list = viewport ? GetForegroundDrawList(viewport) : NULL; // Render additional visuals into the top-most draw list - if (window && fg_draw_list && IsItemHovered()) + ImDrawList* fg_draw_list = GetForegroundDrawList(window); // Render additional visuals into the top-most draw list + if (window && IsItemHovered()) fg_draw_list->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255)); if (!node_open) return; @@ -17103,7 +11657,7 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; p += ImFormatString(p, buf_end - p, "%s'%s'", - tab_n > 0 ? ", " : "", (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???"); + tab_n > 0 ? ", " : "", (tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???"); } p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } "); if (!is_active) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } @@ -17125,7 +11679,7 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label) if (SmallButton("<")) { TabBarQueueReorder(tab_bar, tab, -1); } SameLine(0, 2); if (SmallButton(">")) { TabBarQueueReorder(tab_bar, tab, +1); } SameLine(); Text("%02d%c Tab 0x%08X '%s' Offset: %.1f, Width: %.1f/%.1f", - tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->Window || tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???", tab->Offset, tab->Width, tab->ContentWidth); + tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : "???", tab->Offset, tab->Width, tab->ContentWidth); PopID(); } TreePop(); @@ -17135,31 +11689,19 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label) void ImGui::DebugNodeViewport(ImGuiViewportP* viewport) { SetNextItemOpen(true, ImGuiCond_Once); - if (TreeNode((void*)(intptr_t)viewport->ID, "Viewport #%d, ID: 0x%08X, Parent: 0x%08X, Window: \"%s\"", viewport->Idx, viewport->ID, viewport->ParentViewportId, viewport->Window ? viewport->Window->Name : "N/A")) + if (TreeNode("viewport0", "Viewport #%d", 0)) { ImGuiWindowFlags flags = viewport->Flags; - BulletText("Main Pos: (%.0f,%.0f), Size: (%.0f,%.0f)\nWorkArea Offset Left: %.0f Top: %.0f, Right: %.0f, Bottom: %.0f\nMonitor: %d, DpiScale: %.0f%%", + BulletText("Main Pos: (%.0f,%.0f), Size: (%.0f,%.0f)\nWorkArea Offset Left: %.0f Top: %.0f, Right: %.0f, Bottom: %.0f", viewport->Pos.x, viewport->Pos.y, viewport->Size.x, viewport->Size.y, - viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y, - viewport->PlatformMonitor, viewport->DpiScale * 100.0f); - if (viewport->Idx > 0) { SameLine(); if (SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200, 200); viewport->UpdateWorkRect(); if (viewport->Window) viewport->Window->Pos = viewport->Pos; } } - BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s%s%s", viewport->Flags, - //(flags & ImGuiViewportFlags_IsPlatformWindow) ? " IsPlatformWindow" : "", // Omitting because it is the standard + viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y); + BulletText("Flags: 0x%04X =%s%s%s", viewport->Flags, + (flags & ImGuiViewportFlags_IsPlatformWindow) ? " IsPlatformWindow" : "", (flags & ImGuiViewportFlags_IsPlatformMonitor) ? " IsPlatformMonitor" : "", - (flags & ImGuiViewportFlags_OwnedByApp) ? " OwnedByApp" : "", - (flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "", - (flags & ImGuiViewportFlags_NoTaskBarIcon) ? " NoTaskBarIcon" : "", - (flags & ImGuiViewportFlags_NoFocusOnAppearing) ? " NoFocusOnAppearing" : "", - (flags & ImGuiViewportFlags_NoFocusOnClick) ? " NoFocusOnClick" : "", - (flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "", - (flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "", - (flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "", - (flags & ImGuiViewportFlags_Minimized) ? " Minimized" : "", - (flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "", - (flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : ""); + (flags & ImGuiViewportFlags_OwnedByApp) ? " OwnedByApp" : ""); for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++) for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++) - DebugNodeDrawList(NULL, viewport, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList"); + DebugNodeDrawList(NULL, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList"); TreePop(); } } @@ -17187,13 +11729,12 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label) TextDisabled("Note: some memory buffers have been compacted/freed."); ImGuiWindowFlags flags = window->Flags; - DebugNodeDrawList(window, window->Viewport, window->DrawList, "DrawList"); + DebugNodeDrawList(window, window->DrawList, "DrawList"); BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f) Ideal (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y, window->ContentSizeIdeal.x, window->ContentSizeIdeal.y); BulletText("Flags: 0x%08X (%s%s%s%s%s%s%s%s%s..)", flags, (flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "", (flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "", (flags & ImGuiWindowFlags_NoMouseInputs)? "NoMouseInputs":"", (flags & ImGuiWindowFlags_NoNavInputs) ? "NoNavInputs" : "", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : ""); - BulletText("WindowClassId: 0x%08X", window->WindowClass.ClassId); BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f) Scrollbar:%s%s", window->Scroll.x, window->ScrollMax.x, window->Scroll.y, window->ScrollMax.y, window->ScrollbarX ? "X" : "", window->ScrollbarY ? "Y" : ""); BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1); BulletText("Appearing: %d, Hidden: %d (CanSkip %d Cannot %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesCanSkipItems, window->HiddenFramesCannotSkipItems, window->SkipItems); @@ -17210,15 +11751,7 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label) GetForegroundDrawList(window)->AddRect(r.Min + window->Pos, r.Max + window->Pos, IM_COL32(255, 255, 0, 255)); } BulletText("NavLayersActiveMask: %X, NavLastChildNavWindow: %s", window->DC.NavLayersActiveMask, window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL"); - - BulletText("Viewport: %d%s, ViewportId: 0x%08X, ViewportPos: (%.1f,%.1f)", window->Viewport ? window->Viewport->Idx : -1, window->ViewportOwned ? " (Owned)" : "", window->ViewportId, window->ViewportPos.x, window->ViewportPos.y); - BulletText("ViewportMonitor: %d", window->Viewport ? window->Viewport->PlatformMonitor : -1); - BulletText("DockId: 0x%04X, DockOrder: %d, Act: %d, Vis: %d", window->DockId, window->DockOrder, window->DockIsActive, window->DockTabIsVisible); - if (window->DockNode || window->DockNodeAsHost) - DebugNodeDockNode(window->DockNodeAsHost ? window->DockNodeAsHost : window->DockNode, window->DockNodeAsHost ? "DockNodeAsHost" : "DockNode"); - if (window->RootWindow != window) { DebugNodeWindow(window->RootWindow, "RootWindow"); } - if (window->RootWindowDockTree != window->RootWindow) { DebugNodeWindow(window->RootWindowDockTree, "RootWindowDockTree"); } if (window->ParentWindow != NULL) { DebugNodeWindow(window->ParentWindow, "ParentWindow"); } if (window->DC.ChildWindows.Size > 0) { DebugNodeWindowsList(&window->DC.ChildWindows, "ChildWindows"); } if (window->ColumnsStorage.Size > 0 && TreeNode("Columns", "Columns sets (%d)", window->ColumnsStorage.Size)) @@ -17256,7 +11789,7 @@ void ImGui::DebugNodeWindowsList(ImVector* windows, const char* la void ImGui::ShowMetricsWindow(bool*) {} void ImGui::ShowFontAtlas(ImFontAtlas*) {} void ImGui::DebugNodeColumns(ImGuiOldColumns*) {} -void ImGui::DebugNodeDrawList(ImGuiWindow*, ImGuiViewportP*, const ImDrawList*, const char*) {} +void ImGui::DebugNodeDrawList(ImGuiWindow*, const ImDrawList*, const char*) {} void ImGui::DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList*, const ImDrawList*, const ImDrawCmd*, bool, bool) {} void ImGui::DebugNodeFont(ImFont*) {} void ImGui::DebugNodeStorage(ImGuiStorage*, const char*) {} diff --git a/3rdparty/dear-imgui/imgui.h b/3rdparty/dear-imgui/imgui.h index 4d9e8ddac..ff91abde5 100644 --- a/3rdparty/dear-imgui/imgui.h +++ b/3rdparty/dear-imgui/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (headers) // Help: @@ -11,7 +11,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/3793 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/4451 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -27,12 +27,11 @@ Index of this file: // [SECTION] Helpers: Memory allocations macros, ImVector<> // [SECTION] ImGuiStyle // [SECTION] ImGuiIO -// [SECTION] Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiWindowClass, ImGuiPayload, ImGuiTableSortSpecs, ImGuiTableColumnSortSpecs) +// [SECTION] Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiPayload, ImGuiTableSortSpecs, ImGuiTableColumnSortSpecs) // [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor) // [SECTION] Drawing API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawFlags, ImDrawListFlags, ImDrawList, ImDrawData) // [SECTION] Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont) // [SECTION] Viewports (ImGuiViewportFlags, ImGuiViewport) -// [SECTION] Platform interface for multi-viewport support (ImGuiPlatformIO, ImGuiPlatformMonitor) // [SECTION] Obsolete functions and types */ @@ -61,12 +60,10 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.84 WIP" -#define IMGUI_VERSION_NUM 18314 +#define IMGUI_VERSION "1.84" +#define IMGUI_VERSION_NUM 18400 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE -#define IMGUI_HAS_VIEWPORT // Viewport WIP branch -#define IMGUI_HAS_DOCK // Docking WIP branch // Define attributes of all API symbols declarations (e.g. for DLL under Windows) // IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default backends files (imgui_impl_xxx.h) @@ -154,8 +151,6 @@ struct ImGuiInputTextCallbackData; // Shared state of InputText() when using cu struct ImGuiListClipper; // Helper to manually clip large list of items struct ImGuiOnceUponAFrame; // Helper for running a block of code not more than once a frame, used by IMGUI_ONCE_UPON_A_FRAME macro struct ImGuiPayload; // User data payload for drag and drop operations -struct ImGuiPlatformIO; // Multi-viewport support: interface for Platform/Renderer backends + viewports to render -struct ImGuiPlatformMonitor; // Multi-viewport support: user-provided bounds for each connected monitor/display. Used when positioning popups and tooltips to avoid them straddling monitors struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSizeConstraints() (rare/advanced use) struct ImGuiStorage; // Helper for key->value storage struct ImGuiStyle; // Runtime data for styling/colors @@ -163,8 +158,7 @@ struct ImGuiTableSortSpecs; // Sorting specifications for a table (often struct ImGuiTableColumnSortSpecs; // Sorting specification for one column of a table struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder) struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbbb][,ccccc]") -struct ImGuiViewport; // A Platform Window (always 1 unless multi-viewport are enabled. One per platform window to output to). In the future may represent Platform Monitor -struct ImGuiWindowClass; // Window class (rare/advanced uses: provide hints to the platform backend via altered viewport flags and parent/child info) +struct ImGuiViewport; // A Platform Window (always only one in 'master' branch), in the future may represent Platform Monitor // Enums/Flags (declared as int for compatibility with old C++, to allow using as flags and to not pollute the top of this file) // - Tip: Use your programming IDE navigation facilities on the names in the _central column_ below to find the actual flags/enum lists! @@ -189,7 +183,6 @@ typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: f typedef int ImGuiColorEditFlags; // -> enum ImGuiColorEditFlags_ // Flags: for ColorEdit4(), ColorPicker4() etc. typedef int ImGuiConfigFlags; // -> enum ImGuiConfigFlags_ // Flags: for io.ConfigFlags typedef int ImGuiComboFlags; // -> enum ImGuiComboFlags_ // Flags: for BeginCombo() -typedef int ImGuiDockNodeFlags; // -> enum ImGuiDockNodeFlags_ // Flags: for DockSpace() typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: for BeginDragDropSource(), AcceptDragDropPayload() typedef int ImGuiFocusedFlags; // -> enum ImGuiFocusedFlags_ // Flags: for IsWindowFocused() typedef int ImGuiHoveredFlags; // -> enum ImGuiHoveredFlags_ // Flags: for IsItemHovered(), IsWindowHovered() etc. @@ -345,12 +338,10 @@ namespace ImGui IMGUI_API bool IsWindowFocused(ImGuiFocusedFlags flags=0); // is current window focused? or its root/child, depending on flags. see flags for options. IMGUI_API bool IsWindowHovered(ImGuiHoveredFlags flags=0); // is current window hovered (and typically: not blocked by a popup/modal)? see flags for options. NB: If you are trying to check whether your mouse should be dispatched to imgui or to your app, you should use the 'io.WantCaptureMouse' boolean for that! Please read the FAQ! IMGUI_API ImDrawList* GetWindowDrawList(); // get draw list associated to the current window, to append your own drawing primitives - IMGUI_API float GetWindowDpiScale(); // get DPI scale currently associated to the current window's viewport. IMGUI_API ImVec2 GetWindowPos(); // get current window position in screen space (useful if you want to do your own drawing via the DrawList API) IMGUI_API ImVec2 GetWindowSize(); // get current window size IMGUI_API float GetWindowWidth(); // get current window width (shortcut for GetWindowSize().x) IMGUI_API float GetWindowHeight(); // get current window height (shortcut for GetWindowSize().y) - IMGUI_API ImGuiViewport*GetWindowViewport(); // get viewport currently associated to the current window. // Window manipulation // - Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin). @@ -361,7 +352,6 @@ namespace ImGui IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin() IMGUI_API void SetNextWindowFocus(); // set next window to be focused / top-most. call before Begin() IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily override the Alpha component of ImGuiCol_WindowBg/ChildBg/PopupBg. you may also use ImGuiWindowFlags_NoBackground. - IMGUI_API void SetNextWindowViewport(ImGuiID viewport_id); // set next window viewport IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects. IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 0); // (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0, 0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects. IMGUI_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed(). @@ -779,7 +769,6 @@ namespace ImGui IMGUI_API int GetColumnsCount(); // Tab Bars, Tabs - // Note: Tabs are automatically created by the docking system. Use this to create tab bars/tabs yourself without docking being involved. IMGUI_API bool BeginTabBar(const char* str_id, ImGuiTabBarFlags flags = 0); // create and append into a TabBar IMGUI_API void EndTabBar(); // only call EndTabBar() if BeginTabBar() returns true! IMGUI_API bool BeginTabItem(const char* label, bool* p_open = NULL, ImGuiTabItemFlags flags = 0); // create a Tab. Returns true if the Tab is selected. @@ -787,25 +776,6 @@ namespace ImGui IMGUI_API bool TabItemButton(const char* label, ImGuiTabItemFlags flags = 0); // create a Tab behaving like a button. return true when clicked. cannot be selected in the tab bar. IMGUI_API void SetTabItemClosed(const char* tab_or_docked_window_label); // notify TabBar or Docking system of a closed tab/window ahead (useful to reduce visual flicker on reorderable tab bars). For tab-bar: call after BeginTabBar() and before Tab submissions. Otherwise call with a window name. - // Docking - // [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable. - // Note: You can use most Docking facilities without calling any API. You DO NOT need to call DockSpace() to use Docking! - // - Drag from window title bar or their tab to dock/undock. Hold SHIFT to disable docking. - // - Drag from window menu button (upper-left button) to undock an entire node (all windows). - // About dockspaces: - // - Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details. - // - Use DockSpaceOverViewport() to create an explicit dock node covering the screen or a specific viewport. - // This is often used with ImGuiDockNodeFlags_PassthruCentralNode. - // - Important: Dockspaces need to be submitted _before_ any window they can host. Submit it early in your frame! - // - Important: Dockspaces need to be kept alive if hidden, otherwise windows docked into it will be undocked. - // e.g. if you have multiple tabs with a dockspace inside each tab: submit the non-visible dockspaces with ImGuiDockNodeFlags_KeepAliveOnly. - IMGUI_API ImGuiID DockSpace(ImGuiID id, const ImVec2& size = ImVec2(0, 0), ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL); - IMGUI_API ImGuiID DockSpaceOverViewport(const ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL); - IMGUI_API void SetNextWindowDockID(ImGuiID dock_id, ImGuiCond cond = 0); // set next window dock id - IMGUI_API void SetNextWindowClass(const ImGuiWindowClass* window_class); // set next window class (control docking compatibility + provide hints to platform backend via custom viewport flags and platform parent/child relationship) - IMGUI_API ImGuiID GetWindowDockID(); - IMGUI_API bool IsWindowDocked(); // is current window docked into another window? - // Logging/Capture // - All text output from the interface can be captured into tty/file/clipboard. By default, tree nodes are automatically opened during logging. IMGUI_API void LogToTTY(int auto_open_depth = -1); // start logging to tty (stdout) @@ -829,6 +799,11 @@ namespace ImGui IMGUI_API void EndDragDropTarget(); // only call EndDragDropTarget() if BeginDragDropTarget() returns true! IMGUI_API const ImGuiPayload* GetDragDropPayload(); // peek directly into the current payload from anywhere. may return NULL. use ImGuiPayload::IsDataType() to test for the payload type. + // Disabling [BETA API] + // - Disable all user interactions and dim items visuals (applying style.DisabledAlpha over current colors) + IMGUI_API void BeginDisabled(bool disabled = true); + IMGUI_API void EndDisabled(); + // Clipping // - Mouse hovering is affected by ImGui::PushClipRect() calls, unlike direct calls to ImDrawList::PushClipRect() which are render only. IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect); @@ -871,10 +846,8 @@ namespace ImGui IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side. IMGUI_API double GetTime(); // get global imgui time. incremented by io.DeltaTime every frame. IMGUI_API int GetFrameCount(); // get global imgui frame count. incremented by 1 every frame. - IMGUI_API ImDrawList* GetBackgroundDrawList(); // get background draw list for the viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. - IMGUI_API ImDrawList* GetForegroundDrawList(); // get foreground draw list for the viewport associated to the current window. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. - IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. - IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. + IMGUI_API ImDrawList* GetBackgroundDrawList(); // this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. + IMGUI_API ImDrawList* GetForegroundDrawList(); // this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances. IMGUI_API const char* GetStyleColorName(ImGuiCol idx); // get a string corresponding to the enum value (for display, saving, etc.). IMGUI_API void SetStateStorage(ImGuiStorage* storage); // replace current window storage with our own (if you want to manipulate it yourself, typically clear subsection of it) @@ -949,16 +922,6 @@ namespace ImGui IMGUI_API void* MemAlloc(size_t size); IMGUI_API void MemFree(void* ptr); - // (Optional) Platform/OS interface for multi-viewport support - // Read comments around the ImGuiPlatformIO structure for more details. - // Note: You may use GetWindowViewport() to get the current viewport of the current window. - IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for backend to setup + viewports list. - IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport. - IMGUI_API void RenderPlatformWindowsDefault(void* platform_render_arg = NULL, void* renderer_render_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs. - IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from backend Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext(). - IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // this is a helper for backends. - IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // this is a helper for backends. the type platform_handle is decided by the backend (e.g. HWND, MyWindow*, GLFWwindow* etc.) - } // namespace ImGui //----------------------------------------------------------------------------- @@ -974,7 +937,7 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programmatically) ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set. - ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it. Also referred to as "window menu button" within a docking node. + ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame ImGuiWindowFlags_NoBackground = 1 << 7, // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f). ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file @@ -989,8 +952,6 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_NoNavInputs = 1 << 18, // No gamepad/keyboard navigation within the window ImGuiWindowFlags_NoNavFocus = 1 << 19, // No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB) ImGuiWindowFlags_UnsavedDocument = 1 << 20, // Display a dot next to the title. When used in a tab/docking context, tab is selected when clicking the X + closure is not assumed (will wait for user to stop submitting the tab). Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar. - ImGuiWindowFlags_NoDocking = 1 << 21, // Disable docking of this window - ImGuiWindowFlags_NoNav = ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus, ImGuiWindowFlags_NoDecoration = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse, ImGuiWindowFlags_NoInputs = ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoNavFocus, @@ -1001,8 +962,7 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip() ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup() ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal() - ImGuiWindowFlags_ChildMenu = 1 << 28, // Don't use! For internal use by BeginMenu() - ImGuiWindowFlags_DockNodeHost = 1 << 29 // Don't use! For internal use by Begin()/NewFrame() + ImGuiWindowFlags_ChildMenu = 1 << 28 // Don't use! For internal use by BeginMenu() // [Obsolete] //ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // --> Set io.ConfigWindowsResizeFromEdges=true and make sure mouse cursors are supported by backend (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) @@ -1312,21 +1272,6 @@ enum ImGuiHoveredFlags_ ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows }; -// Flags for ImGui::DockSpace(), shared/inherited by child nodes. -// (Some flags can be applied to individual nodes directly) -// FIXME-DOCK: Also see ImGuiDockNodeFlagsPrivate_ which may involve using the WIP and internal DockBuilder api. -enum ImGuiDockNodeFlags_ -{ - ImGuiDockNodeFlags_None = 0, - ImGuiDockNodeFlags_KeepAliveOnly = 1 << 0, // Shared // Don't display the dockspace node but keep it alive. Windows docked into this dockspace node won't be undocked. - //ImGuiDockNodeFlags_NoCentralNode = 1 << 1, // Shared // Disable Central Node (the node which can stay empty) - ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 2, // Shared // Disable docking inside the Central Node, which will be always kept empty. - ImGuiDockNodeFlags_PassthruCentralNode = 1 << 3, // Shared // Enable passthru dockspace: 1) DockSpace() will render a ImGuiCol_WindowBg background covering everything excepted the Central Node when empty. Meaning the host window should probably use SetNextWindowBgAlpha(0.0f) prior to Begin() when using this. 2) When Central Node is empty: let inputs pass-through + won't display a DockingEmptyBg background. See demo for details. - ImGuiDockNodeFlags_NoSplit = 1 << 4, // Shared/Local // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion). Note: when turned off, existing splits will be preserved. - ImGuiDockNodeFlags_NoResize = 1 << 5, // Shared/Local // Disable resizing node using the splitter/separators. Useful with programatically setup dockspaces. - ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6 // Shared/Local // Tab bar will automatically hide when there is a single window in the dock node. -}; - // Flags for ImGui::BeginDragDropSource(), ImGui::AcceptDragDropPayload() enum ImGuiDragDropFlags_ { @@ -1467,15 +1412,6 @@ enum ImGuiConfigFlags_ ImGuiConfigFlags_NoMouse = 1 << 4, // Instruct imgui to clear mouse position/buttons in NewFrame(). This allows ignoring the mouse information set by the backend. ImGuiConfigFlags_NoMouseCursorChange = 1 << 5, // Instruct backend to not alter mouse cursor shape and visibility. Use if the backend cursor changes are interfering with yours and you don't want to use SetMouseCursor() to change mouse cursor. You may want to honor requests from imgui by reading GetMouseCursor() yourself instead. - // [BETA] Docking - ImGuiConfigFlags_DockingEnable = 1 << 6, // Docking enable flags. - - // [BETA] Viewports - // When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable. - ImGuiConfigFlags_ViewportsEnable = 1 << 10, // Viewport enable flags (require both ImGuiBackendFlags_PlatformHasViewports + ImGuiBackendFlags_RendererHasViewports set by the respective backends) - ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] 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, // [BETA: Don't use] 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 backend/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core Dear ImGui) ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware. ImGuiConfigFlags_IsTouchScreen = 1 << 21 // Application is using a touch screen instead of a mouse. @@ -1488,12 +1424,7 @@ enum ImGuiBackendFlags_ ImGuiBackendFlags_HasGamepad = 1 << 0, // Backend Platform supports gamepad and currently has one connected. ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Backend Platform supports honoring GetMouseCursor() value to change the OS cursor shape. ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Backend Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set). - ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3, // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices. - - // [BETA] Viewports - ImGuiBackendFlags_PlatformHasViewports = 1 << 10, // Backend Platform supports multiple viewports. - ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, // Backend Platform supports setting io.MouseHoveredViewport to the viewport directly under the mouse _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag and _REGARDLESS_ of whether another viewport is focused and may be capturing the mouse. This information is _NOT EASY_ to provide correctly with most high-level engines! Don't set this without studying _carefully_ how the backends handle ImGuiViewportFlags_NoInputs! - ImGuiBackendFlags_RendererHasViewports = 1 << 12 // Backend Renderer supports multiple viewports. + ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3 // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices. }; // Enumeration for PushStyleColor() / PopStyleColor() @@ -1537,8 +1468,6 @@ enum ImGuiCol_ ImGuiCol_TabActive, ImGuiCol_TabUnfocused, ImGuiCol_TabUnfocusedActive, - ImGuiCol_DockingPreview, // Preview overlay color when about to docking something - ImGuiCol_DockingEmptyBg, // Background color for empty node (e.g. CentralNode with no window docked into it) ImGuiCol_PlotLines, ImGuiCol_PlotLinesHovered, ImGuiCol_PlotHistogram, @@ -1568,6 +1497,7 @@ enum ImGuiStyleVar_ { // Enum name --------------------- // Member in ImGuiStyle structure (see ImGuiStyle for descriptions) ImGuiStyleVar_Alpha, // float Alpha + ImGuiStyleVar_DisabledAlpha, // float DisabledAlpha ImGuiStyleVar_WindowPadding, // ImVec2 WindowPadding ImGuiStyleVar_WindowRounding, // float WindowRounding ImGuiStyleVar_WindowBorderSize, // float WindowBorderSize @@ -1814,6 +1744,7 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE struct ImGuiStyle { float Alpha; // Global alpha applies to everything in Dear ImGui. + float DisabledAlpha; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha. ImVec2 WindowPadding; // Padding within a window. float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows. Large values tend to lead to variety of artifacts and are not recommended. float WindowBorderSize; // Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). @@ -1846,7 +1777,7 @@ struct ImGuiStyle ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line. ImVec2 DisplayWindowPadding; // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows. ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! - float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). We apply per-monitor DPI scaling over this scale. May be removed later. + float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. bool AntiAliasedLines; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList). bool AntiAliasedLinesUseTex; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering. Latched at the beginning of the frame (copied to ImDrawList). bool AntiAliasedFill; // Enable anti-aliased edges around filled shapes (rounded rectangles, circles, etc.). Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList). @@ -1892,17 +1823,6 @@ struct ImGuiIO ImFont* FontDefault; // = NULL // Font to use on NewFrame(). Use NULL to uses Fonts->Fonts[0]. ImVec2 DisplayFramebufferScale; // = (1, 1) // For retina display or other situations where window coordinates are different from framebuffer coordinates. This generally ends up in ImDrawData::FramebufferScale. - // Docking options (when ImGuiConfigFlags_DockingEnable is set) - bool ConfigDockingNoSplit; // = false // Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars. - bool ConfigDockingAlwaysTabBar; // = false // [BETA] [FIXME: This currently creates regression with auto-sizing and general overhead] Make every single floating window display within a docking node. - bool ConfigDockingTransparentPayload;// = false // [BETA] Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge. - - // Viewport options (when ImGuiConfigFlags_ViewportsEnable is set) - bool ConfigViewportsNoAutoMerge; // = false; // Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it. May also set ImGuiViewportFlags_NoAutoMerge on individual viewport. - bool ConfigViewportsNoTaskBarIcon; // = false // Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it. - bool ConfigViewportsNoDecoration; // = true // Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations, ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size). - bool ConfigViewportsNoDefaultParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = , expecting the platform backend to setup a parent/child relationship between the OS windows (some backend may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows. - // Miscellaneous options bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by backend implementations. bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl. @@ -1930,6 +1850,11 @@ struct ImGuiIO void (*SetClipboardTextFn)(void* user_data, const char* text); void* ClipboardUserData; + // Optional: Notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME on Windows) + // (default to use native imm32 api on Windows) + void (*ImeSetInputScreenPosFn)(int x, int y); + void* ImeWindowHandle; // = NULL // (Windows) Set this to your HWND to get automatic IME cursor positioning. + //------------------------------------------------------------------ // Input - Fill before calling NewFrame() //------------------------------------------------------------------ @@ -1938,7 +1863,6 @@ struct ImGuiIO bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. float MouseWheelH; // Mouse wheel Horizontal. Most users don't have a mouse with an horizontal wheel, may not be filled by all backends. - ImGuiID MouseHoveredViewport; // (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag, and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info. If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows). bool KeyCtrl; // Keyboard modifier pressed: Control bool KeyShift; // Keyboard modifier pressed: Shift bool KeyAlt; // Keyboard modifier pressed: Alt @@ -1950,9 +1874,8 @@ struct ImGuiIO IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string + IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually IMGUI_API void AddFocusEvent(bool focused); // Notifies Dear ImGui when hosting platform windows lose or gain input focus - IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually - IMGUI_API void ClearInputKeys(); // [Internal] Release all keys //------------------------------------------------------------------ // Output - Updated by NewFrame() or EndFrame()/Render() @@ -1998,7 +1921,6 @@ struct ImGuiIO float NavInputsDownDuration[ImGuiNavInput_COUNT]; float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui. - bool AppFocusLost; ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16 ImVector InputQueueCharacters; // Queue of _characters_ input (obtained by platform backend). Fill using AddInputCharacter() helper. @@ -2057,27 +1979,6 @@ struct ImGuiSizeCallbackData ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing. }; -// [ALPHA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions. -// Important: the content of this class is still highly WIP and likely to change and be refactored -// before we stabilize Docking features. Please be mindful if using this. -// Provide hints: -// - To the platform backend via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) -// - To the platform backend for OS level parent/child relationships of viewport. -// - To the docking system for various options and filtering. -struct ImGuiWindowClass -{ - ImGuiID ClassId; // User data. 0 = Default class (unclassed). Windows of different classes cannot be docked with each others. - ImGuiID ParentViewportId; // Hint for the platform backend. If non-zero, the platform backend can create a parent<>child relationship between the platform windows. Not conforming backends are free to e.g. parent every viewport to the main viewport or not. - ImGuiViewportFlags ViewportFlagsOverrideSet; // Viewport flags to set when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. - ImGuiViewportFlags ViewportFlagsOverrideClear; // Viewport flags to clear when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. - ImGuiTabItemFlags TabItemFlagsOverrideSet; // [EXPERIMENTAL] TabItem flags to set when a window of this class gets submitted into a dock node tab bar. May use with ImGuiTabItemFlags_Leading or ImGuiTabItemFlags_Trailing. - ImGuiDockNodeFlags DockNodeFlagsOverrideSet; // [EXPERIMENTAL] Dock node flags to set when a window of this class is hosted by a dock node (it doesn't have to be selected!) - bool DockingAlwaysTabBar; // Set to true to enforce single floating windows of this class always having their own docking node (equivalent of setting the global io.ConfigDockingAlwaysTabBar) - bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window. // FIXME-DOCK: Move to DockNodeFlags override? - - ImGuiWindowClass() { memset(this, 0, sizeof(*this)); DockingAllowUnclassed = true; } -}; - // Data payload for Drag and Drop operations: AcceptDragDropPayload(), GetDragDropPayload() struct ImGuiPayload { @@ -2606,7 +2507,6 @@ struct ImDrawData ImVec2 DisplayPos; // Top-left position of the viewport to render (== top-left of the orthogonal projection matrix to use) (== GetMainViewport()->Pos for the main viewport, == (0.0) in most single-viewport applications) ImVec2 DisplaySize; // Size of the viewport to render (== GetMainViewport()->Size for the main viewport, == io.DisplaySize in most single-viewport applications) ImVec2 FramebufferScale; // Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display. - ImGuiViewport* OwnerViewport; // Viewport carrying the ImDrawData instance, might be of use to the renderer (generally not). // Functions ImDrawData() { Clear(); } @@ -2876,21 +2776,11 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_None = 0, ImGuiViewportFlags_IsPlatformWindow = 1 << 0, // Represent a Platform Window ImGuiViewportFlags_IsPlatformMonitor = 1 << 1, // Represent a Platform Monitor (unused yet) - ImGuiViewportFlags_OwnedByApp = 1 << 2, // Platform Window: is created/managed by the application (rather than a dear imgui backend) - ImGuiViewportFlags_NoDecoration = 1 << 3, // Platform Window: Disable platform decorations: title bar, borders, etc. (generally set all windows, but if ImGuiConfigFlags_ViewportsDecoration is set we only set this on popups/tooltips) - ImGuiViewportFlags_NoTaskBarIcon = 1 << 4, // Platform Window: Disable platform task bar icon (generally set on popups/tooltips, or all windows if ImGuiConfigFlags_ViewportsNoTaskBarIcon is set) - ImGuiViewportFlags_NoFocusOnAppearing = 1 << 5, // Platform Window: Don't take focus when created. - ImGuiViewportFlags_NoFocusOnClick = 1 << 6, // Platform Window: Don't take focus when clicked on. - ImGuiViewportFlags_NoInputs = 1 << 7, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it. - ImGuiViewportFlags_NoRendererClear = 1 << 8, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely). - ImGuiViewportFlags_TopMost = 1 << 9, // Platform Window: Display on top (for tooltips only). - ImGuiViewportFlags_Minimized = 1 << 10, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. - ImGuiViewportFlags_NoAutoMerge = 1 << 11, // Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). - ImGuiViewportFlags_CanHostOtherWindows = 1 << 12 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). + ImGuiViewportFlags_OwnedByApp = 1 << 2 // Platform Window: is created/managed by the application (rather than a dear imgui backend) }; // - Currently represents the Platform Window created by the application which is hosting our Dear ImGui windows. -// - With multi-viewport enabled, we extend this concept to have multiple active viewports. +// - In 'docking' branch with multi-viewport enabled, we extend this concept to have multiple active viewports. // - In the future we will extend this concept further to also represent Platform Monitor and support a "no main platform window" operation mode. // - About Main Area vs Work Area: // - Main Area = entire viewport. @@ -2898,158 +2788,19 @@ enum ImGuiViewportFlags_ // - Windows are generally trying to stay within the Work Area of their host viewport. struct ImGuiViewport { - ImGuiID ID; // Unique identifier for the viewport ImGuiViewportFlags Flags; // See ImGuiViewportFlags_ ImVec2 Pos; // Main Area: Position of the viewport (Dear ImGui coordinates are the same as OS desktop/native coordinates) ImVec2 Size; // Main Area: Size of the viewport. ImVec2 WorkPos; // Work Area: Position of the viewport minus task bars, menus bars, status bars (>= Pos) ImVec2 WorkSize; // Work Area: Size of the viewport minus task bars, menu bars, status bars (<= Size) - float DpiScale; // 1.0f = 96 DPI = No extra scale. - ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform backend to setup a parent/child relationship between platform windows. - ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). - - // Our design separate the Renderer and Platform backends to facilitate combining default backends with each others. - // When our create your own backend for a custom engine, it is possible that both Renderer and Platform will be handled - // by the same system and you may not need to use all the UserData/Handle fields. - // The library never uses those fields, they are merely storage to facilitate backend implementation. - void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function. - void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function. - void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) - void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) - 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 resized by the OS / host window manager, authoritative size will be OS window size) - bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) ImGuiViewport() { memset(this, 0, sizeof(*this)); } - ~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); } // Helpers ImVec2 GetCenter() const { return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); } ImVec2 GetWorkCenter() const { return ImVec2(WorkPos.x + WorkSize.x * 0.5f, WorkPos.y + WorkSize.y * 0.5f); } }; -//----------------------------------------------------------------------------- -// [SECTION] Platform interface for multi-viewport support -//----------------------------------------------------------------------------- -// [BETA] (Optional) This is completely optional, for advanced users! -// If you are new to Dear ImGui and trying to integrate it into your engine, you can probably ignore this for now. -// -// This feature allows you to seamlessly drag Dear ImGui windows outside of your application viewport. -// This is achieved by creating new Platform/OS windows on the fly, and rendering into them. -// Dear ImGui manages the viewport structures, and the backend create and maintain one Platform/OS window for each of those viewports. -// -// See Glossary https://github.com/ocornut/imgui/wiki/Glossary for details about some of the terminology. -// See Thread https://github.com/ocornut/imgui/issues/1542 for gifs, news and questions about this evolving feature. -// -// About the coordinates system: -// - When multi-viewports are enabled, all Dear ImGui coordinates become absolute coordinates (same as OS coordinates!) -// - So e.g. ImGui::SetNextWindowPos(ImVec2(0,0)) will position a window relative to your primary monitor! -// - If you want to position windows relative to your main application viewport, use ImGui::GetMainViewport()->Pos as a base position. -// -// Steps to use multi-viewports in your application, when using a default backend from the examples/ folder: -// - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// - Backend: The backend initialization will setup all necessary ImGuiPlatformIO's functions and update monitors info every frame. -// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). -// - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. -// -// Steps to use multi-viewports in your application, when using a custom backend: -// - Important: THIS IS NOT EASY TO DO and comes with many subtleties not described here! -// It's also an experimental feature, so some of the requirements may evolve. -// Consider using default backends if you can. Either way, carefully follow and refer to examples/ backends for details. -// - Application: Enable feature with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// - Backend: Hook ImGuiPlatformIO's Platform_* and Renderer_* callbacks (see below). -// Set 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports' and 'io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports'. -// Update ImGuiPlatformIO's Monitors list every frame. -// Update MousePos every frame, in absolute coordinates. -// - Application: In your main loop, call ImGui::UpdatePlatformWindows(), ImGui::RenderPlatformWindowsDefault() after EndFrame() or Render(). -// You may skip calling RenderPlatformWindowsDefault() if its API is not convenient for your needs. Read comments below. -// - Application: Fix absolute coordinates used in ImGui::SetWindowPos() or ImGui::SetNextWindowPos() calls. -// -// About ImGui::RenderPlatformWindowsDefault(): -// - This function is a mostly a _helper_ for the common-most cases, and to facilitate using default backends. -// - You can check its simple source code to understand what it does. -// It basically iterates secondary viewports and call 4 functions that are setup in ImGuiPlatformIO, if available: -// Platform_RenderWindow(), Renderer_RenderWindow(), Platform_SwapBuffers(), Renderer_SwapBuffers() -// Those functions pointers exists only for the benefit of RenderPlatformWindowsDefault(). -// - If you have very specific rendering needs (e.g. flipping multiple swap-chain simultaneously, unusual sync/threading issues, etc.), -// you may be tempted to ignore RenderPlatformWindowsDefault() and write customized code to perform your renderingg. -// You may decide to setup the platform_io's *RenderWindow and *SwapBuffers pointers and call your functions through those pointers, -// or you may decide to never setup those pointers and call your code directly. They are a convenience, not an obligatory interface. -//----------------------------------------------------------------------------- - -// (Optional) Access via ImGui::GetPlatformIO() -struct ImGuiPlatformIO -{ - //------------------------------------------------------------------ - // Input - Backend interface/functions + Monitor List - //------------------------------------------------------------------ - - // (Optional) Platform functions (e.g. Win32, GLFW, SDL2) - // For reference, the second column shows which function are generally calling the Platform Functions: - // N = ImGui::NewFrame() ~ beginning of the dear imgui frame: read info from platform/OS windows (latest size/position) - // F = ImGui::Begin(), ImGui::EndFrame() ~ during the dear imgui frame - // U = ImGui::UpdatePlatformWindows() ~ after the dear imgui frame: create and update all platform/OS windows - // R = ImGui::RenderPlatformWindowsDefault() ~ render - // D = ImGui::DestroyPlatformWindows() ~ shutdown - // The general idea is that NewFrame() we will read the current Platform/OS state, and UpdatePlatformWindows() will write to it. - // - // The functions are designed so we can mix and match 2 imgui_impl_xxxx files, one for the Platform (~window/input handling), one for Renderer. - // Custom engine backends will often provide both Platform and Renderer interfaces and so may not need to use all functions. - // Platform functions are typically called before their Renderer counterpart, apart from Destroy which are called the other way. - - // Platform function --------------------------------------------------- Called by ----- - void (*Platform_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create a new platform window for the given viewport - void (*Platform_DestroyWindow)(ImGuiViewport* vp); // N . U . D // - void (*Platform_ShowWindow)(ImGuiViewport* vp); // . . U . . // Newly created windows are initially hidden so SetWindowPos/Size/Title can be called on them before showing the window - void (*Platform_SetWindowPos)(ImGuiViewport* vp, ImVec2 pos); // . . U . . // Set platform window position (given the upper-left corner of client area) - ImVec2 (*Platform_GetWindowPos)(ImGuiViewport* vp); // N . . . . // - void (*Platform_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Set platform window client area size (ignoring OS decorations such as OS title bar etc.) - ImVec2 (*Platform_GetWindowSize)(ImGuiViewport* vp); // N . . . . // Get platform window client area size - void (*Platform_SetWindowFocus)(ImGuiViewport* vp); // N . . . . // Move window to front and set input focus - bool (*Platform_GetWindowFocus)(ImGuiViewport* vp); // . . U . . // - bool (*Platform_GetWindowMinimized)(ImGuiViewport* vp); // N . . . . // Get platform window minimized state. When minimized, we generally won't attempt to get/set size and contents will be culled more easily - void (*Platform_SetWindowTitle)(ImGuiViewport* vp, const char* str); // . . U . . // Set platform window title (given an UTF-8 string) - void (*Platform_SetWindowAlpha)(ImGuiViewport* vp, float alpha); // . . U . . // (Optional) Setup global transparency (not per-pixel transparency) - void (*Platform_UpdateWindow)(ImGuiViewport* vp); // . . U . . // (Optional) Called by UpdatePlatformWindows(). Optional hook to allow the platform backend from doing general book-keeping every frame. - void (*Platform_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Main rendering (platform side! This is often unused, or just setting a "current" context for OpenGL bindings). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). - 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. - void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // . F . . . // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. FIXME: The call timing of this is inconsistent because we want to support without multi-viewports. - 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) - void (*Renderer_CreateWindow)(ImGuiViewport* vp); // . . U . . // Create swap chain, frame buffers etc. (called after Platform_CreateWindow) - void (*Renderer_DestroyWindow)(ImGuiViewport* vp); // N . U . D // Destroy swap chain, frame buffers etc. (called before Platform_DestroyWindow) - void (*Renderer_SetWindowSize)(ImGuiViewport* vp, ImVec2 size); // . . U . . // Resize swap chain, frame buffers etc. (called after Platform_SetWindowSize) - void (*Renderer_RenderWindow)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Clear framebuffer, setup render target, then render the viewport->DrawData. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). - void (*Renderer_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers. 'render_arg' is the value passed to RenderPlatformWindowsDefault(). - - // (Optional) Monitor list - // - Updated by: app/backend. Update every frame to dynamically support changing monitor or DPI configuration. - // - Used by: dear imgui to query DPI info, clamp popups/tooltips within same monitor and not have them straddle monitors. - ImVector Monitors; - - //------------------------------------------------------------------ - // Output - List of viewports to render into platform windows - //------------------------------------------------------------------ - - // Viewports list (the list is updated by calling ImGui::EndFrame or ImGui::Render) - // (in the future we will attempt to organize this feature to remove the need for a "main viewport") - ImVector Viewports; // Main viewports, followed by all secondary viewports. - ImGuiPlatformIO() { memset(this, 0, sizeof(*this)); } // Zero clear -}; - -// (Optional) This is required when enabling multi-viewport. Represent the bounds of each connected monitor/display and their DPI. -// We use this information for multiple DPI support + clamping the position of popups and tooltips so they don't straddle multiple monitors. -struct ImGuiPlatformMonitor -{ - ImVec2 MainPos, MainSize; // Coordinates of the area displayed on this monitor (Min = upper left, Max = bottom right) - ImVec2 WorkPos, WorkSize; // Coordinates without task bars / side bars / menu bars. Used to avoid positioning popups/tooltips inside this region. If you don't have this info, please copy the value for MainPos/MainSize. - float DpiScale; // 1.0f = 96 DPI - ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; } -}; - //----------------------------------------------------------------------------- // [SECTION] Obsolete functions and types // (Will be removed! Read 'API BREAKING CHANGES' section in imgui.cpp for details) diff --git a/3rdparty/dear-imgui/imgui_demo.cpp b/3rdparty/dear-imgui/imgui_demo.cpp index d62d8dec2..d75989d69 100644 --- a/3rdparty/dear-imgui/imgui_demo.cpp +++ b/3rdparty/dear-imgui/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (demo code) // Help: @@ -67,7 +67,6 @@ Index of this file: // [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen() // [SECTION] Example App: Manipulating window titles / ShowExampleAppWindowTitles() // [SECTION] Example App: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering() -// [SECTION] Example App: Docking, DockSpace / ShowExampleAppDockSpace() // [SECTION] Example App: Documents Handling / ShowExampleAppDocuments() */ @@ -171,7 +170,6 @@ Index of this file: #if !defined(IMGUI_DISABLE_DEMO_WINDOWS) // Forward Declarations -static void ShowExampleAppDockSpace(bool* p_open); static void ShowExampleAppDocuments(bool* p_open); static void ShowExampleAppMainMenuBar(); static void ShowExampleAppConsole(bool* p_open); @@ -202,16 +200,6 @@ static void HelpMarker(const char* desc) } } -static void ShowDockingDisabledMessage() -{ - ImGuiIO& io = ImGui::GetIO(); - ImGui::Text("ERROR: Docking is not enabled! See Demo > Configuration."); - ImGui::Text("Set io.ConfigFlags |= ImGuiConfigFlags_DockingEnable in your code, or "); - ImGui::SameLine(0.0f, 0.0f); - if (ImGui::SmallButton("click here")) - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; -} - // Helper to display basic user controls. void ImGui::ShowUserGuide() { @@ -275,7 +263,6 @@ void ImGui::ShowDemoWindow(bool* p_open) // Examples Apps (accessible from the "Examples" menu) static bool show_app_main_menu_bar = false; - static bool show_app_dockspace = false; static bool show_app_documents = false; static bool show_app_console = false; @@ -291,8 +278,7 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool show_app_custom_rendering = false; if (show_app_main_menu_bar) ShowExampleAppMainMenuBar(); - if (show_app_dockspace) ShowExampleAppDockSpace(&show_app_dockspace); // Process the Docking app first, as explicit DockSpace() nodes needs to be submitted early (read comments near the DockSpace function) - if (show_app_documents) ShowExampleAppDocuments(&show_app_documents); // Process the Document app next, as it may also use a DockSpace() + if (show_app_documents) ShowExampleAppDocuments(&show_app_documents); if (show_app_console) ShowExampleAppConsole(&show_app_console); if (show_app_log) ShowExampleAppLog(&show_app_log); @@ -331,7 +317,6 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool no_nav = false; static bool no_background = false; static bool no_bring_to_front = false; - static bool no_docking = false; static bool unsaved_document = false; ImGuiWindowFlags window_flags = 0; @@ -344,7 +329,6 @@ void ImGui::ShowDemoWindow(bool* p_open) if (no_nav) window_flags |= ImGuiWindowFlags_NoNav; if (no_background) window_flags |= ImGuiWindowFlags_NoBackground; if (no_bring_to_front) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus; - if (no_docking) window_flags |= ImGuiWindowFlags_NoDocking; if (unsaved_document) window_flags |= ImGuiWindowFlags_UnsavedDocument; if (no_close) p_open = NULL; // Don't pass our bool* to Begin @@ -392,7 +376,6 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::MenuItem("Fullscreen window", NULL, &show_app_fullscreen); ImGui::MenuItem("Manipulating window titles", NULL, &show_app_window_titles); ImGui::MenuItem("Custom rendering", NULL, &show_app_custom_rendering); - ImGui::MenuItem("Dockspace", NULL, &show_app_dockspace); ImGui::MenuItem("Documents", NULL, &show_app_documents); ImGui::EndMenu(); } @@ -457,37 +440,6 @@ void ImGui::ShowDemoWindow(bool* p_open) } ImGui::CheckboxFlags("io.ConfigFlags: NoMouseCursorChange", &io.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange); ImGui::SameLine(); HelpMarker("Instruct backend to not alter mouse cursor shape and visibility."); - - ImGui::CheckboxFlags("io.ConfigFlags: DockingEnable", &io.ConfigFlags, ImGuiConfigFlags_DockingEnable); - ImGui::SameLine(); HelpMarker("Drag from window title bar or their tab to dock/undock. Hold SHIFT to disable docking.\n\nDrag from window menu button (upper-left button) to undock an entire node (all windows)."); - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - ImGui::Indent(); - ImGui::Checkbox("io.ConfigDockingNoSplit", &io.ConfigDockingNoSplit); - ImGui::SameLine(); HelpMarker("Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars."); - ImGui::Checkbox("io.ConfigDockingAlwaysTabBar", &io.ConfigDockingAlwaysTabBar); - ImGui::SameLine(); HelpMarker("Create a docking node and tab-bar on single floating windows."); - ImGui::Checkbox("io.ConfigDockingTransparentPayload", &io.ConfigDockingTransparentPayload); - ImGui::SameLine(); HelpMarker("Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge."); - ImGui::Unindent(); - } - - ImGui::CheckboxFlags("io.ConfigFlags: ViewportsEnable", &io.ConfigFlags, ImGuiConfigFlags_ViewportsEnable); - ImGui::SameLine(); HelpMarker("[beta] Enable beta multi-viewports support. See ImGuiPlatformIO for details."); - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) - { - ImGui::Indent(); - ImGui::Checkbox("io.ConfigViewportsNoAutoMerge", &io.ConfigViewportsNoAutoMerge); - ImGui::SameLine(); HelpMarker("Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it."); - ImGui::Checkbox("io.ConfigViewportsNoTaskBarIcon", &io.ConfigViewportsNoTaskBarIcon); - ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform backends won't refresh the task bar icon state right away)."); - ImGui::Checkbox("io.ConfigViewportsNoDecoration", &io.ConfigViewportsNoDecoration); - ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform backends won't refresh the decoration right away)."); - ImGui::Checkbox("io.ConfigViewportsNoDefaultParent", &io.ConfigViewportsNoDefaultParent); - ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform backends won't refresh the parenting right away)."); - ImGui::Unindent(); - } - ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink); ImGui::SameLine(); HelpMarker("Enable blinking cursor (optional as some users consider it to be distracting)"); ImGui::Checkbox("io.ConfigDragClickToInputText", &io.ConfigDragClickToInputText); @@ -510,13 +462,10 @@ void ImGui::ShowDemoWindow(bool* p_open) // Make a local copy to avoid modifying actual backend flags. ImGuiBackendFlags backend_flags = io.BackendFlags; - ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &backend_flags, ImGuiBackendFlags_HasGamepad); - ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors); - ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &backend_flags, ImGuiBackendFlags_HasSetMousePos); - ImGui::CheckboxFlags("io.BackendFlags: PlatformHasViewports", &backend_flags, ImGuiBackendFlags_PlatformHasViewports); - ImGui::CheckboxFlags("io.BackendFlags: HasMouseHoveredViewport",&backend_flags, ImGuiBackendFlags_HasMouseHoveredViewport); - ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &backend_flags, ImGuiBackendFlags_RendererHasVtxOffset); - ImGui::CheckboxFlags("io.BackendFlags: RendererHasViewports", &backend_flags, ImGuiBackendFlags_RendererHasViewports); + ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &backend_flags, ImGuiBackendFlags_HasGamepad); + ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors); + ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &backend_flags, ImGuiBackendFlags_HasSetMousePos); + ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &backend_flags, ImGuiBackendFlags_RendererHasVtxOffset); ImGui::TreePop(); ImGui::Separator(); } @@ -562,7 +511,6 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::TableNextColumn(); ImGui::Checkbox("No nav", &no_nav); ImGui::TableNextColumn(); ImGui::Checkbox("No background", &no_background); ImGui::TableNextColumn(); ImGui::Checkbox("No bring to front", &no_bring_to_front); - ImGui::TableNextColumn(); ImGui::Checkbox("No docking", &no_docking); ImGui::TableNextColumn(); ImGui::Checkbox("Unsaved document", &unsaved_document); ImGui::EndTable(); } @@ -585,6 +533,10 @@ static void ShowDemoWindowWidgets() if (!ImGui::CollapsingHeader("Widgets")) return; + static bool disable_all = false; // The Checkbox for that is inside the "Disabled" section at the bottom + if (disable_all) + ImGui::BeginDisabled(); + if (ImGui::TreeNode("Basic")) { static int clicked = 0; @@ -2233,7 +2185,7 @@ static void ShowDemoWindowWidgets() ImGui::TreePop(); } - if (ImGui::TreeNode("Querying Status (Edited/Active/Focused/Hovered etc.)")) + if (ImGui::TreeNode("Querying Status (Edited/Active/Hovered etc.)")) { // Select an item type const char* item_names[] = @@ -2241,16 +2193,20 @@ static void ShowDemoWindowWidgets() "Text", "Button", "Button (w/ repeat)", "Checkbox", "SliderFloat", "InputText", "InputFloat", "InputFloat3", "ColorEdit4", "Selectable", "MenuItem", "TreeNode", "TreeNode (w/ double-click)", "Combo", "ListBox" }; - static int item_type = 1; + static int item_type = 4; + static bool item_disabled = false; ImGui::Combo("Item Type", &item_type, item_names, IM_ARRAYSIZE(item_names), IM_ARRAYSIZE(item_names)); ImGui::SameLine(); HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions. Note that the bool return value of most ImGui function is generally equivalent to calling ImGui::IsItemHovered()."); + ImGui::Checkbox("Item Disabled", &item_disabled); // Submit selected item item so we can query their status in the code following it. bool ret = false; static bool b = false; static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f }; static char str[16] = {}; + if (item_disabled) + ImGui::BeginDisabled(true); if (item_type == 0) { ImGui::Text("ITEM: Text"); } // Testing text items with no identifier/interaction if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); } // Testing button if (item_type == 2) { ImGui::PushButtonRepeat(true); ret = ImGui::Button("ITEM: Button"); ImGui::PopButtonRepeat(); } // Testing button (with repeater) @@ -2278,6 +2234,7 @@ static void ShowDemoWindowWidgets() "IsItemHovered(_AllowWhenBlockedByPopup) = %d\n" "IsItemHovered(_AllowWhenBlockedByActiveItem) = %d\n" "IsItemHovered(_AllowWhenOverlapped) = %d\n" + "IsItemHovered(_AllowWhenDisabled) = %d\n" "IsItemHovered(_RectOnly) = %d\n" "IsItemActive() = %d\n" "IsItemEdited() = %d\n" @@ -2296,6 +2253,7 @@ static void ShowDemoWindowWidgets() ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup), ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem), ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenOverlapped), + ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled), ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly), ImGui::IsItemActive(), ImGui::IsItemEdited(), @@ -2310,6 +2268,9 @@ static void ShowDemoWindowWidgets() ImGui::GetItemRectSize().x, ImGui::GetItemRectSize().y ); + if (item_disabled) + ImGui::EndDisabled(); + static bool embed_all_inside_a_child_window = false; ImGui::Checkbox("Embed everything inside a child window (for additional testing)", &embed_all_inside_a_child_window); if (embed_all_inside_a_child_window) @@ -2360,13 +2321,10 @@ static void ShowDemoWindowWidgets() // Calling IsItemHovered() after begin returns the hovered status of the title bar. // This is useful in particular if you want to create a context menu associated to the title bar of a window. - // This will also work when docked into a Tab (the Tab replace the Title Bar and guarantee the same properties). static bool test_window = false; ImGui::Checkbox("Hovered/Active tests after Begin() for title bar testing", &test_window); if (test_window) { - // FIXME-DOCK: This window cannot be docked within the ImGui Demo window, this will cause a feedback loop and get them stuck. - // Could we fix this through an ImGuiWindowClass feature? Or an API call to tag our parent as "don't skip items"? ImGui::Begin("Title bar Hovered/Active tests", &test_window); if (ImGui::BeginPopupContextItem()) // <-- This is using IsItemHovered() { @@ -2382,6 +2340,18 @@ static void ShowDemoWindowWidgets() ImGui::TreePop(); } + + // Demonstrate BeginDisabled/EndDisabled using a checkbox located at the bottom of the section (which is a bit odd: + // logically we'd have this checkbox at the top of the section, but we don't want this feature to steal that space) + if (disable_all) + ImGui::EndDisabled(); + + if (ImGui::TreeNode("Disable block")) + { + ImGui::Checkbox("Disable entire section above", &disable_all); + ImGui::SameLine(); HelpMarker("Demonstrate using BeginDisabled()/EndDisabled() across this section."); + ImGui::TreePop(); + } } static void ShowDemoWindowLayout() @@ -2451,7 +2421,7 @@ static void ShowDemoWindowLayout() // You can also call SetNextWindowPos() to position the child window. The parent window will effectively // layout from this position. // - Using ImGui::GetItemRectMin/Max() to query the "item" state (because the child window is an item from - // the POV of the parent window). See 'Demo->Querying Status (Active/Focused/Hovered etc.)' for details. + // the POV of the parent window). See 'Demo->Querying Status (Edited/Active/Hovered etc.)' for details. { static int offset_x = 0; ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); @@ -5760,12 +5730,6 @@ void ImGui::ShowAboutWindow(bool* p_open) #endif #ifdef __clang_version__ ImGui::Text("define: __clang_version__=%s", __clang_version__); -#endif -#ifdef IMGUI_HAS_VIEWPORT - ImGui::Text("define: IMGUI_HAS_VIEWPORT"); -#endif -#ifdef IMGUI_HAS_DOCK - ImGui::Text("define: IMGUI_HAS_DOCK"); #endif ImGui::Separator(); ImGui::Text("io.BackendPlatformName: %s", io.BackendPlatformName ? io.BackendPlatformName : "NULL"); @@ -5777,18 +5741,7 @@ void ImGui::ShowAboutWindow(bool* p_open) if (io.ConfigFlags & ImGuiConfigFlags_NavNoCaptureKeyboard) ImGui::Text(" NavNoCaptureKeyboard"); if (io.ConfigFlags & ImGuiConfigFlags_NoMouse) ImGui::Text(" NoMouse"); if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) ImGui::Text(" NoMouseCursorChange"); - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) ImGui::Text(" DockingEnable"); - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) ImGui::Text(" ViewportsEnable"); - if (io.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports) ImGui::Text(" DpiEnableScaleViewports"); - if (io.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleFonts) ImGui::Text(" DpiEnableScaleFonts"); if (io.MouseDrawCursor) ImGui::Text("io.MouseDrawCursor"); - if (io.ConfigViewportsNoAutoMerge) ImGui::Text("io.ConfigViewportsNoAutoMerge"); - if (io.ConfigViewportsNoTaskBarIcon) ImGui::Text("io.ConfigViewportsNoTaskBarIcon"); - if (io.ConfigViewportsNoDecoration) ImGui::Text("io.ConfigViewportsNoDecoration"); - if (io.ConfigViewportsNoDefaultParent) ImGui::Text("io.ConfigViewportsNoDefaultParent"); - if (io.ConfigDockingNoSplit) ImGui::Text("io.ConfigDockingNoSplit"); - if (io.ConfigDockingAlwaysTabBar) ImGui::Text("io.ConfigDockingAlwaysTabBar"); - if (io.ConfigDockingTransparentPayload) ImGui::Text("io.ConfigDockingTransparentPayload"); if (io.ConfigMacOSXBehaviors) ImGui::Text("io.ConfigMacOSXBehaviors"); if (io.ConfigInputTextCursorBlink) ImGui::Text("io.ConfigInputTextCursorBlink"); if (io.ConfigWindowsResizeFromEdges) ImGui::Text("io.ConfigWindowsResizeFromEdges"); @@ -5798,10 +5751,7 @@ void ImGui::ShowAboutWindow(bool* p_open) if (io.BackendFlags & ImGuiBackendFlags_HasGamepad) ImGui::Text(" HasGamepad"); if (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) ImGui::Text(" HasMouseCursors"); if (io.BackendFlags & ImGuiBackendFlags_HasSetMousePos) ImGui::Text(" HasSetMousePos"); - if (io.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) ImGui::Text(" PlatformHasViewports"); - if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport)ImGui::Text(" HasMouseHoveredViewport"); if (io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) ImGui::Text(" RendererHasVtxOffset"); - if (io.BackendFlags & ImGuiBackendFlags_RendererHasViewports) ImGui::Text(" RendererHasViewports"); ImGui::Separator(); ImGui::Text("io.Fonts: %d fonts, Flags: 0x%08X, TexSize: %d,%d", io.Fonts->Fonts.Size, io.Fonts->Flags, io.Fonts->TexWidth, io.Fonts->TexHeight); ImGui::Text("io.DisplaySize: %.2f,%.2f", io.DisplaySize.x, io.DisplaySize.y); @@ -6116,6 +6066,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) HelpMarker("When drawing circle primitives with \"num_segments == 0\" tesselation will be calculated automatically."); ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero. + ImGui::DragFloat("Disabled Alpha", &style.DisabledAlpha, 0.005f, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Additional alpha multiplier for disabled items (multiply over current value of Alpha)."); ImGui::PopItemWidth(); ImGui::EndTabItem(); @@ -7028,8 +6979,6 @@ static void ShowExampleAppConstrainedResize(bool* p_open) ImGuiWindowFlags flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0; if (ImGui::Begin("Example: Constrained Resize", p_open, flags)) { - if (ImGui::IsWindowDocked()) - ImGui::Text("Warning: Sizing Constraints won't work if the window is docked!"); if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine(); if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine(); if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); } @@ -7054,7 +7003,7 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) { static int corner = 0; ImGuiIO& io = ImGui::GetIO(); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav; if (corner != -1) { const float PAD = 10.0f; @@ -7067,7 +7016,6 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f; window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f; ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); - ImGui::SetNextWindowViewport(viewport->ID); window_flags |= ImGuiWindowFlags_NoMove; } ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background @@ -7405,129 +7353,6 @@ static void ShowExampleAppCustomRendering(bool* p_open) ImGui::End(); } -//----------------------------------------------------------------------------- -// [SECTION] Example App: Docking, DockSpace / ShowExampleAppDockSpace() -//----------------------------------------------------------------------------- - -// Demonstrate using DockSpace() to create an explicit docking node within an existing window. -// Note: You can use most Docking facilities without calling any API. You DO NOT need to call DockSpace() to use Docking! -// - Drag from window title bar or their tab to dock/undock. Hold SHIFT to disable docking. -// - Drag from window menu button (upper-left button) to undock an entire node (all windows). -// About dockspaces: -// - Use DockSpace() to create an explicit dock node _within_ an existing window. -// - Use DockSpaceOverViewport() to create an explicit dock node covering the screen or a specific viewport. -// This is often used with ImGuiDockNodeFlags_PassthruCentralNode. -// - Important: Dockspaces need to be submitted _before_ any window they can host. Submit it early in your frame! (*) -// - Important: Dockspaces need to be kept alive if hidden, otherwise windows docked into it will be undocked. -// e.g. if you have multiple tabs with a dockspace inside each tab: submit the non-visible dockspaces with ImGuiDockNodeFlags_KeepAliveOnly. -// (*) because of this constraint, the implicit \"Debug\" window can not be docked into an explicit DockSpace() node, -// because that window is submitted as part of the part of the NewFrame() call. An easy workaround is that you can create -// your own implicit "Debug##2" window after calling DockSpace() and leave it in the window stack for anyone to use. -void ShowExampleAppDockSpace(bool* p_open) -{ - // If you strip some features of, this demo is pretty much equivalent to calling DockSpaceOverViewport()! - // In most cases you should be able to just call DockSpaceOverViewport() and ignore all the code below! - // In this specific demo, we are not using DockSpaceOverViewport() because: - // - we allow the host window to be floating/moveable instead of filling the viewport (when opt_fullscreen == false) - // - we allow the host window to have padding (when opt_padding == true) - // - we have a local menu bar in the host window (vs. you could use BeginMainMenuBar() + DockSpaceOverViewport() in your code!) - // TL;DR; this demo is more complicated than what you would normally use. - // If we removed all the options we are showcasing, this demo would become: - // void ShowExampleAppDockSpace() - // { - // ImGui::DockSpaceOverViewport(ImGui::GetMainViewport()); - // } - - static bool opt_fullscreen = true; - static bool opt_padding = false; - static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; - - // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, - // because it would be confusing to have two docking targets within each others. - ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking; - if (opt_fullscreen) - { - const ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(viewport->WorkSize); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; - } - else - { - dockspace_flags &= ~ImGuiDockNodeFlags_PassthruCentralNode; - } - - // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background - // and handle the pass-thru hole, so we ask Begin() to not render a background. - if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) - window_flags |= ImGuiWindowFlags_NoBackground; - - // Important: note that we proceed even if Begin() returns false (aka window is collapsed). - // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive, - // all active windows docked into it will lose their parent and become undocked. - // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise - // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. - if (!opt_padding) - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGui::Begin("DockSpace Demo", p_open, window_flags); - if (!opt_padding) - ImGui::PopStyleVar(); - - if (opt_fullscreen) - ImGui::PopStyleVar(2); - - // Submit the DockSpace - ImGuiIO& io = ImGui::GetIO(); - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); - } - else - { - ShowDockingDisabledMessage(); - } - - if (ImGui::BeginMenuBar()) - { - if (ImGui::BeginMenu("Options")) - { - // Disabling fullscreen would allow the window to be moved to the front of other windows, - // which we can't undo at the moment without finer window depth/z control. - ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen); - ImGui::MenuItem("Padding", NULL, &opt_padding); - ImGui::Separator(); - - if (ImGui::MenuItem("Flag: NoSplit", "", (dockspace_flags & ImGuiDockNodeFlags_NoSplit) != 0)) { dockspace_flags ^= ImGuiDockNodeFlags_NoSplit; } - if (ImGui::MenuItem("Flag: NoResize", "", (dockspace_flags & ImGuiDockNodeFlags_NoResize) != 0)) { dockspace_flags ^= ImGuiDockNodeFlags_NoResize; } - if (ImGui::MenuItem("Flag: NoDockingInCentralNode", "", (dockspace_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) != 0)) { dockspace_flags ^= ImGuiDockNodeFlags_NoDockingInCentralNode; } - if (ImGui::MenuItem("Flag: AutoHideTabBar", "", (dockspace_flags & ImGuiDockNodeFlags_AutoHideTabBar) != 0)) { dockspace_flags ^= ImGuiDockNodeFlags_AutoHideTabBar; } - if (ImGui::MenuItem("Flag: PassthruCentralNode", "", (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0, opt_fullscreen)) { dockspace_flags ^= ImGuiDockNodeFlags_PassthruCentralNode; } - ImGui::Separator(); - - if (ImGui::MenuItem("Close", NULL, false, p_open != NULL)) - *p_open = false; - ImGui::EndMenu(); - } - HelpMarker( - "When docking is enabled, you can ALWAYS dock MOST window into another! Try it now!" "\n" - "- Drag from window title bar or their tab to dock/undock." "\n" - "- Drag from window menu button (upper-left button) to undock an entire node (all windows)." "\n" - "- Hold SHIFT to disable docking." "\n" - "This demo app has nothing to do with it!" "\n\n" - "This demo app only demonstrate the use of ImGui::DockSpace() which allows you to manually create a docking node _within_ another window." "\n\n" - "Read comments in ShowExampleAppDockSpace() for more details."); - - ImGui::EndMenuBar(); - } - - ImGui::End(); -} - //----------------------------------------------------------------------------- // [SECTION] Example App: Documents Handling / ShowExampleAppDocuments() //----------------------------------------------------------------------------- @@ -7627,25 +7452,11 @@ void ShowExampleAppDocuments(bool* p_open) static ExampleAppDocuments app; // Options - enum Target - { - Target_None, - Target_Tab, // Create documents as local tab into a local tab bar - Target_DockSpaceAndWindow // Create documents as regular windows, and create an embedded dockspace - }; - static Target opt_target = Target_Tab; static bool opt_reorderable = true; static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_; - // When (opt_target == Target_DockSpaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant") - // that we emit gets docked into the same spot as the parent window ("Example: Documents"). - // This would create a problematic feedback loop because selecting the "Eggplant" tab would make the "Example: Documents" tab - // not visible, which in turn would stop submitting the "Eggplant" window. - // We avoid this problem by submitting our documents window even if our parent window is not currently visible. - // Another solution may be to make the "Example: Documents" window use the ImGuiWindowFlags_NoDocking. - bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar); - if (!window_contents_visible && opt_target != Target_DockSpaceAndWindow) + if (!window_contents_visible) { ImGui::End(); return; @@ -7692,12 +7503,6 @@ void ShowExampleAppDocuments(bool* p_open) doc->DoForceClose(); ImGui::PopID(); } - ImGui::PushItemWidth(ImGui::GetFontSize() * 12); - ImGui::Combo("Output", (int*)&opt_target, "None\0TabBar+Tabs\0DockSpace+Window\0"); - ImGui::PopItemWidth(); - bool redock_all = false; - if (opt_target == Target_Tab) { ImGui::SameLine(); ImGui::Checkbox("Reorderable Tabs", &opt_reorderable); } - if (opt_target == Target_DockSpaceAndWindow) { ImGui::SameLine(); redock_all = ImGui::Button("Redock all"); } ImGui::Separator(); @@ -7711,8 +7516,7 @@ void ShowExampleAppDocuments(bool* p_open) // hole for one-frame, both in the tab-bar and in tab-contents when closing a tab/window. // The rarely used SetTabItemClosed() function is a way to notify of programmatic closure to avoid the one-frame hole. - // Tabs - if (opt_target == Target_Tab) + // Submit Tab Bar and Tabs { ImGuiTabBarFlags tab_bar_flags = (opt_fitting_flags) | (opt_reorderable ? ImGuiTabBarFlags_Reorderable : 0); if (ImGui::BeginTabBar("##tabs", tab_bar_flags)) @@ -7752,53 +7556,6 @@ void ShowExampleAppDocuments(bool* p_open) ImGui::EndTabBar(); } } - else if (opt_target == Target_DockSpaceAndWindow) - { - if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - NotifyOfDocumentsClosedElsewhere(app); - - // Create a DockSpace node where any window can be docked - ImGuiID dockspace_id = ImGui::GetID("MyDockSpace"); - ImGui::DockSpace(dockspace_id); - - // Create Windows - for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) - { - MyDocument* doc = &app.Documents[doc_n]; - if (!doc->Open) - continue; - - ImGui::SetNextWindowDockID(dockspace_id, redock_all ? ImGuiCond_Always : ImGuiCond_FirstUseEver); - ImGuiWindowFlags window_flags = (doc->Dirty ? ImGuiWindowFlags_UnsavedDocument : 0); - bool visible = ImGui::Begin(doc->Name, &doc->Open, window_flags); - - // Cancel attempt to close when unsaved add to save queue so we can display a popup. - if (!doc->Open && doc->Dirty) - { - doc->Open = true; - doc->DoQueueClose(); - } - - MyDocument::DisplayContextMenu(doc); - if (visible) - MyDocument::DisplayContents(doc); - - ImGui::End(); - } - } - else - { - ShowDockingDisabledMessage(); - } - } - - // Early out other contents - if (!window_contents_visible) - { - ImGui::End(); - return; - } // Update closing queue static ImVector close_queue; diff --git a/3rdparty/dear-imgui/imgui_draw.cpp b/3rdparty/dear-imgui/imgui_draw.cpp index 0a16565c4..e1d7b7eee 100644 --- a/3rdparty/dear-imgui/imgui_draw.cpp +++ b/3rdparty/dear-imgui/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (drawing and font code) /* @@ -230,8 +230,6 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst) colors[ImGuiCol_TabActive] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f); colors[ImGuiCol_TabUnfocused] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f); colors[ImGuiCol_TabUnfocusedActive] = ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f); - colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_HeaderActive] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); @@ -292,8 +290,6 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst) colors[ImGuiCol_TabActive] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f); colors[ImGuiCol_TabUnfocused] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f); colors[ImGuiCol_TabUnfocusedActive] = ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f); - colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_Header] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); @@ -355,8 +351,6 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst) colors[ImGuiCol_TabActive] = ImLerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f); colors[ImGuiCol_TabUnfocused] = ImLerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f); colors[ImGuiCol_TabUnfocusedActive] = ImLerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f); - colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_Header] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); - colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); @@ -3736,7 +3730,6 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderBullet() // - RenderCheckMark() // - RenderMouseCursor() -// - RenderArrowDockMenu() // - RenderArrowPointingAt() // - RenderRectFilledRangeH() // - RenderRectFilledWithHole() @@ -3831,14 +3824,6 @@ void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half } } -// This is less wide than RenderArrow() and we use in dock nodes instead of the regular RenderArrow() to denote a change of functionality, -// and because the saved space means that the left-most tab label can stay at exactly the same position as the label of a loose window. -void ImGui::RenderArrowDockMenu(ImDrawList* draw_list, ImVec2 p_min, float sz, ImU32 col) -{ - draw_list->AddRectFilled(p_min + ImVec2(sz * 0.20f, sz * 0.15f), p_min + ImVec2(sz * 0.80f, sz * 0.30f), col); - RenderArrowPointingAt(draw_list, p_min + ImVec2(sz * 0.50f, sz * 0.85f), ImVec2(sz * 0.30f, sz * 0.40f), ImGuiDir_Down, col); -} - static inline float ImAcos01(float x) { if (x <= 0.0f) return IM_PI * 0.5f; diff --git a/3rdparty/dear-imgui/imgui_internal.h b/3rdparty/dear-imgui/imgui_internal.h index 10751f827..1eb0cb7a0 100644 --- a/3rdparty/dear-imgui/imgui_internal.h +++ b/3rdparty/dear-imgui/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! @@ -121,10 +121,6 @@ struct ImGuiColorMod; // Stacked color modifier, backup of modifie struct ImGuiContext; // Main Dear ImGui context struct ImGuiContextHook; // Hook for extensions like ImGuiTestEngine struct ImGuiDataTypeInfo; // Type information associated to a ImGuiDataType enum -struct ImGuiDockContext; // Docking system context -struct ImGuiDockRequest; // Docking system dock/undock queued request -struct ImGuiDockNode; // Docking system node (hold a list of Windows OR two child dock nodes) -struct ImGuiDockNodeSettings; // Storage for a dock node in .ini file (we preserve those even if the associated dock node isn't active during the session) struct ImGuiGroupData; // Stacked storage data for BeginGroup()/EndGroup() struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box struct ImGuiLastItemData; // Status storage for last submitted items @@ -151,7 +147,6 @@ struct ImGuiWindowTempData; // Temporary storage for one window (that's struct ImGuiWindowSettings; // Storage for a window .ini settings (we keep one of those even if the actual window wasn't instanced during this session) // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. -typedef int ImGuiDataAuthority; // -> enum ImGuiDataAuthority_ // Enum: for storing the source authority (dock node vs window) of a field typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag() typedef int ImGuiItemAddFlags; // -> enum ImGuiItemAddFlags_ // Flags: for ItemAdd() @@ -199,9 +194,6 @@ namespace ImStb // [SECTION] Macros //----------------------------------------------------------------------------- -// Internal Drag and Drop payload types. String starting with '_' are reserved for Dear ImGui. -#define IMGUI_PAYLOAD_TYPE_WINDOW "_IMWINDOW" // Payload == ImGuiWindow* - // Debug Logging #ifndef IMGUI_DEBUG_LOG #define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) @@ -210,12 +202,8 @@ namespace ImStb // Debug Logging for selected systems. Remove the '((void)0) //' to enable. //#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log //#define IMGUI_DEBUG_LOG_NAV IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log #define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log #define IMGUI_DEBUG_LOG_NAV(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log // Static Asserts #if (__cplusplus >= 201100) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201100) @@ -754,7 +742,7 @@ enum ImGuiItemFlags_ ImGuiItemFlags_None = 0, ImGuiItemFlags_NoTabStop = 1 << 0, // false // Disable keyboard tabbing (FIXME: should merge with _NoNav) ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. - ImGuiItemFlags_Disabled = 1 << 2, // false // Disable interactions but doesn't affect visuals. See PushDisabled()/PushDisabled(). See github.com/ocornut/imgui/issues/211 + ImGuiItemFlags_Disabled = 1 << 2, // false // Disable interactions but doesn't affect visuals. See BeginDisabled()/EndDisabled(). See github.com/ocornut/imgui/issues/211 ImGuiItemFlags_NoNav = 1 << 3, // false // Disable keyboard/gamepad directional navigation (FIXME: should merge with _NoTabStop) ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false // Disable item being a candidate for default focus (e.g. used by title bar items) ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // Disable MenuItem/Selectable() automatically closing their popup window @@ -817,7 +805,7 @@ enum ImGuiButtonFlagsPrivate_ ImGuiButtonFlags_FlattenChildren = 1 << 11, // allow interactions even if a child window is overlapping ImGuiButtonFlags_AllowItemOverlap = 1 << 12, // require previous frame HoveredId to either match id or be null before being usable, use along with SetItemAllowOverlap() ImGuiButtonFlags_DontClosePopups = 1 << 13, // disable automatically closing parent popup on press // [UNUSED] - //ImGuiButtonFlags_Disabled = 1 << 14, // disable interactions -> use PushDisabled() or ImGuiItemFlags_Disabled + //ImGuiButtonFlags_Disabled = 1 << 14, // disable interactions -> use BeginDisabled() or ImGuiItemFlags_Disabled ImGuiButtonFlags_AlignTextBaseLine = 1 << 15, // vertically align button to match text baseline - ButtonEx() only // FIXME: Should be removed and handled by SmallButton(), not possible currently because of DC.CursorPosPrevLine ImGuiButtonFlags_NoKeyModifiers = 1 << 16, // disable mouse interaction if a key modifier is held ImGuiButtonFlags_NoHoldingActiveId = 1 << 17, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only) @@ -1146,10 +1134,7 @@ enum ImGuiNextWindowDataFlags_ ImGuiNextWindowDataFlags_HasSizeConstraint = 1 << 4, ImGuiNextWindowDataFlags_HasFocus = 1 << 5, ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6, - ImGuiNextWindowDataFlags_HasScroll = 1 << 7, - ImGuiNextWindowDataFlags_HasViewport = 1 << 8, - ImGuiNextWindowDataFlags_HasDock = 1 << 9, - ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10 + ImGuiNextWindowDataFlags_HasScroll = 1 << 7 }; // Storage for SetNexWindow** functions @@ -1159,21 +1144,16 @@ struct ImGuiNextWindowData ImGuiCond PosCond; ImGuiCond SizeCond; ImGuiCond CollapsedCond; - ImGuiCond DockCond; ImVec2 PosVal; ImVec2 PosPivotVal; ImVec2 SizeVal; ImVec2 ContentSizeVal; ImVec2 ScrollVal; - bool PosUndock; bool CollapsedVal; ImRect SizeConstraintRect; ImGuiSizeCallback SizeCallback; void* SizeCallbackUserData; float BgAlphaVal; // Override background alpha - ImGuiID ViewportId; - ImGuiID DockId; - ImGuiWindowClass WindowClass; ImVec2 MenuBarOffsetMinVal; // (Always on) This is not exposed publicly, so we don't clear it and it doesn't have a corresponding flag (could we? for consistency?) ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); } @@ -1302,137 +1282,7 @@ struct ImGuiOldColumns //----------------------------------------------------------------------------- #ifdef IMGUI_HAS_DOCK - -// Extend ImGuiDockNodeFlags_ -enum ImGuiDockNodeFlagsPrivate_ -{ - // [Internal] - ImGuiDockNodeFlags_DockSpace = 1 << 10, // Local, Saved // A dockspace is a node that occupy space within an existing user window. Otherwise the node is floating and create its own window. - ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local, Saved // The central node has 2 main properties: stay visible when empty, only use "remaining" spaces from its neighbor. - ImGuiDockNodeFlags_NoTabBar = 1 << 12, // Local, Saved // Tab bar is completely unavailable. No triangle in the corner to enable it back. - ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local, Saved // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar) - ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local, Saved // Disable window/docking menu (that one that appears instead of the collapse button) - ImGuiDockNodeFlags_NoCloseButton = 1 << 15, // Local, Saved // - ImGuiDockNodeFlags_NoDocking = 1 << 16, // Local, Saved // Disable any form of docking in this dockspace or individual node. (On a whole dockspace, this pretty much defeat the purpose of using a dockspace at all). Note: when turned on, existing docked nodes will be preserved. - ImGuiDockNodeFlags_NoDockingSplitMe = 1 << 17, // [EXPERIMENTAL] Prevent another window/node from splitting this node. - ImGuiDockNodeFlags_NoDockingSplitOther = 1 << 18, // [EXPERIMENTAL] Prevent this node from splitting another window/node. - ImGuiDockNodeFlags_NoDockingOverMe = 1 << 19, // [EXPERIMENTAL] Prevent another window/node to be docked over this node. - ImGuiDockNodeFlags_NoDockingOverOther = 1 << 20, // [EXPERIMENTAL] Prevent this node to be docked over another window or non-empty node. - ImGuiDockNodeFlags_NoDockingOverEmpty = 1 << 21, // [EXPERIMENTAL] Prevent this node to be docked over an empty node (e.g. DockSpace with no other windows) - ImGuiDockNodeFlags_NoResizeX = 1 << 22, // [EXPERIMENTAL] - ImGuiDockNodeFlags_NoResizeY = 1 << 23, // [EXPERIMENTAL] - ImGuiDockNodeFlags_SharedFlagsInheritMask_ = ~0, - ImGuiDockNodeFlags_NoResizeFlagsMask_ = ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_NoResizeX | ImGuiDockNodeFlags_NoResizeY, - ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResizeFlagsMask_ | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking, - ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace, // When splitting those flags are moved to the inheriting child, never duplicated - ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_NoResizeFlagsMask_ | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking -}; - -// Store the source authority (dock node vs window) of a field -enum ImGuiDataAuthority_ -{ - ImGuiDataAuthority_Auto, - ImGuiDataAuthority_DockNode, - ImGuiDataAuthority_Window -}; - -enum ImGuiDockNodeState -{ - ImGuiDockNodeState_Unknown, - ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow, - ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing, - ImGuiDockNodeState_HostWindowVisible -}; - -// sizeof() 156~192 -struct IMGUI_API ImGuiDockNode -{ - ImGuiID ID; - ImGuiDockNodeFlags SharedFlags; // (Write) Flags shared by all nodes of a same dockspace hierarchy (inherited from the root node) - ImGuiDockNodeFlags LocalFlags; // (Write) Flags specific to this node - ImGuiDockNodeFlags LocalFlagsInWindows; // (Write) Flags specific to this node, applied from windows - ImGuiDockNodeFlags MergedFlags; // (Read) Effective flags (== SharedFlags | LocalFlagsInNode | LocalFlagsInWindows) - ImGuiDockNodeState State; - ImGuiDockNode* ParentNode; - ImGuiDockNode* ChildNodes[2]; // [Split node only] Child nodes (left/right or top/bottom). Consider switching to an array. - ImVector Windows; // Note: unordered list! Iterate TabBar->Tabs for user-order. - ImGuiTabBar* TabBar; - ImVec2 Pos; // Current position - ImVec2 Size; // Current size - ImVec2 SizeRef; // [Split node only] Last explicitly written-to size (overridden when using a splitter affecting the node), used to calculate Size. - ImGuiAxis SplitAxis; // [Split node only] Split axis (X or Y) - ImGuiWindowClass WindowClass; // [Root node only] - - ImGuiWindow* HostWindow; - ImGuiWindow* VisibleWindow; // Generally point to window which is ID is == SelectedTabID, but when CTRL+Tabbing this can be a different window. - ImGuiDockNode* CentralNode; // [Root node only] Pointer to central node. - ImGuiDockNode* OnlyNodeWithWindows; // [Root node only] Set when there is a single visible node within the hierarchy. - int LastFrameAlive; // Last frame number the node was updated or kept alive explicitly with DockSpace() + ImGuiDockNodeFlags_KeepAliveOnly - int LastFrameActive; // Last frame number the node was updated. - int LastFrameFocused; // Last frame number the node was focused. - ImGuiID LastFocusedNodeId; // [Root node only] Which of our child docking node (any ancestor in the hierarchy) was last focused. - ImGuiID SelectedTabId; // [Leaf node only] Which of our tab/window is selected. - ImGuiID WantCloseTabId; // [Leaf node only] Set when closing a specific tab/window. - ImGuiDataAuthority AuthorityForPos :3; - ImGuiDataAuthority AuthorityForSize :3; - ImGuiDataAuthority AuthorityForViewport :3; - bool IsVisible :1; // Set to false when the node is hidden (usually disabled as it has no active window) - bool IsFocused :1; - bool HasCloseButton :1; // Provide space for a close button (if any of the docked window has one). Note that button may be hidden on window without one. - bool HasWindowMenuButton :1; - bool WantCloseAll :1; // Set when closing all tabs at once. - bool WantLockSizeOnce :1; - bool WantMouseMove :1; // After a node extraction we need to transition toward moving the newly created host window - bool WantHiddenTabBarUpdate :1; - bool WantHiddenTabBarToggle :1; - bool MarkedForPosSizeWrite :1; // Update by DockNodeTreeUpdatePosSize() write-filtering - - ImGuiDockNode(ImGuiID id); - ~ImGuiDockNode(); - bool IsRootNode() const { return ParentNode == NULL; } - bool IsDockSpace() const { return (MergedFlags & ImGuiDockNodeFlags_DockSpace) != 0; } - bool IsFloatingNode() const { return ParentNode == NULL && (MergedFlags & ImGuiDockNodeFlags_DockSpace) == 0; } - bool IsCentralNode() const { return (MergedFlags & ImGuiDockNodeFlags_CentralNode) != 0; } - bool IsHiddenTabBar() const { return (MergedFlags & ImGuiDockNodeFlags_HiddenTabBar) != 0; } // Hidden tab bar can be shown back by clicking the small triangle - bool IsNoTabBar() const { return (MergedFlags & ImGuiDockNodeFlags_NoTabBar) != 0; } // Never show a tab bar - bool IsSplitNode() const { return ChildNodes[0] != NULL; } - bool IsLeafNode() const { return ChildNodes[0] == NULL; } - bool IsEmpty() const { return ChildNodes[0] == NULL && Windows.Size == 0; } - ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } - - void SetLocalFlags(ImGuiDockNodeFlags flags) { LocalFlags = flags; UpdateMergedFlags(); } - void UpdateMergedFlags() { MergedFlags = SharedFlags | LocalFlags | LocalFlagsInWindows; } -}; - -// List of colors that are stored at the time of Begin() into Docked Windows. -// We currently store the packed colors in a simple array window->DockStyle.Colors[]. -// A better solution may involve appending into a log of colors in ImGuiContext + store offsets into those arrays in ImGuiWindow, -// but it would be more complex as we'd need to double-buffer both as e.g. drop target may refer to window from last frame. -enum ImGuiWindowDockStyleCol -{ - ImGuiWindowDockStyleCol_Text, - ImGuiWindowDockStyleCol_Tab, - ImGuiWindowDockStyleCol_TabHovered, - ImGuiWindowDockStyleCol_TabActive, - ImGuiWindowDockStyleCol_TabUnfocused, - ImGuiWindowDockStyleCol_TabUnfocusedActive, - ImGuiWindowDockStyleCol_COUNT -}; - -struct ImGuiWindowDockStyle -{ - ImU32 Colors[ImGuiWindowDockStyleCol_COUNT]; -}; - -struct ImGuiDockContext -{ - ImGuiStorage Nodes; // Map ID -> ImGuiDockNode*: Active nodes - ImVector Requests; - ImVector NodesSettings; - bool WantFullRebuild; - ImGuiDockContext() { memset(this, 0, sizeof(*this)); } -}; - +// #endif // #ifdef IMGUI_HAS_DOCK //----------------------------------------------------------------------------- @@ -1443,31 +1293,18 @@ struct ImGuiDockContext // Every instance of ImGuiViewport is in fact a ImGuiViewportP. struct ImGuiViewportP : public ImGuiViewport { - int Idx; - int LastFrameActive; // Last frame number this viewport was activated by a window - int LastFrontMostStampCount;// Last stamp number from when a window hosted by this viewport was made front-most (by comparing this value between two viewport we have an implicit viewport z-order - ImGuiID LastNameHash; - ImVec2 LastPos; - float Alpha; // Window opacity (when dragging dockable windows/viewports we make them transparent) - float LastAlpha; - short PlatformMonitor; - bool PlatformWindowCreated; - ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set) int DrawListsLastFrame[2]; // Last frame number the background (0) and foreground (1) draw lists were used ImDrawList* DrawLists[2]; // Convenience background (0) and foreground (1) draw lists. We use them to draw software mouser cursor when io.MouseDrawCursor is set and to draw most debug overlays. ImDrawData DrawDataP; ImDrawDataBuilder DrawDataBuilder; - ImVec2 LastPlatformPos; - ImVec2 LastPlatformSize; - ImVec2 LastRendererSize; + ImVec2 WorkOffsetMin; // Work Area: Offset from Pos to top-left corner of Work Area. Generally (0,0) or (0,+main_menu_bar_height). Work Area is Full Area but without menu-bars/status-bars (so WorkArea always fit inside Pos/Size!) ImVec2 WorkOffsetMax; // Work Area: Offset from Pos+Size to bottom-right corner of Work Area. Generally (0,0) or (0,-status_bar_height). ImVec2 BuildWorkOffsetMin; // Work Area: Offset being built during current frame. Generally >= 0.0f. ImVec2 BuildWorkOffsetMax; // Work Area: Offset being built during current frame. Generally <= 0.0f. - ImGuiViewportP() { Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } - ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } - void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; } + ImGuiViewportP() { DrawListsLastFrame[0] = DrawListsLastFrame[1] = -1; DrawLists[0] = DrawLists[1] = NULL; } + ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } // Calculate work rect pos/size given a set of offset (we have 1 pair of offset for rect locked from last frame data, and 1 pair for currently building rect) ImVec2 CalcWorkRectPos(const ImVec2& off_min) const { return ImVec2(Pos.x + off_min.x, Pos.y + off_min.y); } @@ -1490,17 +1327,12 @@ struct ImGuiViewportP : public ImGuiViewport struct ImGuiWindowSettings { ImGuiID ID; - ImVec2ih Pos; // NB: Settings position are stored RELATIVE to the viewport! Whereas runtime ones are absolute positions. + ImVec2ih Pos; ImVec2ih Size; - ImVec2ih ViewportPos; - ImGuiID ViewportId; - ImGuiID DockId; // ID of last known DockNode (even if the DockNode is invisible because it has only 1 active window), or 0 if none. - ImGuiID ClassId; // ID of window class if specified - short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. bool Collapsed; bool WantApply; // Set when loaded from .ini data (to enable merging/loading .ini data into an already running context) - ImGuiWindowSettings() { memset(this, 0, sizeof(*this)); DockOrder = -1; } + ImGuiWindowSettings() { memset(this, 0, sizeof(*this)); } char* GetName() { return (char*)(this + 1); } }; @@ -1530,7 +1362,6 @@ struct ImGuiMetricsConfig bool ShowTablesRects; bool ShowDrawCmdMesh; bool ShowDrawCmdBoundingBoxes; - bool ShowDockingNodes; int ShowWindowsRectsType; int ShowTablesRectsType; @@ -1541,7 +1372,6 @@ struct ImGuiMetricsConfig ShowTablesRects = false; ShowDrawCmdMesh = true; ShowDrawCmdBoundingBoxes = true; - ShowDockingNodes = false; ShowWindowsRectsType = -1; ShowTablesRectsType = -1; } @@ -1589,10 +1419,7 @@ struct ImGuiContext bool Initialized; bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it. ImGuiIO IO; - ImGuiPlatformIO PlatformIO; ImGuiStyle Style; - ImGuiConfigFlags ConfigFlagsCurrFrame; // = g.IO.ConfigFlags at the time of NewFrame() - ImGuiConfigFlags ConfigFlagsLastFrame; ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back() float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window. float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height. @@ -1600,7 +1427,6 @@ struct ImGuiContext double Time; int FrameCount; int FrameCountEnded; - int FrameCountPlatformEnded; int FrameCountRendered; bool WithinFrameScope; // Set by NewFrame(), cleared by EndFrame() bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed @@ -1621,8 +1447,7 @@ struct ImGuiContext ImGuiWindow* CurrentWindow; // Window being drawn into ImGuiWindow* HoveredWindow; // Window the mouse is hovering. Will typically catch mouse inputs. ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set. - ImGuiDockNode* HoveredDockNode; // Hovered dock node. - ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindowDockTree. + ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actual window that is moved is generally MovingWindow->RootWindow. ImGuiWindow* WheelingWindow; // Track the window we started mouse-wheeling on. Until a timer elapse or mouse has moved, generally keep scrolling the same window even if during the course of scrolling the mouse ends up hovering a child window. ImVec2 WheelingWindowRefMousePos; float WheelingWindowTimer; @@ -1677,14 +1502,7 @@ struct ImGuiContext ImVectorBeginPopupStack; // Which level of BeginPopup() we are in (reset every frame) // Viewports - ImVector Viewports; // Active viewports (always 1+, and generally 1 unless multi-viewports are enabled). Each viewports hold their copy of ImDrawData. - float CurrentDpiScale; // == CurrentViewport->DpiScale - ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport() - ImGuiViewportP* MouseViewport; - ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag. - ImGuiID PlatformLastFocusedViewportId; - ImGuiPlatformMonitor FallbackMonitor; // Virtual monitor used as fallback if backend doesn't provide monitor information. - int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter + ImVector Viewports; // Active viewports (Size==1 in 'master' branch). Each viewports hold their copy of ImDrawData. // Gamepad/keyboard Navigation ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' @@ -1795,6 +1613,7 @@ struct ImGuiContext bool DragCurrentAccumDirty; float DragCurrentAccum; // Accumulator for dragging modification. Always high-precision, not rounded by end-user precision settings float DragSpeedDefaultRatio; // If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio + float DisabledAlphaBackup; // Backup for style.Alpha for BeginDisabled() float ScrollbarClickDeltaToGrabCenter; // Distance between mouse and center of grab box, normalized in parent space. Use storage? int TooltipOverrideCount; float TooltipSlowDelay; // Time before slow tooltips appears (FIXME: This is temporary until we merge in tooltip timer+priority work) @@ -1804,13 +1623,8 @@ struct ImGuiContext // Platform support ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor ImVec2 PlatformImeLastPos; - ImGuiViewportP* PlatformImePosViewport; char PlatformLocaleDecimalPoint; // '.' or *localeconv()->decimal_point - // Extensions - // FIXME: We could provide an API to register one slot in an array held in ImGuiContext? - ImGuiDockContext DockContext; - // Settings bool SettingsLoaded; float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero @@ -1852,14 +1666,13 @@ struct ImGuiContext ImGuiContext(ImFontAtlas* shared_font_atlas) { Initialized = false; - ConfigFlagsCurrFrame = ConfigFlagsLastFrame = ImGuiConfigFlags_None; FontAtlasOwnedByContext = shared_font_atlas ? false : true; Font = NULL; FontSize = FontBaseSize = 0.0f; IO.Fonts = shared_font_atlas ? shared_font_atlas : IM_NEW(ImFontAtlas)(); Time = 0.0f; FrameCount = 0; - FrameCountEnded = FrameCountPlatformEnded = FrameCountRendered = -1; + FrameCountEnded = FrameCountRendered = -1; WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; GcCompactAll = false; TestEngineHookItems = false; @@ -1870,7 +1683,6 @@ struct ImGuiContext CurrentWindow = NULL; HoveredWindow = NULL; HoveredWindowUnderMovingWindow = NULL; - HoveredDockNode = NULL; MovingWindow = NULL; WheelingWindow = NULL; WheelingWindowTimer = 0.0f; @@ -1906,12 +1718,6 @@ struct ImGuiContext CurrentItemFlags = ImGuiItemFlags_None; - CurrentDpiScale = 0.0f; - CurrentViewport = NULL; - MouseViewport = MouseLastHoveredViewport = NULL; - PlatformLastFocusedViewportId = 0; - ViewportFrontMostStampCount = 0; - NavWindow = NULL; NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0; NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; @@ -1975,12 +1781,12 @@ struct ImGuiContext DragCurrentAccumDirty = false; DragCurrentAccum = 0.0f; DragSpeedDefaultRatio = 1.0f / 100.0f; + DisabledAlphaBackup = 0.0f; ScrollbarClickDeltaToGrabCenter = 0.0f; TooltipOverrideCount = 0; TooltipSlowDelay = 0.50f; PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX); - PlatformImePosViewport = 0; PlatformLocaleDecimalPoint = '.'; SettingsLoaded = false; @@ -2067,12 +1873,7 @@ struct IMGUI_API ImGuiWindow { char* Name; // Window name, owned by the window. ImGuiID ID; // == ImHashStr(Name) - ImGuiWindowFlags Flags, FlagsPreviousFrame; // See enum ImGuiWindowFlags_ - ImGuiWindowClass WindowClass; // Advanced users only. Set with SetNextWindowClass() - ImGuiViewportP* Viewport; // Always set in Begin(), only inactive windows may have a NULL value here - ImGuiID ViewportId; // We backup the viewport id (since the viewport may disappear or never be created if the window is inactive) - ImVec2 ViewportPos; // We backup the viewport position (since the viewport may disappear or never be created if the window is inactive) - int ViewportAllowPlatformMonitorExtend; // Reset to -1 every frame (index is guaranteed to be valid between NewFrame..EndFrame), only used in the Appearing frame of a tooltip/popup to enforce clamping to a given monitor + ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_ ImVec2 Pos; // Position (always rounded-up to nearest pixel) ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) ImVec2 SizeFull; // Size when non collapsed @@ -2092,7 +1893,6 @@ struct IMGUI_API ImGuiWindow ImVec2 ScrollTargetEdgeSnapDist; // 0.0f = no snapping, >0.0f snapping threshold ImVec2 ScrollbarSizes; // Size taken by each scrollbars on their smaller axis. Pay attention! ScrollbarSizes.x == width of the vertical scrollbar, ScrollbarSizes.y = height of the horizontal scrollbar. bool ScrollbarX, ScrollbarY; // Are scrollbars visible? - bool ViewportOwned; bool Active; // Set to true on Begin(), unless Collapsed bool WasActive; bool WriteAccessed; // Set to true when any widget access the current window @@ -2120,7 +1920,6 @@ struct IMGUI_API ImGuiWindow ImGuiCond SetWindowPosAllowFlags : 8; // store acceptable condition flags for SetNextWindowPos() use. ImGuiCond SetWindowSizeAllowFlags : 8; // store acceptable condition flags for SetNextWindowSize() use. ImGuiCond SetWindowCollapsedAllowFlags : 8; // store acceptable condition flags for SetNextWindowCollapsed() use. - ImGuiCond SetWindowDockAllowFlags : 8; // store acceptable condition flags for SetNextWindowDock() use. ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size) ImVec2 SetWindowPosPivot; // store window pivot for positioning. ImVec2(0, 0) when positioning from top-left corner; ImVec2(0.5f, 0.5f) for centering; ImVec2(1, 1) for bottom right. @@ -2140,20 +1939,17 @@ struct IMGUI_API ImGuiWindow ImVec2ih HitTestHoleOffset; int LastFrameActive; // Last frame number the window was Active. - int LastFrameJustFocused; // Last frame number the window was made Focused. float LastTimeActive; // Last timestamp the window was Active (using float as we don't need high precision there) float ItemWidthDefault; ImGuiStorage StateStorage; ImVector ColumnsStorage; float FontWindowScale; // User scale multiplier per-window, via SetWindowFontScale() - float FontDpiScale; int SettingsOffset; // Offset into SettingsWindows[] (offsets are always valid as we only grow the array from the back) ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) ImDrawList DrawListInst; ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL. - ImGuiWindow* RootWindow; // Point to ourself or first ancestor that is not a child window. Doesn't cross through dock nodes. We use this so IsWindowFocused() can behave consistently regardless of docking state. - ImGuiWindow* RootWindowDockTree; // Point to ourself or first ancestor that is not a child window. Cross through dock nodes. + ImGuiWindow* RootWindow; // Point to ourself or first ancestor that is not a child window == Top-level window. ImGuiWindow* RootWindowForTitleBarHighlight; // Point to ourself or first ancestor which will display TitleBgActive color when this window is active. ImGuiWindow* RootWindowForNav; // Point to ourself or first ancestor which doesn't have the NavFlattened flag. @@ -2165,19 +1961,6 @@ struct IMGUI_API ImGuiWindow int MemoryDrawListVtxCapacity; bool MemoryCompacted; // Set when window extraneous data have been garbage collected - // Docking - bool DockIsActive :1; // When docking artifacts are actually visible. When this is set, DockNode is guaranteed to be != NULL. ~~ (DockNode != NULL) && (DockNode->Windows.Size > 1). - bool DockNodeIsVisible :1; - bool DockTabIsVisible :1; // Is our window visible this frame? ~~ is the corresponding tab selected? - bool DockTabWantClose :1; - short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. - ImGuiWindowDockStyle DockStyle; - ImGuiDockNode* DockNode; // Which node are we docked into. Important: Prefer testing DockIsActive in many cases as this will still be set when the dock node is hidden. - ImGuiDockNode* DockNodeAsHost; // Which node are we owning (for parent windows) - ImGuiID DockId; // Backup of last valid DockNode->ID, so single window remember their dock node id even when they are not bound any more - ImGuiItemStatusFlags DockTabItemStatusFlags; - ImRect DockTabItemRect; - public: ImGuiWindow(ImGuiContext* context, const char* name); ~ImGuiWindow(); @@ -2192,7 +1975,7 @@ public: // We don't use g.FontSize because the window may be != g.CurrentWidow. ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); } - float CalcFontSize() const { ImGuiContext& g = *GImGui; float scale = g.FontBaseSize * FontWindowScale * FontDpiScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; } + float CalcFontSize() const { ImGuiContext& g = *GImGui; float scale = g.FontBaseSize * FontWindowScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; } float TitleBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; } ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); } float MenuBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; } @@ -2216,17 +1999,14 @@ enum ImGuiTabItemFlagsPrivate_ { ImGuiTabItemFlags_SectionMask_ = ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing, ImGuiTabItemFlags_NoCloseButton = 1 << 20, // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout) - ImGuiTabItemFlags_Button = 1 << 21, // Used by TabItemButton, change the tab item behavior to mimic a button - ImGuiTabItemFlags_Unsorted = 1 << 22, // [Docking] Trailing tabs with the _Unsorted flag will be sorted based on the DockOrder of their Window. - ImGuiTabItemFlags_Preview = 1 << 23 // [Docking] Display tab shape for docking preview (height is adjusted slightly to compensate for the yet missing tab bar) + ImGuiTabItemFlags_Button = 1 << 21 // Used by TabItemButton, change the tab item behavior to mimic a button }; -// Storage for one active tab item (sizeof() 48 bytes) +// Storage for one active tab item (sizeof() 40 bytes) struct ImGuiTabItem { ImGuiID ID; ImGuiTabItemFlags Flags; - ImGuiWindow* Window; // When TabItem is part of a DockNode's TabBar, we hold on to a window. int LastFrameVisible; int LastFrameSelected; // This allows us to infer an ordered list of the last activated tabs with little maintenance float Offset; // Position relative to beginning of tab @@ -2241,7 +2021,7 @@ struct ImGuiTabItem }; // Storage for a tab bar (sizeof() 152 bytes) -struct IMGUI_API ImGuiTabBar +struct ImGuiTabBar { ImVector Tabs; ImGuiTabBarFlags Flags; @@ -2279,8 +2059,6 @@ struct IMGUI_API ImGuiTabBar int GetTabOrder(const ImGuiTabItem* tab) const { return Tabs.index_from_ptr(tab); } const char* GetTabName(const ImGuiTabItem* tab) const { - if (tab->Window) - return tab->Window->Name; IM_ASSERT(tab->NameOffset != -1 && tab->NameOffset < TabsNames.Buf.Size); return TabsNames.Buf.Data + tab->NameOffset; } @@ -2575,7 +2353,9 @@ namespace ImGui // Fonts, drawing IMGUI_API void SetCurrentFont(ImFont* font); inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; } - inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { return GetForegroundDrawList(window->Viewport); } + inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { IM_UNUSED(window); return GetForegroundDrawList(); } // This seemingly unnecessary wrapper simplifies compatibility between the 'master' and 'docking' branches. + IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. + IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. // Init IMGUI_API void Initialize(ImGuiContext* context); @@ -2584,7 +2364,6 @@ namespace ImGui // NewFrame IMGUI_API void UpdateHoveredWindowAndCaptureFlags(); IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window); - IMGUI_API void StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* node, bool undock_floating_node); IMGUI_API void UpdateMouseMovingWindowNewFrame(); IMGUI_API void UpdateMouseMovingWindowEndFrame(); @@ -2593,13 +2372,6 @@ namespace ImGui IMGUI_API void RemoveContextHook(ImGuiContext* context, ImGuiID hook_to_remove); IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type); - // Viewports - IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos); - IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale); - IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport); - IMGUI_API void SetCurrentViewport(ImGuiWindow* window, ImGuiViewportP* viewport); - IMGUI_API const ImGuiPlatformMonitor* GetViewportPlatformMonitor(ImGuiViewport* viewport); - // Settings IMGUI_API void MarkIniSettingsDirty(); IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window); @@ -2640,7 +2412,6 @@ namespace ImGui IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); IMGUI_API void ItemFocusable(ImGuiWindow* window, ImGuiID id); IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged); - IMGUI_API void SetLastItemData(ImGuiID item_id, ImGuiItemFlags in_flags, ImGuiItemStatusFlags status_flags, const ImRect& item_rect); IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h); IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x); IMGUI_API void PushMultiItemsWidths(int components, float width_full); @@ -2651,8 +2422,6 @@ namespace ImGui // Parameter stacks IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); IMGUI_API void PopItemFlag(); - IMGUI_API void PushDisabled(bool disabled = true); - IMGUI_API void PopDisabled(); #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS // If you have old/custom copy-and-pasted widgets that used FocusableItemRegister(): @@ -2724,55 +2493,6 @@ namespace ImGui inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } IMGUI_API ImGuiKeyModFlags GetMergedKeyModFlags(); - // Docking - // (some functions are only declared in imgui.cpp, see Docking section) - IMGUI_API void DockContextInitialize(ImGuiContext* ctx); - IMGUI_API void DockContextShutdown(ImGuiContext* ctx); - IMGUI_API void DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_settings_refs); // Use root_id==0 to clear all - IMGUI_API void DockContextRebuildNodes(ImGuiContext* ctx); - IMGUI_API void DockContextNewFrameUpdateUndocking(ImGuiContext* ctx); - IMGUI_API void DockContextNewFrameUpdateDocking(ImGuiContext* ctx); - IMGUI_API ImGuiID DockContextGenNodeID(ImGuiContext* ctx); - IMGUI_API void DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer); - IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window); - IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); - IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos); - IMGUI_API bool DockNodeBeginAmendTabBar(ImGuiDockNode* node); - IMGUI_API void DockNodeEndAmendTabBar(); - inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; } - inline int DockNodeGetDepth(const ImGuiDockNode* node) { int depth = 0; while (node->ParentNode) { node = node->ParentNode; depth++; } return depth; } - inline ImGuiID DockNodeGetWindowMenuButtonId(const ImGuiDockNode* node) { return ImHashStr("#COLLAPSE", 0, node->ID); } - inline ImGuiDockNode* GetWindowDockNode() { ImGuiContext& g = *GImGui; return g.CurrentWindow->DockNode; } - IMGUI_API bool GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window); - IMGUI_API void BeginDocked(ImGuiWindow* window, bool* p_open); - IMGUI_API void BeginDockableDragDropSource(ImGuiWindow* window); - IMGUI_API void BeginDockableDragDropTarget(ImGuiWindow* window); - IMGUI_API void SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond); - - // Docking - Builder function needs to be generally called before the node is used/submitted. - // - The DockBuilderXXX functions are designed to _eventually_ become a public API, but it is too early to expose it and guarantee stability. - // - Do not hold on ImGuiDockNode* pointers! They may be invalidated by any split/merge/remove operation and every frame. - // - To create a DockSpace() node, make sure to set the ImGuiDockNodeFlags_DockSpace flag when calling DockBuilderAddNode(). - // You can create dockspace nodes (attached to a window) _or_ floating nodes (carry its own window) with this API. - // - DockBuilderSplitNode() create 2 child nodes within 1 node. The initial node becomes a parent node. - // - If you intend to split the node immediately after creation using DockBuilderSplitNode(), make sure - // to call DockBuilderSetNodeSize() beforehand. If you don't, the resulting split sizes may not be reliable. - // - Call DockBuilderFinish() after you are done. - IMGUI_API void DockBuilderDockWindow(const char* window_name, ImGuiID node_id); - IMGUI_API ImGuiDockNode*DockBuilderGetNode(ImGuiID node_id); - inline ImGuiDockNode* DockBuilderGetCentralNode(ImGuiID node_id) { ImGuiDockNode* node = DockBuilderGetNode(node_id); if (!node) return NULL; return DockNodeGetRootNode(node)->CentralNode; } - IMGUI_API ImGuiID DockBuilderAddNode(ImGuiID node_id = 0, ImGuiDockNodeFlags flags = 0); - IMGUI_API void DockBuilderRemoveNode(ImGuiID node_id); // Remove node and all its child, undock all windows - IMGUI_API void DockBuilderRemoveNodeDockedWindows(ImGuiID node_id, bool clear_settings_refs = true); - IMGUI_API void DockBuilderRemoveNodeChildNodes(ImGuiID node_id); // Remove all split/hierarchy. All remaining docked windows will be re-docked to the remaining root node (node_id). - IMGUI_API void DockBuilderSetNodePos(ImGuiID node_id, ImVec2 pos); - IMGUI_API void DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size); - IMGUI_API ImGuiID DockBuilderSplitNode(ImGuiID node_id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir); // Create 2 child nodes in this parent node. - IMGUI_API void DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs); - IMGUI_API void DockBuilderCopyNode(ImGuiID src_node_id, ImGuiID dst_node_id, ImVector* out_node_remap_pairs); - IMGUI_API void DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name); - IMGUI_API void DockBuilderFinish(ImGuiID node_id); - // Drag and Drop IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); IMGUI_API void ClearDragDrop(); @@ -2842,16 +2562,14 @@ namespace ImGui IMGUI_API ImGuiTableSettings* TableSettingsFindByID(ImGuiID id); // Tab Bars - IMGUI_API bool BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags, ImGuiDockNode* dock_node); + IMGUI_API bool BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& bb, ImGuiTabBarFlags flags); IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id); - IMGUI_API ImGuiTabItem* TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar); - IMGUI_API void TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGuiWindow* window); IMGUI_API void TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id); IMGUI_API void TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); IMGUI_API void TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int offset); IMGUI_API void TabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, ImVec2 mouse_pos); IMGUI_API bool TabBarProcessReorder(ImGuiTabBar* tab_bar); - IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window); + IMGUI_API bool TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags); IMGUI_API ImVec2 TabItemCalcSize(const char* label, bool has_close_button); IMGUI_API void TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col); IMGUI_API void TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImVec2 frame_padding, const char* label, ImGuiID tab_id, ImGuiID close_button_id, bool is_contents_visible, bool* out_just_closed, bool* out_text_clipped); @@ -2876,7 +2594,6 @@ namespace ImGui IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); - IMGUI_API void RenderArrowDockMenu(ImDrawList* draw_list, ImVec2 p_min, float sz, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding); @@ -2890,7 +2607,7 @@ namespace ImGui IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0); IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos); - IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_node); + IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos); IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0); IMGUI_API void Scrollbar(ImGuiAxis axis); IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* p_scroll_v, float avail_v, float contents_v, ImDrawFlags flags); @@ -2961,8 +2678,7 @@ namespace ImGui IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); IMGUI_API void DebugNodeColumns(ImGuiOldColumns* columns); - IMGUI_API void DebugNodeDockNode(ImGuiDockNode* node, const char* label); - IMGUI_API void DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, const ImDrawList* draw_list, const char* label); + IMGUI_API void DebugNodeDrawList(ImGuiWindow* window, const ImDrawList* draw_list, const char* label); IMGUI_API void DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, const ImDrawList* draw_list, const ImDrawCmd* draw_cmd, bool show_mesh, bool show_aabb); IMGUI_API void DebugNodeFont(ImFont* font); IMGUI_API void DebugNodeStorage(ImGuiStorage* storage, const char* label); diff --git a/3rdparty/dear-imgui/imgui_tables.cpp b/3rdparty/dear-imgui/imgui_tables.cpp index c7223905e..71ac00f6a 100644 --- a/3rdparty/dear-imgui/imgui_tables.cpp +++ b/3rdparty/dear-imgui/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (tables and columns code) /* diff --git a/3rdparty/dear-imgui/imgui_widgets.cpp b/3rdparty/dear-imgui/imgui_widgets.cpp index 82f30c091..7e009ba1b 100644 --- a/3rdparty/dear-imgui/imgui_widgets.cpp +++ b/3rdparty/dear-imgui/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.84 WIP +// dear imgui, v1.84 // (widgets code) /* @@ -497,7 +497,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool flags |= ImGuiButtonFlags_PressedOnDefault_; ImGuiWindow* backup_hovered_window = g.HoveredWindow; - const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindowDockTree == window->RootWindowDockTree; + const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window; if (flatten_hovered_children) g.HoveredWindow = window; @@ -818,8 +818,7 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos) return pressed; } -// The Collapse button also functions as a Dock Menu button. -bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_node) +bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -830,21 +829,16 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_no bool pressed = ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_None); // Render - //bool is_dock_menu = (window->DockNodeAsHost && !window->Collapsed); ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); ImU32 text_col = GetColorU32(ImGuiCol_Text); ImVec2 center = bb.GetCenter(); if (hovered || held) - window->DrawList->AddCircleFilled(center + ImVec2(0,-0.5f), g.FontSize * 0.5f + 1.0f, bg_col, 12); - - if (dock_node) - RenderArrowDockMenu(window->DrawList, bb.Min + g.Style.FramePadding, g.FontSize, text_col); - else - RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f); + window->DrawList->AddCircleFilled(center/*+ ImVec2(0.0f, -0.5f)*/, g.FontSize * 0.5f + 1.0f, bg_col, 12); + RenderArrow(window->DrawList, bb.Min + g.Style.FramePadding, text_col, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f); // Switch to moving the window after mouse is moved beyond the initial drag threshold if (IsItemActive() && IsMouseDragging(0)) - StartMouseMovingWindowOrNode(window, dock_node, true); + StartMouseMovingWindow(window); return pressed; } @@ -3460,7 +3454,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data style.FramePadding.x = style.FramePadding.y; ImGuiButtonFlags button_flags = ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups; if (flags & ImGuiInputTextFlags_ReadOnly) - PushDisabled(true); + BeginDisabled(true); SameLine(0, style.ItemInnerSpacing.x); if (ButtonEx("-", ImVec2(button_size, button_size), button_flags)) { @@ -3474,7 +3468,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data value_changed = true; } if (flags & ImGuiInputTextFlags_ReadOnly) - PopDisabled(); + EndDisabled(); const char* label_end = FindRenderedTextEnd(label); if (label != label_end) @@ -4709,10 +4703,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.) if (!is_readonly) - { - g.PlatformImePos = ImVec2(cursor_screen_pos.x - 1, cursor_screen_pos.y - g.FontSize); - g.PlatformImePosViewport = window->Viewport; - } + g.PlatformImePos = ImVec2(cursor_screen_pos.x - 1.0f, cursor_screen_pos.y - g.FontSize); } } else @@ -6187,7 +6178,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl const bool disabled_global = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0; if (disabled_item && !disabled_global) // Only testing this as an optimization - PushDisabled(true); + BeginDisabled(true); // FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only, // which would be advantageous since most selectable are not selected. @@ -6260,10 +6251,10 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl CloseCurrentPopup(); if (disabled_item && !disabled_global) - PopDisabled(); + EndDisabled(); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); - return pressed; + return pressed; //-V1020 } bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags, const ImVec2& size_arg) @@ -6744,10 +6735,10 @@ bool ImGui::BeginViewportSideBar(const char* name, ImGuiViewport* viewport_p, Im IM_ASSERT(dir != ImGuiDir_None); ImGuiWindow* bar_window = FindWindowByName(name); - ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)(viewport_p ? viewport_p : GetMainViewport()); if (bar_window == NULL || bar_window->BeginCount == 0) { // Calculate and set window size/position + ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)(viewport_p ? viewport_p : GetMainViewport()); ImRect avail_rect = viewport->GetBuildWorkRect(); ImGuiAxis axis = (dir == ImGuiDir_Up || dir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X; ImVec2 pos = avail_rect.Min; @@ -6765,8 +6756,7 @@ bool ImGui::BeginViewportSideBar(const char* name, ImGuiViewport* viewport_p, Im viewport->BuildWorkOffsetMax[axis] -= axis_size; } - window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking; - SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set. + window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint bool is_open = Begin(name, NULL, window_flags); @@ -6780,9 +6770,6 @@ bool ImGui::BeginMainMenuBar() ImGuiContext& g = *GImGui; ImGuiViewportP* viewport = (ImGuiViewportP*)(void*)GetMainViewport(); - // Notify of viewport change so GetFrameHeight() can be accurate in case of DPI change - SetCurrentViewport(NULL, viewport); - // For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set. // FIXME: This could be generalized as an opt-in way to clamp window->DC.CursorStartPos to avoid SafeArea? // FIXME: Consider removing support for safe area down the line... it's messy. Nowadays consoles have support for TV calibration in OS settings. @@ -6856,7 +6843,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) ImVec2 popup_pos, pos = window->DC.CursorPos; PushID(label); if (!enabled) - PushDisabled(); + BeginDisabled(); const ImGuiMenuColumns* offsets = &window->DC.MenuColumns; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { @@ -6889,7 +6876,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) RenderArrow(window->DrawList, pos + ImVec2(offsets->OffsetMark + extra_w + g.FontSize * 0.30f, 0.0f), GetColorU32(ImGuiCol_Text), ImGuiDir_Right); } if (!enabled) - PopDisabled(); + EndDisabled(); const bool hovered = (g.HoveredId == id) && enabled; if (menuset_is_open) @@ -7022,7 +7009,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut bool pressed; PushID(label); if (!enabled) - PushDisabled(true); + BeginDisabled(true); const ImGuiSelectableFlags flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_SetNavIdOnHover; const ImGuiMenuColumns* offsets = &window->DC.MenuColumns; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) @@ -7062,7 +7049,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut } IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0)); if (!enabled) - PopDisabled(); + EndDisabled(); PopID(); return pressed; @@ -7094,7 +7081,6 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, // - TabBarCalcTabID() [Internal] // - TabBarCalcMaxTabWidth() [Internal] // - TabBarFindTabById() [Internal] -// - TabBarAddTab() [Internal] // - TabBarRemoveTab() [Internal] // - TabBarCloseTab() [Internal] // - TabBarScrollClamp() [Internal] @@ -7116,7 +7102,7 @@ struct ImGuiTabBarSection namespace ImGui { static void TabBarLayout(ImGuiTabBar* tab_bar); - static ImU32 TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window); + static ImU32 TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label); static float TabBarCalcMaxTabWidth(); static float TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling); static void TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiID tab_id, ImGuiTabBarSection* sections); @@ -7179,10 +7165,10 @@ bool ImGui::BeginTabBar(const char* str_id, ImGuiTabBarFlags flags) ImGuiTabBar* tab_bar = g.TabBars.GetOrAddByKey(id); ImRect tab_bar_bb = ImRect(window->DC.CursorPos.x, window->DC.CursorPos.y, window->WorkRect.Max.x, window->DC.CursorPos.y + g.FontSize + g.Style.FramePadding.y * 2); tab_bar->ID = id; - return BeginTabBarEx(tab_bar, tab_bar_bb, flags | ImGuiTabBarFlags_IsFocused, NULL); + return BeginTabBarEx(tab_bar, tab_bar_bb, flags | ImGuiTabBarFlags_IsFocused); } -bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImGuiTabBarFlags flags, ImGuiDockNode* dock_node) +bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImGuiTabBarFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -7207,7 +7193,7 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG // Ensure correct ordering when toggling ImGuiTabBarFlags_Reorderable flag, or when a new tab was added while being not reorderable if ((flags & ImGuiTabBarFlags_Reorderable) != (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) || (tab_bar->TabsAddedNew && !(flags & ImGuiTabBarFlags_Reorderable))) - if (tab_bar->Tabs.Size > 1 && (flags & ImGuiTabBarFlags_DockNode) == 0) // FIXME: TabBar with DockNode can now be hybrid + if (tab_bar->Tabs.Size > 1) ImQsort(tab_bar->Tabs.Data, tab_bar->Tabs.Size, sizeof(ImGuiTabItem), TabItemComparerByBeginOrder); tab_bar->TabsAddedNew = false; @@ -7233,13 +7219,6 @@ bool ImGui::BeginTabBarEx(ImGuiTabBar* tab_bar, const ImRect& tab_bar_bb, ImG // Draw separator const ImU32 col = GetColorU32((flags & ImGuiTabBarFlags_IsFocused) ? ImGuiCol_TabActive : ImGuiCol_TabUnfocusedActive); const float y = tab_bar->BarRect.Max.y - 1.0f; - if (dock_node != NULL) - { - const float separator_min_x = dock_node->Pos.x + window->WindowBorderSize; - const float separator_max_x = dock_node->Pos.x + dock_node->Size.x - window->WindowBorderSize; - window->DrawList->AddLine(ImVec2(separator_min_x, y), ImVec2(separator_max_x, y), col, 1.0f); - } - else { const float separator_min_x = tab_bar->BarRect.Min.x - IM_FLOOR(window->WindowPadding.x * 0.5f); const float separator_max_x = tab_bar->BarRect.Max.x + IM_FLOOR(window->WindowPadding.x * 0.5f); @@ -7390,7 +7369,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet, // and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window. const char* tab_name = tab_bar->GetTabName(tab); - const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0; + const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) ? false : true; tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x; int section_n = TabItemGetSectionIdx(tab); @@ -7469,7 +7448,6 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) { ImGuiTabItem* tab = &tab_bar->Tabs[section_tab_index + tab_n]; tab->Offset = tab_offset; - tab->NameOffset = -1; tab_offset += tab->Width + (tab_n < section->TabCount - 1 ? g.Style.ItemInnerSpacing.x : 0.0f); } tab_bar->WidthAllTabs += ImMax(section->Width + section->Spacing, 0.0f); @@ -7477,9 +7455,6 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) section_tab_index += section->TabCount; } - // Clear name buffers - tab_bar->TabsNames.Buf.resize(0); - // If we have lost the selected tab, select the next most recently active one if (found_selected_tab_id == false) tab_bar->SelectedTabId = 0; @@ -7490,10 +7465,6 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) tab_bar->VisibleTabId = tab_bar->SelectedTabId; tab_bar->VisibleTabWasSubmitted = false; - // CTRL+TAB can override visible tab temporarily - if (g.NavWindowingTarget != NULL && g.NavWindowingTarget->DockNode && g.NavWindowingTarget->DockNode->TabBar == tab_bar) - tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->ID; - // Update scrolling if (scroll_to_tab_id != 0) TabBarScrollToTab(tab_bar, scroll_to_tab_id, sections); @@ -7515,6 +7486,10 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) tab_bar->ScrollingRectMinX = tab_bar->BarRect.Min.x + sections[0].Width + sections[0].Spacing; tab_bar->ScrollingRectMaxX = tab_bar->BarRect.Max.x - sections[2].Width - sections[1].Spacing; + // Clear name buffers + if ((tab_bar->Flags & ImGuiTabBarFlags_DockNode) == 0) + tab_bar->TabsNames.Buf.resize(0); + // Actual layout in host window (we don't do it in BeginTabBar() so as not to waste an extra frame) ImGuiWindow* window = g.CurrentWindow; window->DC.CursorPos = tab_bar->BarRect.Min; @@ -7522,13 +7497,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) window->DC.IdealMaxPos.x = ImMax(window->DC.IdealMaxPos.x, tab_bar->BarRect.Min.x + tab_bar->WidthAllTabsIdeal); } -// Dockable uses Name/ID in the global namespace. Non-dockable items use the ID stack. -static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, ImGuiWindow* docked_window) +// Dockables uses Name/ID in the global namespace. Non-dockable items use the ID stack. +static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label) { - if (docked_window != NULL) + if (tab_bar->Flags & ImGuiTabBarFlags_DockNode) { - IM_UNUSED(tab_bar); - IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_DockNode); ImGuiID id = ImHashStr(label); KeepAliveID(id); return id; @@ -7555,41 +7528,6 @@ ImGuiTabItem* ImGui::TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id) return NULL; } -// FIXME: See references to #2304 in TODO.txt -ImGuiTabItem* ImGui::TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar) -{ - ImGuiTabItem* most_recently_selected_tab = NULL; - for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) - { - ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; - if (most_recently_selected_tab == NULL || most_recently_selected_tab->LastFrameSelected < tab->LastFrameSelected) - if (tab->Window && tab->Window->WasActive) - most_recently_selected_tab = tab; - } - return most_recently_selected_tab; -} - -// The purpose of this call is to register tab in advance so we can control their order at the time they appear. -// Otherwise calling this is unnecessary as tabs are appending as needed by the BeginTabItem() function. -void ImGui::TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGuiWindow* window) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(TabBarFindTabByID(tab_bar, window->ID) == NULL); - IM_ASSERT(g.CurrentTabBar != tab_bar); // Can't work while the tab bar is active as our tab doesn't have an X offset yet, in theory we could/should test something like (tab_bar->CurrFrameVisible < g.FrameCount) but we'd need to solve why triggers the commented early-out assert in BeginTabBarEx() (probably dock node going from implicit to explicit in same frame) - - if (!window->HasCloseButton) - tab_flags |= ImGuiTabItemFlags_NoCloseButton; // Set _NoCloseButton immediately because it will be used for first-frame width calculation. - - ImGuiTabItem new_tab; - new_tab.ID = window->ID; - new_tab.Flags = tab_flags; - new_tab.LastFrameVisible = tab_bar->CurrFrameVisible; // Required so BeginTabBar() doesn't ditch the tab - if (new_tab.LastFrameVisible == -1) - new_tab.LastFrameVisible = g.FrameCount - 1; - new_tab.Window = window; // Required so tab bar layout can compute the tab width before tab submission - tab_bar->Tabs.push_back(new_tab); -} - // The *TabId fields be already set by the docking system _before_ the actual TabItem was created, so we clear them regardless. void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) { @@ -7864,9 +7802,9 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f IM_ASSERT_USER_ERROR(tab_bar, "Needs to be called between BeginTabBar() and EndTabBar()!"); return false; } - IM_ASSERT((flags & ImGuiTabItemFlags_Button) == 0); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead! + IM_ASSERT(!(flags & ImGuiTabItemFlags_Button)); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead! - bool ret = TabItemEx(tab_bar, label, p_open, flags, NULL); + bool ret = TabItemEx(tab_bar, label, p_open, flags); if (ret && !(flags & ImGuiTabItemFlags_NoPushId)) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_bar->LastTabItemIdx]; @@ -7907,10 +7845,10 @@ bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags) IM_ASSERT_USER_ERROR(tab_bar != NULL, "Needs to be called between BeginTabBar() and EndTabBar()!"); return false; } - return TabItemEx(tab_bar, label, NULL, flags | ImGuiTabItemFlags_Button | ImGuiTabItemFlags_NoReorder, NULL); + return TabItemEx(tab_bar, label, NULL, flags | ImGuiTabItemFlags_Button | ImGuiTabItemFlags_NoReorder); } -bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) +bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags) { // Layout whole tab bar if not already done if (tab_bar->WantLayout) @@ -7922,7 +7860,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, return false; const ImGuiStyle& style = g.Style; - const ImGuiID id = TabBarCalcTabID(tab_bar, label, docked_window); + const ImGuiID id = TabBarCalcTabID(tab_bar, label); // If the user called us with *p_open == false, we early out and don't render. // We make a call to ItemAdd() so that attempts to use a contextual popup menu with an implicit ID won't use an older ID. @@ -7969,21 +7907,10 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, const bool is_tab_button = (flags & ImGuiTabItemFlags_Button) != 0; tab->LastFrameVisible = g.FrameCount; tab->Flags = flags; - tab->Window = docked_window; // Append name with zero-terminator - // (regular tabs are permitted in a DockNode tab bar, but window tabs not permitted in a non-DockNode tab bar) - if (tab->Window != NULL) - { - IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_DockNode); - tab->NameOffset = -1; - } - else - { - IM_ASSERT(tab->Window == NULL); - tab->NameOffset = (ImS32)tab_bar->TabsNames.size(); - tab_bar->TabsNames.append(label, label + strlen(label) + 1); // Append name _with_ the zero-terminator. - } + tab->NameOffset = (ImS32)tab_bar->TabsNames.size(); + tab_bar->TabsNames.append(label, label + strlen(label) + 1); // Update selected tab if (tab_appearing && (tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs) && tab_bar->NextSelectedTabId == 0) @@ -8001,7 +7928,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, tab_bar->VisibleTabWasSubmitted = true; // On the very first frame of a tab bar we let first tab contents be visible to minimize appearing glitches - if (!tab_contents_visible && tab_bar->SelectedTabId == 0 && tab_bar_appearing && docked_window == NULL) + if (!tab_contents_visible && tab_bar->SelectedTabId == 0 && tab_bar_appearing) if (tab_bar->Tabs.Size == 1 && !(tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs)) tab_contents_visible = true; @@ -8052,84 +7979,32 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, // Click to Select a tab ImGuiButtonFlags button_flags = ((is_tab_button ? ImGuiButtonFlags_PressedOnClickRelease : ImGuiButtonFlags_PressedOnClick) | ImGuiButtonFlags_AllowItemOverlap); - if (g.DragDropActive && !g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW)) // FIXME: May be an opt-in property of the payload to disable this + if (g.DragDropActive) button_flags |= ImGuiButtonFlags_PressedOnDragDropHold; bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, button_flags); if (pressed && !is_tab_button) tab_bar->NextSelectedTabId = id; - // Transfer active id window so the active id is not owned by the dock host (as StartMouseMovingWindow() - // will only do it on the drag). This allows FocusWindow() to be more conservative in how it clears active id. - if (held && docked_window && g.ActiveId == id && g.ActiveIdIsJustActivated) - g.ActiveIdWindow = docked_window; - // Allow the close button to overlap unless we are dragging (in which case we don't want any overlapping tabs to be hovered) if (g.ActiveId != id) SetItemAllowOverlap(); - // Drag and drop a single floating window node moves it - ImGuiDockNode* node = docked_window ? docked_window->DockNode : NULL; - const bool single_floating_window_node = node && node->IsFloatingNode() && (node->Windows.Size == 1); - if (held && single_floating_window_node && IsMouseDragging(0, 0.0f)) + // Drag and drop: re-order tabs + if (held && !tab_appearing && IsMouseDragging(0)) { - // Move - StartMouseMovingWindow(docked_window); - } - else if (held && !tab_appearing && IsMouseDragging(0)) - { - // Drag and drop: re-order tabs - int drag_dir = 0; - float drag_distance_from_edge_x = 0.0f; - if (!g.DragDropActive && ((tab_bar->Flags & ImGuiTabBarFlags_Reorderable) || (docked_window != NULL))) + if (!g.DragDropActive && (tab_bar->Flags & ImGuiTabBarFlags_Reorderable)) { // While moving a tab it will jump on the other side of the mouse, so we also test for MouseDelta.x if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < bb.Min.x) { - drag_dir = -1; - drag_distance_from_edge_x = bb.Min.x - g.IO.MousePos.x; TabBarQueueReorderFromMousePos(tab_bar, tab, g.IO.MousePos); } else if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > bb.Max.x) { - drag_dir = +1; - drag_distance_from_edge_x = g.IO.MousePos.x - bb.Max.x; TabBarQueueReorderFromMousePos(tab_bar, tab, g.IO.MousePos); } } - - // Extract a Dockable window out of it's tab bar - if (docked_window != NULL && !(docked_window->Flags & ImGuiWindowFlags_NoMove)) - { - // We use a variable threshold to distinguish dragging tabs within a tab bar and extracting them out of the tab bar - bool undocking_tab = (g.DragDropActive && g.DragDropPayload.SourceId == id); - if (!undocking_tab) //&& (!g.IO.ConfigDockingWithShift || g.IO.KeyShift) - { - float threshold_base = g.FontSize; - float threshold_x = (threshold_base * 2.2f); - float threshold_y = (threshold_base * 1.5f) + ImClamp((ImFabs(g.IO.MouseDragMaxDistanceAbs[0].x) - threshold_base * 2.0f) * 0.20f, 0.0f, threshold_base * 4.0f); - //GetForegroundDrawList()->AddRect(ImVec2(bb.Min.x - threshold_x, bb.Min.y - threshold_y), ImVec2(bb.Max.x + threshold_x, bb.Max.y + threshold_y), IM_COL32_WHITE); // [DEBUG] - - float distance_from_edge_y = ImMax(bb.Min.y - g.IO.MousePos.y, g.IO.MousePos.y - bb.Max.y); - if (distance_from_edge_y >= threshold_y) - undocking_tab = true; - if (drag_distance_from_edge_x > threshold_x) - if ((drag_dir < 0 && tab_bar->GetTabOrder(tab) == 0) || (drag_dir > 0 && tab_bar->GetTabOrder(tab) == tab_bar->Tabs.Size - 1)) - undocking_tab = true; - } - - if (undocking_tab) - { - // Undock - // FIXME: refactor to share more code with e.g. StartMouseMovingWindow - DockContextQueueUndockWindow(&g, docked_window); - g.MovingWindow = docked_window; - SetActiveID(g.MovingWindow->MoveId, g.MovingWindow); - g.ActiveIdClickOffset -= g.MovingWindow->Pos - bb.Min; - g.ActiveIdNoClearOnFocusLoss = true; - SetActiveIdUsingNavAndKeys(); - } - } } #if 0 @@ -8198,20 +8073,10 @@ void ImGui::SetTabItemClosed(const char* label) if (is_within_manual_tab_bar) { ImGuiTabBar* tab_bar = g.CurrentTabBar; - ImGuiID tab_id = TabBarCalcTabID(tab_bar, label, NULL); + ImGuiID tab_id = TabBarCalcTabID(tab_bar, label); if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id)) tab->WantClose = true; // Will be processed by next call to TabBarLayout() } - else if (ImGuiWindow* window = FindWindowByName(label)) - { - if (window->DockIsActive) - if (ImGuiDockNode* node = window->DockNode) - { - ImGuiID tab_id = TabBarCalcTabID(node->TabBar, label, window); - TabBarRemoveTab(node->TabBar, tab_id); - window->DockTabWantClose = true; - } - } } ImVec2 ImGui::TabItemCalcSize(const char* label, bool has_close_button) @@ -8235,7 +8100,7 @@ void ImGui::TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabI IM_ASSERT(width > 0.0f); const float rounding = ImMax(0.0f, ImMin((flags & ImGuiTabItemFlags_Button) ? g.Style.FrameRounding : g.Style.TabRounding, width * 0.5f - 1.0f)); const float y1 = bb.Min.y + 1.0f; - const float y2 = bb.Max.y + ((flags & ImGuiTabItemFlags_Preview) ? 0.0f : -1.0f); + const float y2 = bb.Max.y - 1.0f; draw_list->PathLineTo(ImVec2(bb.Min.x, y2)); draw_list->PathArcToFast(ImVec2(bb.Min.x + rounding, y1 + rounding), rounding, 6, 9); draw_list->PathArcToFast(ImVec2(bb.Max.x - rounding, y1 + rounding), rounding, 9, 12);