Nebula
Loading...
Searching...
No Matches
imguidetach.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13//------------------------------------------------------------------------------
14#include "imgui.h"
15#include "imgui_internal.h"
16
18{
19
20//------------------------------------------------------------------------------
26{
27 ImGuiID dragged = 0;
28 ImVec2 dropPos;
29 ImGuiID focusOnShow = 0;
30};
32
33//------------------------------------------------------------------------------
45inline void
46DeferWindowDetach(const char* name)
47{
48 ImGuiContext& g = *GImGui;
49 if ((g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) == 0)
50 {
51 return;
52 }
53
54 ImGuiWindow* window = ImGui::FindWindowByName(name);
55 if (window == nullptr)
56 {
57 return;
58 }
59
60 // Let go: the window goes where it was dropped, and ImGui makes its OS window there
61 if (State.dragged == window->ID && g.MovingWindow != window)
62 {
63 State.dragged = 0;
64
65 // Dropped onto a dock, which places it
66 if (window->DockNode != nullptr)
67 {
68 return;
69 }
70
71 ImGui::SetNextWindowPos(State.dropPos, ImGuiCond_Always);
72 // Written out, because the math operators are not there for every file that includes ImGui
73 const ImGuiViewport* main = ImGui::GetMainViewport();
74 const bool inside = State.dropPos.x >= main->Pos.x && State.dropPos.y >= main->Pos.y &&
75 State.dropPos.x + window->Size.x <= main->Pos.x + main->Size.x &&
76 State.dropPos.y + window->Size.y <= main->Pos.y + main->Size.y;
77 if (!inside)
78 {
79 State.focusOnShow = window->ID;
80 }
81 return;
82 }
83
84 // Only a window that is dragged on its own, and is still in the main window. A window that has its
85 // own OS window already moves with it, and a docked window moves with its dock
86 ImGuiViewport* mainViewport = ImGui::GetMainViewport();
87 if (g.MovingWindow != window || window->Viewport != mainViewport || window->ViewportOwned || window->DockIsActive)
88 {
89 return;
90 }
91 if (!ImGui::IsMousePosValid() || !ImGui::IsMouseDown(ImGuiMouseButton_Left))
92 {
93 return;
94 }
95
96 // The same place ImGui moves the window to, but set through the API so it is not kept inside
97 State.dragged = window->ID;
98 State.dropPos = ImVec2(g.IO.MousePos.x - g.ActiveIdClickOffset.x, g.IO.MousePos.y - g.ActiveIdClickOffset.y);
99 ImGui::SetNextWindowPos(State.dropPos, ImGuiCond_Always);
100 ImGui::SetNextWindowViewport(mainViewport->ID);
101}
102
103
104} // namespace Dynui::ImguiDetach
Definition imguidetach.h:18
void DeferWindowDetach(const char *name)
By default ImGui gives a window its own OS window as soon as it is dragged past the edge of the main ...
Definition imguidetach.h:46
DetachStateType State
Definition imguidetach.h:31
The window being dragged out of the main window, where it is to be let go, and the window that was le...
Definition imguidetach.h:26
ImGuiID dragged
Definition imguidetach.h:27
ImGuiID focusOnShow
Definition imguidetach.h:29
ImVec2 dropPos
Definition imguidetach.h:28