forked from hoffstadt/DearPyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmvLayoutWindow.cpp
277 lines (233 loc) · 9.98 KB
/
mvLayoutWindow.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include "mvLayoutWindow.h"
#include <imnodes.h>
#include "mvContext.h"
#include "mvItemRegistry.h"
static void
DebugItem(const char* label, const char* item) {
ImGui::Text("%s", label);
ImGui::SameLine();
ImGui::TextColored(ImVec4(1.0f, 0.0f, 1.0f, 1.0f), "%s", item);
}
mvLayoutWindow::mvLayoutWindow()
{
m_windowflags = ImGuiWindowFlags_NoSavedSettings;
}
void mvLayoutWindow::renderRootCategory(const char* category, std::vector<std::shared_ptr<mvAppItem>>& roots)
{
const auto node_flags = ImGuiTreeNodeFlags_OpenOnArrow | (roots.empty() ? ImGuiTreeNodeFlags_Leaf : 0);
ImGui::PushID(&roots);
const auto expanded = ImGui::TreeNodeEx(category, node_flags);
if (expanded)
{
for (auto& root : roots)
renderTreeNode(root);
ImGui::TreePop();
}
ImGui::PopID();
}
void mvLayoutWindow::renderTreeNode(std::shared_ptr<mvAppItem>& item)
{
// build up flags for current node
const auto node_flags = ImGuiTreeNodeFlags_OpenOnArrow
| ((item->uuid == m_selectedItem) ? ImGuiTreeNodeFlags_Selected : 0)
| (DearPyGui::GetEntityDesciptionFlags(item->type) & MV_ITEM_DESC_CONTAINER ? 0 : ImGuiTreeNodeFlags_Leaf);
// render this node
ImGui::PushID(item.get());
std::string labelToShow = DearPyGui::GetEntityTypeString(item->type);
if (!item->config.alias.empty())
labelToShow = item->config.alias;
else if (!item->config.specifiedLabel.empty())
labelToShow = item->config.specifiedLabel;
if (!_imguiFilter.PassFilter(labelToShow.c_str()) && _startFiltering)
{
ImGui::PopID();
return;
}
const auto expanded = ImGui::TreeNodeEx(labelToShow.c_str(), node_flags);
if (item->uuid == m_selectedItem)
_startFiltering = true;
// processing for selecting node
if (ImGui::IsItemClicked())
{
m_selectedItem = item->uuid;
_itemref = item;
m_dirtyNodes = true;
}
if (!(DearPyGui::GetEntityDesciptionFlags(item->type) & MV_ITEM_DESC_CONTAINER))
{
if(expanded)
ImGui::TreePop();
ImGui::PopID();
if (item->uuid == m_selectedItem)
_startFiltering = false;
return;
}
if (expanded)
{
int i = 0;
for (auto& childrenSet : item->childslots)
{
std::string title = "Child Slot: " + std::to_string(i++);
if (_slots)
{
if (ImGui::TreeNodeEx(title.c_str(), childrenSet.empty() ? ImGuiTreeNodeFlags_Leaf : 0))
{
for (auto& children : childrenSet)
if(children)
renderTreeNode(children);
ImGui::TreePop();
}
}
else
{
for (auto& children : childrenSet)
if(children)
renderTreeNode(children);
}
}
ImGui::TreePop();
}
ImGui::PopID();
if (item->uuid == m_selectedItem)
_startFiltering = false;
}
void mvLayoutWindow::drawWidgets()
{
mvUUID parentName = 0;
if (_itemref == nullptr && GContext->itemRegistry->windowRoots.size() > 0)
_itemref = GContext->itemRegistry->windowRoots[0];
else if(_itemref == nullptr)
return;
if (_itemref->info.parentPtr)
parentName = _itemref->info.parentPtr->uuid;
// left side
ImGui::BeginGroup();
if (ImGui::ArrowButton("Move Up", ImGuiDir_Up))
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
mvSubmitCallback([&]()
{
MoveItemUp(*GContext->itemRegistry, m_selectedItem);
});
}
ImGui::SameLine();
if (ImGui::ArrowButton("Move Down", ImGuiDir_Down))
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
mvSubmitCallback([&]()
{
MoveItemDown(*GContext->itemRegistry, m_selectedItem);
});
}
ImGui::SameLine();
if (ImGui::Button("Delete"))
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
mvSubmitCallback([&]()
{
DeleteItem(*GContext->itemRegistry, m_selectedItem, false);
m_selectedItem = 0;
});
_itemref = nullptr;
_itemref = GContext->itemRegistry->windowRoots[0];
}
ImGui::SameLine();
if (ImGui::Button("Show"))
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
mvAppItem* tempItem = GetItem(*GContext->itemRegistry, m_selectedItem);
tempItem->config.show = true;
tempItem->info.shownLastFrame = true;
}
ImGui::SameLine();
if (ImGui::Button("Hide"))
{
std::lock_guard<std::recursive_mutex> lk(GContext->mutex);
mvAppItem* tempItem = GetItem(*GContext->itemRegistry, m_selectedItem);
tempItem->config.show = false;
tempItem->info.hiddenLastFrame = true;
}
ImGui::SameLine();
ImGui::Checkbox("Show Slots###layout", &_slots);
ImGui::BeginChild("###layoutwindow", ImVec2(400, 0));
static char ts[6] = "True";
static char fs[6] = "False";
std::string width = std::to_string(_itemref->config.width);
std::string height = std::to_string(_itemref->config.height);
std::string sizex = std::to_string(_itemref->state.rectSize.x);
std::string sizey = std::to_string(_itemref->state.rectSize.y);
ImGui::PushID(_itemref.get());
DebugItem("Label:", _itemref->config.specifiedLabel.c_str());
DebugItem("ID:", std::to_string(_itemref->uuid).c_str());
DebugItem("Alias:", _itemref->config.alias.c_str());
DebugItem("Type:", DearPyGui::GetEntityTypeString(_itemref->type));
DebugItem("Filter:", _itemref->config.filter.c_str());
DebugItem("Payload Type:", _itemref->config.payloadType.c_str());
DebugItem("Location:", std::to_string(_itemref->info.location).c_str());
DebugItem("Track Offset:", std::to_string(_itemref->config.trackOffset).c_str());
DebugItem("Container:", DearPyGui::GetEntityDesciptionFlags(_itemref->type) & MV_ITEM_DESC_CONTAINER ? ts : fs);
DebugItem("Width:", width.c_str());
DebugItem("Height:", height.c_str());
DebugItem("Size x:", sizex.c_str());
DebugItem("Size y:", sizey.c_str());
DebugItem("Show:", _itemref->config.show ? ts : fs);
DebugItem("Enabled:", _itemref->config.enabled ? ts : fs);
DebugItem("Tracked:", _itemref->config.tracked ? ts : fs);
DebugItem("Callback:", _itemref->config.callback ? ts : fs);
DebugItem("User Data:", _itemref->config.user_data ? ts : fs);
DebugItem("Drop Callback:", _itemref->config.dropCallback ? ts : fs);
DebugItem("Drag Callback:", _itemref->config.dragCallback ? ts : fs);
ImGui::Spacing();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Text("Bindings");
ImGui::Separator();
DebugItem("Theme Bound:", _itemref->theme ? ts : fs);
DebugItem("Font Bound:", _itemref->font ? ts : fs);
DebugItem("Handlers Bound:", _itemref->handlerRegistry ? ts : fs);
int applicableState = DearPyGui::GetApplicableState(_itemref->type);
ImGui::Spacing();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Text("State");
ImGui::Separator();
if (applicableState & MV_STATE_VISIBLE) DebugItem("Item Visible:", IsItemVisible(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_HOVER) DebugItem("Item Hovered:", IsItemHovered(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_ACTIVE) DebugItem("Item Active:", IsItemActive(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_FOCUSED) DebugItem("Item Focused:", IsItemFocused(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_CLICKED)
{
DebugItem("Item Left Clicked:", IsItemLeftClicked(_itemref->state, 1) ? ts : fs);
DebugItem("Item Right Clicked:", IsItemRightClicked(_itemref->state, 1) ? ts : fs);
DebugItem("Item Middle Clicked:", IsItemMiddleClicked(_itemref->state, 1) ? ts : fs);
}
if (applicableState & MV_STATE_EDITED) DebugItem("Item Edited:", IsItemEdited(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_ACTIVATED) DebugItem("Item Activated:", IsItemActivated(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_DEACTIVATED) DebugItem("Item Deactivated:", IsItemDeactivated(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_DEACTIVATEDAE) DebugItem("Item DeactivatedAfterEdit:", IsItemDeactivatedAfterEdit(_itemref->state, 1) ? ts : fs);
if (applicableState & MV_STATE_TOGGLED_OPEN) DebugItem("Item ToggledOpen:", IsItemToogledOpen(_itemref->state, 1) ? ts : fs);
ImGui::PopID();
ImGui::EndChild();
ImGui::EndGroup();
ImGui::SameLine();
// right side
ImGui::BeginGroup();
_imguiFilter.Draw();
_startFiltering = false;
ImGui::BeginChild("TreeChild", ImVec2(-1.0f, -1.0f), true);
renderRootCategory("Windows", GContext->itemRegistry->windowRoots);
renderRootCategory("Themes", GContext->itemRegistry->themeRegistryRoots);
renderRootCategory("Template Registries", GContext->itemRegistry->itemTemplatesRoots);
renderRootCategory("Staging Containers", GContext->itemRegistry->stagingRoots);
renderRootCategory("Texture Registries", GContext->itemRegistry->textureRegistryRoots);
renderRootCategory("Font Registries", GContext->itemRegistry->fontRegistryRoots);
renderRootCategory("Item Handler Registries", GContext->itemRegistry->itemHandlerRegistryRoots);
renderRootCategory("Handler Registries", GContext->itemRegistry->handlerRegistryRoots);
renderRootCategory("Value Registries", GContext->itemRegistry->valueRegistryRoots);
renderRootCategory("Colormap Registries", GContext->itemRegistry->colormapRoots);
renderRootCategory("File Dialogs", GContext->itemRegistry->filedialogRoots);
renderRootCategory("Viewport Menubars", GContext->itemRegistry->viewportMenubarRoots);
renderRootCategory("Viewport Drawlists", GContext->itemRegistry->viewportDrawlistRoots);
ImGui::EndChild();
ImGui::EndGroup();
}