-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathImGuiDock.h
85 lines (66 loc) · 1.85 KB
/
ImGuiDock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
class GuiWindow;
namespace ImGuiDock
{
enum class DockSlot { Left, Right, Top, Bottom, Tab, None };
struct Dock;
class Dockspace;
struct Container
{
Container *splits[2]{ nullptr, nullptr };
Container *parent = nullptr;
Dock *activeDock = nullptr;
std::vector<Dock*>docks;
bool verticalSplit = false;
bool alwaysAutoResize = true;
float size = 0;
};
struct Dock
{
Dock *initialize(const char *dtitle, bool dcloseButton, ImVec2 dminSize, std::function<void(ImVec2)> ddrawFunction)
{
title = dtitle;
closeButton = dcloseButton;
minSize = dminSize;
drawFunction = ddrawFunction;
return this;
};
//Container *parent = nullptr;
Container *container = nullptr;
Dockspace *redockFrom = nullptr;
Dock *redockTo = nullptr;
const char *title;
DockSlot dockSlot = DockSlot::Tab;
DockSlot redockSlot = DockSlot::None;
bool closeButton = true;
bool undockable = false;
bool draging = false;
ImVec2 lastSize;
ImVec2 minSize;
std::function<void(ImVec2)> drawFunction;
std::function<bool(void)> onCloseFunction;
};
class Dockspace
{
public:
Dockspace();
~Dockspace();
bool dock(Dock *dock, DockSlot dockSlot, float size = 0, bool active = false);
bool dockWith(Dock *dock, Dock *dockTo, DockSlot dockSlot, float size = 0, bool active = false);
bool undock(Dock *dock);
void updateAndDraw(ImVec2 size);
void clear();
std::vector<Dock*>m_docks;
Container m_container;
std::vector<Container*>m_containers;
protected:
void _renderTabBar(Container *container, ImVec2 size, ImVec2 cursorPos);
bool _getMinSize(Container *container, ImVec2 *min);
enum DockToAction
{
eUndock, eDrag, eClose, eNull
};
Dock *m_currentDockTo = nullptr;
DockToAction m_currentDockToAction = eNull;
};
};