2026-04-07 14:41:01 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
|
|
|
#include <XCEngine/UI/Widgets/UIExpansionModel.h>
|
|
|
|
|
#include <XCEngine/UI/Widgets/UISelectionModel.h>
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine::UI::Editor::Widgets {
|
|
|
|
|
|
|
|
|
|
inline constexpr std::size_t UIEditorTreeViewInvalidIndex = static_cast<std::size_t>(-1);
|
|
|
|
|
|
|
|
|
|
enum class UIEditorTreeViewHitTargetKind : std::uint8_t {
|
|
|
|
|
None = 0,
|
|
|
|
|
Row,
|
|
|
|
|
Disclosure
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewItem {
|
|
|
|
|
std::string itemId = {};
|
|
|
|
|
std::string label = {};
|
|
|
|
|
std::uint32_t depth = 0u;
|
|
|
|
|
bool forceLeaf = false;
|
|
|
|
|
float desiredHeight = 0.0f;
|
2026-04-11 22:14:02 +08:00
|
|
|
::XCEngine::UI::UITextureHandle leadingIcon = {};
|
2026-04-07 14:41:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewState {
|
|
|
|
|
std::string hoveredItemId = {};
|
|
|
|
|
bool focused = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewMetrics {
|
|
|
|
|
float rowHeight = 28.0f;
|
|
|
|
|
float rowGap = 2.0f;
|
|
|
|
|
float horizontalPadding = 8.0f;
|
|
|
|
|
float indentWidth = 18.0f;
|
|
|
|
|
float disclosureExtent = 12.0f;
|
|
|
|
|
float disclosureLabelGap = 6.0f;
|
2026-04-11 22:14:02 +08:00
|
|
|
float iconExtent = 18.0f;
|
|
|
|
|
float iconLabelGap = 2.0f;
|
2026-04-11 22:31:14 +08:00
|
|
|
float iconInsetY = 0.0f;
|
2026-04-07 14:41:01 +08:00
|
|
|
float labelInsetY = 6.0f;
|
|
|
|
|
float cornerRounding = 6.0f;
|
|
|
|
|
float borderThickness = 1.0f;
|
|
|
|
|
float focusedBorderThickness = 2.0f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewPalette {
|
|
|
|
|
::XCEngine::UI::UIColor surfaceColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor borderColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.29f, 0.29f, 0.29f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor focusedBorderColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.84f, 0.84f, 0.84f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor rowHoverColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.24f, 0.24f, 0.24f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor rowSelectedColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.32f, 0.32f, 0.32f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor rowSelectedFocusedColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.40f, 0.40f, 0.40f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor disclosureColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.74f, 0.74f, 0.74f, 1.0f);
|
|
|
|
|
::XCEngine::UI::UIColor textColor =
|
|
|
|
|
::XCEngine::UI::UIColor(0.94f, 0.94f, 0.94f, 1.0f);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewLayout {
|
|
|
|
|
::XCEngine::UI::UIRect bounds = {};
|
|
|
|
|
std::vector<std::size_t> visibleItemIndices = {};
|
|
|
|
|
std::vector<::XCEngine::UI::UIRect> rowRects = {};
|
|
|
|
|
std::vector<::XCEngine::UI::UIRect> disclosureRects = {};
|
2026-04-11 22:14:02 +08:00
|
|
|
std::vector<::XCEngine::UI::UIRect> iconRects = {};
|
2026-04-07 14:41:01 +08:00
|
|
|
std::vector<::XCEngine::UI::UIRect> labelRects = {};
|
|
|
|
|
std::vector<bool> itemHasChildren = {};
|
|
|
|
|
std::vector<bool> itemExpanded = {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct UIEditorTreeViewHitTarget {
|
|
|
|
|
UIEditorTreeViewHitTargetKind kind = UIEditorTreeViewHitTargetKind::None;
|
|
|
|
|
std::size_t visibleIndex = UIEditorTreeViewInvalidIndex;
|
|
|
|
|
std::size_t itemIndex = UIEditorTreeViewInvalidIndex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool IsUIEditorTreeViewPointInside(
|
|
|
|
|
const ::XCEngine::UI::UIRect& rect,
|
|
|
|
|
const ::XCEngine::UI::UIPoint& point);
|
|
|
|
|
|
|
|
|
|
bool DoesUIEditorTreeViewItemHaveChildren(
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
std::size_t itemIndex);
|
|
|
|
|
|
|
|
|
|
std::size_t FindUIEditorTreeViewItemIndex(
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
std::string_view itemId);
|
|
|
|
|
|
|
|
|
|
std::size_t FindUIEditorTreeViewParentItemIndex(
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
std::size_t itemIndex);
|
|
|
|
|
|
|
|
|
|
std::vector<std::size_t> CollectUIEditorTreeViewVisibleItemIndices(
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel);
|
|
|
|
|
|
|
|
|
|
std::size_t FindUIEditorTreeViewFirstVisibleChildItemIndex(
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel,
|
|
|
|
|
std::size_t itemIndex);
|
|
|
|
|
|
|
|
|
|
UIEditorTreeViewLayout BuildUIEditorTreeViewLayout(
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel,
|
|
|
|
|
const UIEditorTreeViewMetrics& metrics = {});
|
|
|
|
|
|
|
|
|
|
UIEditorTreeViewHitTarget HitTestUIEditorTreeView(
|
|
|
|
|
const UIEditorTreeViewLayout& layout,
|
|
|
|
|
const ::XCEngine::UI::UIPoint& point);
|
|
|
|
|
|
|
|
|
|
void AppendUIEditorTreeViewBackground(
|
|
|
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
|
|
|
const UIEditorTreeViewLayout& layout,
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UISelectionModel& selectionModel,
|
|
|
|
|
const UIEditorTreeViewState& state,
|
|
|
|
|
const UIEditorTreeViewPalette& palette = {},
|
|
|
|
|
const UIEditorTreeViewMetrics& metrics = {});
|
|
|
|
|
|
|
|
|
|
void AppendUIEditorTreeViewForeground(
|
|
|
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
|
|
|
const UIEditorTreeViewLayout& layout,
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const UIEditorTreeViewPalette& palette = {},
|
|
|
|
|
const UIEditorTreeViewMetrics& metrics = {});
|
|
|
|
|
|
|
|
|
|
void AppendUIEditorTreeView(
|
|
|
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const std::vector<UIEditorTreeViewItem>& items,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UISelectionModel& selectionModel,
|
|
|
|
|
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel,
|
|
|
|
|
const UIEditorTreeViewState& state,
|
|
|
|
|
const UIEditorTreeViewPalette& palette = {},
|
|
|
|
|
const UIEditorTreeViewMetrics& metrics = {});
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor::Widgets
|