Skip to content

Commit 8d95146

Browse files
committed
Improve UI/UX
1 parent 113376a commit 8d95146

3 files changed

Lines changed: 349 additions & 560 deletions

File tree

UnityInspector/src/game/features/inspector/hierarchy_window.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "pch.h"
22
#include "inspector.h"
33

4-
54
void Inspector::RenderHierarchyNode(HierarchyNode& node, const int depth)
65
{
76
if (!Core::helper->SafeIsAlive(node.gameObject)) return;
@@ -22,7 +21,7 @@ void Inspector::RenderHierarchyNode(HierarchyNode& node, const int depth)
2221
if (checkChildren(c)) return true;
2322
}
2423
return false;
25-
};
24+
};
2625
if (checkChildren(child))
2726
{
2827
matchesSearch = true;
@@ -39,8 +38,11 @@ void Inspector::RenderHierarchyNode(HierarchyNode& node, const int depth)
3938
const bool hasChildren = !node.children.empty();
4039
const bool isSelected = (FindTabForObject(node.gameObject) >= 0);
4140

42-
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth;
43-
if (!hasChildren) flags |= ImGuiTreeNodeFlags_Leaf;
41+
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow |
42+
ImGuiTreeNodeFlags_SpanAvailWidth |
43+
ImGuiTreeNodeFlags_FramePadding;
44+
45+
if (!hasChildren) flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;
4446
if (isSelected) flags |= ImGuiTreeNodeFlags_Selected;
4547

4648
bool isActive = true;
@@ -50,17 +52,14 @@ void Inspector::RenderHierarchyNode(HierarchyNode& node, const int depth)
5052
return;
5153
}
5254

53-
if (!isActive)
54-
{
55-
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
56-
}
5755

58-
const bool nodeOpen = ImGui::TreeNodeEx(node.name.c_str(), flags);
56+
const char* icon = hasChildren ? " " : " ";
57+
const char* activeIcon = isActive ? "" : " ";
58+
59+
std::string label = activeIcon + std::string(icon) + node.name;
60+
61+
const bool nodeOpen = ImGui::TreeNodeEx(label.c_str(), flags);
5962

60-
if (!isActive)
61-
{
62-
ImGui::PopStyleColor();
63-
}
6463

6564
if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen())
6665
{
@@ -69,14 +68,19 @@ void Inspector::RenderHierarchyNode(HierarchyNode& node, const int depth)
6968

7069
if (ImGui::BeginPopupContextItem())
7170
{
72-
if (ImGui::MenuItem("Inspect"))
71+
if (ImGui::MenuItem("Inspect", nullptr, false, true))
7372
{
7473
OpenObjectInNewTab(node.gameObject);
7574
}
75+
ImGui::Separator();
76+
if (ImGui::MenuItem(isActive ? "Deactivate" : "Activate"))
77+
{
78+
Core::helper->SafeSetActive(node.gameObject, !isActive);
79+
}
7680
ImGui::EndPopup();
7781
}
7882

79-
if (nodeOpen)
83+
if (hasChildren && nodeOpen)
8084
{
8185
for (auto& child : node.children)
8286
{

UnityInspector/src/game/features/inspector/inspector.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "pch.h"
1+
#include "pch.h"
22
#include "inspector.h"
33
#include "assembly_explorer.h"
44

@@ -44,7 +44,7 @@ void Inspector::Render()
4444

4545
UR::ThreadAttach();
4646

47-
ImGui::SetNextWindowSize(ImVec2(350, 500), ImGuiCond_FirstUseEver);
47+
ImGui::SetNextWindowSize(ImVec2(380, 600), ImGuiCond_FirstUseEver);
4848

4949
if (ImGui::Begin("Hierarchy", nullptr))
5050
{
@@ -54,19 +54,18 @@ void Inspector::Render()
5454
}
5555

5656
ImGui::SameLine();
57-
ImGui::Checkbox("Auto Refresh", &Core::config->inspector.AutoRefresh);
57+
ImGui::Checkbox("Auto", &Core::config->inspector.AutoRefresh);
5858

5959
ImGui::SameLine();
60-
ImGui::Text("Objects: %zu", rootNodes.size());
60+
ImGui::TextDisabled("| %zu objects", rootNodes.size());
6161

6262
ImGui::SameLine();
63-
6463
ImGui::SetNextItemWidth(-1);
6564
ImGui::InputTextWithHint("##Search", "Search...", searchBuffer, sizeof(searchBuffer));
6665

6766
ImGui::Separator();
6867

69-
if (ImGui::BeginChild("HierarchyTree", ImVec2(0, 0), true))
68+
if (ImGui::BeginChild("HierarchyTree", ImVec2(0, 0), false))
7069
{
7170
if (rootNodes.empty())
7271
{
@@ -104,4 +103,4 @@ void Inspector::Render()
104103
{
105104
assemblyExplorer.reset();
106105
}
107-
}
106+
}

0 commit comments

Comments
 (0)