Extract shared editor tree view
This commit is contained in:
@@ -162,7 +162,7 @@ inline ImVec2 ProjectBrowserPanePadding() {
|
||||
return ImVec2(10.0f, 8.0f);
|
||||
}
|
||||
|
||||
inline ImVec2 ProjectTreeNodeFramePadding() {
|
||||
inline ImVec2 NavigationTreeNodeFramePadding() {
|
||||
return ImVec2(4.0f, 3.0f);
|
||||
}
|
||||
|
||||
@@ -226,10 +226,6 @@ inline ImVec2 PopupWindowPadding() {
|
||||
return ImVec2(12.0f, 10.0f);
|
||||
}
|
||||
|
||||
inline ImVec2 HierarchyNodeFramePadding() {
|
||||
return ImVec2(4.0f, 3.0f);
|
||||
}
|
||||
|
||||
inline ImVec2 AssetTileSize() {
|
||||
return ImVec2(104.0f, 82.0f);
|
||||
}
|
||||
|
||||
68
editor/src/UI/TreeView.h
Normal file
68
editor/src/UI/TreeView.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "StyleTokens.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace UI {
|
||||
|
||||
struct TreeNodeOptions {
|
||||
bool selected = false;
|
||||
bool leaf = false;
|
||||
bool defaultOpen = false;
|
||||
bool openOnArrow = true;
|
||||
bool openOnDoubleClick = true;
|
||||
bool spanAvailWidth = true;
|
||||
bool framePadding = true;
|
||||
};
|
||||
|
||||
struct TreeNodeResult {
|
||||
bool open = false;
|
||||
bool clicked = false;
|
||||
bool doubleClicked = false;
|
||||
};
|
||||
|
||||
inline TreeNodeResult DrawTreeNode(const void* id, const char* label, const TreeNodeOptions& options = {}) {
|
||||
ImGuiTreeNodeFlags flags = 0;
|
||||
if (options.openOnArrow) {
|
||||
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
|
||||
}
|
||||
if (options.openOnDoubleClick) {
|
||||
flags |= ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||
}
|
||||
if (options.spanAvailWidth) {
|
||||
flags |= ImGuiTreeNodeFlags_SpanAvailWidth;
|
||||
}
|
||||
if (options.framePadding) {
|
||||
flags |= ImGuiTreeNodeFlags_FramePadding;
|
||||
}
|
||||
if (options.leaf) {
|
||||
flags |= ImGuiTreeNodeFlags_Leaf;
|
||||
}
|
||||
if (options.selected) {
|
||||
flags |= ImGuiTreeNodeFlags_Selected;
|
||||
}
|
||||
if (options.defaultOpen) {
|
||||
flags |= ImGuiTreeNodeFlags_DefaultOpen;
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, NavigationTreeNodeFramePadding());
|
||||
const bool open = ImGui::TreeNodeEx(id, flags, "%s", label);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
return TreeNodeResult{
|
||||
open,
|
||||
ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen(),
|
||||
ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)
|
||||
};
|
||||
}
|
||||
|
||||
inline void EndTreeNode() {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ScalarControls.h"
|
||||
#include "SceneStatusWidget.h"
|
||||
#include "StyleTokens.h"
|
||||
#include "TreeView.h"
|
||||
#include "VectorControls.h"
|
||||
#include "Widgets.h"
|
||||
|
||||
|
||||
@@ -14,12 +14,6 @@ struct ComponentSectionResult {
|
||||
bool open = false;
|
||||
};
|
||||
|
||||
struct HierarchyNodeResult {
|
||||
bool open = false;
|
||||
bool clicked = false;
|
||||
bool doubleClicked = false;
|
||||
};
|
||||
|
||||
struct AssetTileResult {
|
||||
bool clicked = false;
|
||||
bool contextRequested = false;
|
||||
@@ -183,37 +177,6 @@ inline void DrawToolbarBreadcrumbs(
|
||||
ImGui::PopStyleColor(2);
|
||||
}
|
||||
|
||||
inline HierarchyNodeResult DrawHierarchyNode(
|
||||
const void* id,
|
||||
const char* label,
|
||||
bool selected,
|
||||
bool leaf) {
|
||||
ImGuiTreeNodeFlags flags =
|
||||
ImGuiTreeNodeFlags_OpenOnArrow |
|
||||
ImGuiTreeNodeFlags_SpanAvailWidth |
|
||||
ImGuiTreeNodeFlags_FramePadding;
|
||||
if (leaf) {
|
||||
flags |= ImGuiTreeNodeFlags_Leaf;
|
||||
}
|
||||
if (selected) {
|
||||
flags |= ImGuiTreeNodeFlags_Selected;
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, HierarchyNodeFramePadding());
|
||||
const bool open = ImGui::TreeNodeEx(id, flags, "%s", label);
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
return HierarchyNodeResult{
|
||||
open,
|
||||
ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen(),
|
||||
ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)
|
||||
};
|
||||
}
|
||||
|
||||
inline void EndHierarchyNode() {
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
template <typename DrawIconFn>
|
||||
inline AssetTileResult DrawAssetTile(
|
||||
const char* label,
|
||||
|
||||
Reference in New Issue
Block a user