Skip to content

Commit babe402

Browse files
visualize node visibility (#68)
* visualize visibility state of of nodes in tree page as in good old days * &&
1 parent 5d211ca commit babe402

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/DevTools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DevTools {
6262
void setupPlatform();
6363

6464
void drawTree();
65-
void drawTreeBranch(CCNode* node, size_t index, bool drag);
65+
void drawTreeBranch(CCNode* node, size_t index, bool drag, bool visible);
6666
void drawSettings();
6767
void drawAdvancedSettings();
6868
void drawNodeAttributes(CCNode* node);

src/pages/Tree.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ bool isNodeParentOf(CCNode* parent, CCNode* child) {
3535
return false;
3636
}
3737

38-
void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag) {
38+
void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag, bool visible) {
3939
if (!this->searchBranch(node)) {
4040
return;
4141
}
4242

43+
visible = node->isVisible() && visible;
44+
4345
auto selected = DevTools::get()->getSelectedNode() == node;
4446

4547
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_None;
@@ -103,11 +105,22 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag) {
103105
ImGui::SetNextItemOpen(true);
104106
}
105107

108+
auto alpha = ImGui::GetStyle().DisabledAlpha;
109+
ImGui::GetStyle().DisabledAlpha = node->isVisible() ? alpha + 0.15f : alpha;
110+
111+
ImGui::BeginDisabled(!visible);
112+
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false); // Bypass iteract blocking in imgui
113+
106114
const auto name = formatNodeName(node, index);
107115
// The order here is unusual due to imgui weirdness; see the second-to-last paragraph in https://kahwei.dev/2022/06/20/imgui-tree-node/
108116
bool expanded = ImGui::TreeNodeEx(node, flags, "%s", name.c_str());
109117
float height = ImGui::GetItemRectSize().y;
110118

119+
120+
ImGui::GetStyle().DisabledAlpha = alpha;
121+
ImGui::PopItemFlag(); //ImGuiItemFlags_Disabled
122+
ImGui::EndDisabled();
123+
111124
if (ImGui::IsItemClicked()) {
112125
DevTools::get()->selectNode(node);
113126
selected = true;
@@ -152,7 +165,7 @@ void DevTools::drawTreeBranch(CCNode* node, size_t index, bool drag) {
152165
}
153166
size_t i = 0;
154167
for (auto& child : CCArrayExt<CCNode*>(node->getChildren())) {
155-
this->drawTreeBranch(child, i++, drag || isDrag);
168+
this->drawTreeBranch(child, i++, drag || isDrag, visible);
156169
}
157170
ImGui::TreePop();
158171
}
@@ -177,7 +190,7 @@ void DevTools::drawTree() {
177190
m_searchQuery.clear();
178191
}
179192

180-
this->drawTreeBranch(CCDirector::get()->getRunningScene(), 0, false);
193+
this->drawTreeBranch(CCDirector::get()->getRunningScene(), 0, false, true);
181194

182195
if (auto* dragged = this->getDraggedNode()) {
183196
const auto name = formatNodeName(dragged, 0);
@@ -217,4 +230,5 @@ bool DevTools::searchBranch(CCNode* node) {
217230
}
218231
}
219232
return false;
220-
}
233+
234+
}

0 commit comments

Comments
 (0)