115 lines
4.0 KiB
C++
115 lines
4.0 KiB
C++
|
|
#include <XCEngine/UI/Widgets/UIEditorCollectionPrimitives.h>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace UI {
|
||
|
|
namespace Widgets {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
|
float ResolveFloatToken(
|
||
|
|
const Style::UITheme& theme,
|
||
|
|
const char* tokenName,
|
||
|
|
float fallbackValue) {
|
||
|
|
const Style::UITokenResolveResult result =
|
||
|
|
theme.ResolveToken(tokenName, Style::UIStyleValueType::Float);
|
||
|
|
if (result.status != Style::UITokenResolveStatus::Resolved) {
|
||
|
|
return fallbackValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
const float* value = result.value.TryGetFloat();
|
||
|
|
return value != nullptr ? *value : fallbackValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
UIEditorCollectionPrimitiveKind ClassifyUIEditorCollectionPrimitive(std::string_view tagName) {
|
||
|
|
if (tagName == "ScrollView") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::ScrollView;
|
||
|
|
}
|
||
|
|
if (tagName == "TreeView") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::TreeView;
|
||
|
|
}
|
||
|
|
if (tagName == "TreeItem") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::TreeItem;
|
||
|
|
}
|
||
|
|
if (tagName == "ListView") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::ListView;
|
||
|
|
}
|
||
|
|
if (tagName == "ListItem") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::ListItem;
|
||
|
|
}
|
||
|
|
if (tagName == "PropertySection") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::PropertySection;
|
||
|
|
}
|
||
|
|
if (tagName == "FieldRow") {
|
||
|
|
return UIEditorCollectionPrimitiveKind::FieldRow;
|
||
|
|
}
|
||
|
|
|
||
|
|
return UIEditorCollectionPrimitiveKind::None;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool IsUIEditorCollectionPrimitiveContainer(UIEditorCollectionPrimitiveKind kind) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::ScrollView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::TreeView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::ListView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::PropertySection;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool UsesUIEditorCollectionPrimitiveColumnLayout(UIEditorCollectionPrimitiveKind kind) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::TreeView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::ListView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::PropertySection;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool IsUIEditorCollectionPrimitiveHoverable(UIEditorCollectionPrimitiveKind kind) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::TreeItem ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::ListItem ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::FieldRow;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool DoesUIEditorCollectionPrimitiveClipChildren(UIEditorCollectionPrimitiveKind kind) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::ScrollView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::TreeView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::ListView;
|
||
|
|
}
|
||
|
|
|
||
|
|
float ResolveUIEditorCollectionPrimitivePadding(
|
||
|
|
UIEditorCollectionPrimitiveKind kind,
|
||
|
|
const Style::UITheme& theme) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::TreeView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::ListView ||
|
||
|
|
kind == UIEditorCollectionPrimitiveKind::PropertySection
|
||
|
|
? ResolveFloatToken(theme, "space.cardInset", 12.0f)
|
||
|
|
: 0.0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
float ResolveUIEditorCollectionPrimitiveDefaultHeight(
|
||
|
|
UIEditorCollectionPrimitiveKind kind,
|
||
|
|
const Style::UITheme& theme) {
|
||
|
|
switch (kind) {
|
||
|
|
case UIEditorCollectionPrimitiveKind::TreeItem:
|
||
|
|
return ResolveFloatToken(theme, "size.treeItemHeight", 28.0f);
|
||
|
|
case UIEditorCollectionPrimitiveKind::ListItem:
|
||
|
|
return ResolveFloatToken(theme, "size.listItemHeight", 60.0f);
|
||
|
|
case UIEditorCollectionPrimitiveKind::FieldRow:
|
||
|
|
return ResolveFloatToken(theme, "size.fieldRowHeight", 32.0f);
|
||
|
|
case UIEditorCollectionPrimitiveKind::PropertySection:
|
||
|
|
return ResolveFloatToken(theme, "size.propertySectionHeight", 148.0f);
|
||
|
|
default:
|
||
|
|
return 0.0f;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
float ResolveUIEditorCollectionPrimitiveIndent(
|
||
|
|
UIEditorCollectionPrimitiveKind kind,
|
||
|
|
const Style::UITheme& theme,
|
||
|
|
float indentLevel) {
|
||
|
|
return kind == UIEditorCollectionPrimitiveKind::TreeItem
|
||
|
|
? indentLevel * ResolveFloatToken(theme, "size.treeIndent", 18.0f)
|
||
|
|
: 0.0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace Widgets
|
||
|
|
} // namespace UI
|
||
|
|
} // namespace XCEngine
|