From 300464a4878c8ba659807c4d78d95e1357af87b1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 30 Aug 2023 17:36:09 +0200 Subject: [PATCH] Docking: when io.ConfigDockingWithShift is enabled, staying stationary while moving a window displays an help tooltip to increase affordance. (#6709, #4643) Hope this doesn't feel spammy? --- docs/CHANGELOG.txt | 5 +++++ imgui.cpp | 17 ++++++++++++++--- imgui_internal.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c59c0a404404..92a829d6bd3e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -73,6 +73,11 @@ Other changes: for consistency (matching GLFW backend) and as most initialization paths don't actually need to care about rendering backend. +Docking+Viewports Branch: + +- Docking: when io.ConfigDockingWithShift is enabled, staying stationary while moving + a window displays an help tooltip to increase affordance. (#6709, #4643) + ----------------------------------------------------------------------- VERSION 1.89.8 (Released 2023-08-01) diff --git a/imgui.cpp b/imgui.cpp index 4708d5004758..eb75fa26b433 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3639,6 +3639,7 @@ static const ImGuiLocEntry GLocalizationEntriesEnUS[] = { ImGuiLocKey_WindowingPopup, "(Popup)" }, { ImGuiLocKey_WindowingUntitled, "(Untitled)" }, { ImGuiLocKey_DockingHideTabBar, "Hide tab bar###HideTabBar" }, + { ImGuiLocKey_DockingHoldShiftToDock, "Hold SHIFT to enable Docking window."}, }; void ImGui::Initialize() @@ -7314,9 +7315,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { // 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.ConfigDockingWithShift == g.IO.KeyShift)) - if ((window->RootWindowDockTree->Flags & ImGuiWindowFlags_NoDocking) == 0) - BeginDockableDragDropSource(window); + if (g.MovingWindow == window && (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)) @@ -18554,6 +18554,17 @@ void ImGui::BeginDockableDragDropSource(ImGuiWindow* window) IM_ASSERT(g.MovingWindow == window); IM_ASSERT(g.CurrentWindow == window); + // 0: Hold SHIFT to disable docking, 1: Hold SHIFT to enable docking. + if (g.IO.ConfigDockingWithShift != g.IO.KeyShift) + { + // When ConfigDockingWithShift is set, display a tooltip to increase UI affordance. + // We cannot set for HoveredWindowUnderMovingWindow != NULL here, as it is only valid/useful when drag and drop is already active + // (because of the 'is_mouse_dragging_with_an_expected_destination' logic in UpdateViewportsNewFrame() function) + if (g.IO.ConfigDockingWithShift && g.MouseStationaryTimer >= 1.0f && g.ActiveId >= 1.0f) + SetTooltip("%s", LocalizeGetMsg(ImGuiLocKey_DockingHoldShiftToDock)); + return; + } + g.LastItemData.ID = window->MoveId; window = window->RootWindowDockTree; IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0); diff --git a/imgui_internal.h b/imgui_internal.h index 79444e1e3a8d..0012efb69ab7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1862,6 +1862,7 @@ enum ImGuiLocKey : int ImGuiLocKey_WindowingPopup, ImGuiLocKey_WindowingUntitled, ImGuiLocKey_DockingHideTabBar, + ImGuiLocKey_DockingHoldShiftToDock, ImGuiLocKey_COUNT };