ui: add typed editor field foundations
This commit is contained in:
@@ -1,11 +1,30 @@
|
||||
#include <XCEditor/Widgets/UIEditorPropertyGrid.h>
|
||||
|
||||
#include <XCEditor/Core/UIEditorTheme.h>
|
||||
#include <XCEditor/Widgets/UIEditorBoolField.h>
|
||||
#include <XCEditor/Widgets/UIEditorEnumField.h>
|
||||
#include <XCEditor/Widgets/UIEditorMenuPopup.h>
|
||||
#include <XCEditor/Widgets/UIEditorNumberField.h>
|
||||
#include <XCEditor/Widgets/UIEditorTextField.h>
|
||||
#include <XCEditor/Widgets/UIEditorTextLayout.h>
|
||||
|
||||
#include <XCEngine/UI/Widgets/UIPopupOverlayModel.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::Widgets {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
using ::XCEngine::UI::UISize;
|
||||
using ::XCEngine::UI::Widgets::ResolvePopupPlacementRect;
|
||||
using ::XCEngine::UI::Widgets::UIPopupPlacement;
|
||||
using ::XCEngine::UI::Editor::UIEditorMenuItemKind;
|
||||
|
||||
float ClampNonNegative(float value) {
|
||||
return (std::max)(value, 0.0f);
|
||||
}
|
||||
@@ -26,16 +45,105 @@ float ResolveFieldRowHeight(
|
||||
: metrics.fieldRowHeight;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UIPoint ResolveDisclosureGlyphPosition(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
float textInsetY) {
|
||||
return ::XCEngine::UI::UIPoint(rect.x + 2.0f, rect.y + textInsetY - 1.0f);
|
||||
UIPoint ResolveDisclosureGlyphPosition(
|
||||
const UIRect& rect,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
return UIPoint(
|
||||
rect.x + metrics.disclosureGlyphInsetX,
|
||||
rect.y + metrics.sectionTextInsetY + metrics.disclosureGlyphInsetY);
|
||||
}
|
||||
|
||||
const std::string& ResolveDisplayedFieldValue(
|
||||
UIEditorBoolFieldSpec BuildBoolFieldSpec(const UIEditorPropertyGridField& field) {
|
||||
UIEditorBoolFieldSpec spec = {};
|
||||
spec.fieldId = field.fieldId;
|
||||
spec.label = field.label;
|
||||
spec.value = field.boolValue;
|
||||
spec.readOnly = field.readOnly;
|
||||
return spec;
|
||||
}
|
||||
|
||||
UIEditorNumberFieldSpec BuildNumberFieldSpec(const UIEditorPropertyGridField& field) {
|
||||
UIEditorNumberFieldSpec spec = {};
|
||||
spec.fieldId = field.fieldId;
|
||||
spec.label = field.label;
|
||||
spec.value = field.numberValue.value;
|
||||
spec.step = field.numberValue.step;
|
||||
spec.minValue = field.numberValue.minValue;
|
||||
spec.maxValue = field.numberValue.maxValue;
|
||||
spec.integerMode = field.numberValue.integerMode;
|
||||
spec.readOnly = field.readOnly;
|
||||
return spec;
|
||||
}
|
||||
|
||||
UIEditorEnumFieldSpec BuildEnumFieldSpec(const UIEditorPropertyGridField& field) {
|
||||
UIEditorEnumFieldSpec spec = {};
|
||||
spec.fieldId = field.fieldId;
|
||||
spec.label = field.label;
|
||||
spec.options = field.enumValue.options;
|
||||
spec.selectedIndex = field.enumValue.selectedIndex;
|
||||
spec.readOnly = field.readOnly;
|
||||
return spec;
|
||||
}
|
||||
|
||||
UIEditorTextFieldSpec BuildTextFieldSpec(const UIEditorPropertyGridField& field) {
|
||||
UIEditorTextFieldSpec spec = {};
|
||||
spec.fieldId = field.fieldId;
|
||||
spec.label = field.label;
|
||||
spec.value = field.valueText;
|
||||
spec.readOnly = field.readOnly;
|
||||
return spec;
|
||||
}
|
||||
|
||||
struct UIEditorPropertyGridFieldRects {
|
||||
UIRect labelRect = {};
|
||||
UIRect valueRect = {};
|
||||
};
|
||||
|
||||
UIEditorPropertyGridFieldRects ResolveFieldRects(
|
||||
const UIRect& rowRect,
|
||||
const UIEditorPropertyGridField& field,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
switch (field.kind) {
|
||||
case UIEditorPropertyGridFieldKind::Bool: {
|
||||
const UIEditorBoolFieldLayout fieldLayout = BuildUIEditorBoolFieldLayout(
|
||||
rowRect,
|
||||
BuildBoolFieldSpec(field),
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedBoolFieldMetrics(metrics));
|
||||
return { fieldLayout.labelRect, fieldLayout.controlRect };
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Number: {
|
||||
const UIEditorNumberFieldLayout fieldLayout = BuildUIEditorNumberFieldLayout(
|
||||
rowRect,
|
||||
BuildNumberFieldSpec(field),
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedNumberFieldMetrics(metrics));
|
||||
return { fieldLayout.labelRect, fieldLayout.valueRect };
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Enum: {
|
||||
const UIEditorEnumFieldLayout fieldLayout = BuildUIEditorEnumFieldLayout(
|
||||
rowRect,
|
||||
BuildEnumFieldSpec(field),
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedEnumFieldMetrics(metrics));
|
||||
return { fieldLayout.labelRect, fieldLayout.valueRect };
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Text:
|
||||
default: {
|
||||
const UIEditorTextFieldLayout fieldLayout = BuildUIEditorTextFieldLayout(
|
||||
rowRect,
|
||||
BuildTextFieldSpec(field),
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedTextFieldMetrics(metrics));
|
||||
return { fieldLayout.labelRect, fieldLayout.valueRect };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& ResolveDisplayedTextFieldValue(
|
||||
const UIEditorPropertyGridField& field,
|
||||
const ::XCEngine::UI::Widgets::UIPropertyEditModel& propertyEditModel) {
|
||||
if (propertyEditModel.HasActiveEdit() &&
|
||||
if (field.kind == UIEditorPropertyGridFieldKind::Text &&
|
||||
propertyEditModel.HasActiveEdit() &&
|
||||
propertyEditModel.GetActiveFieldId() == field.fieldId) {
|
||||
return propertyEditModel.GetStagedValue();
|
||||
}
|
||||
@@ -43,11 +151,140 @@ const std::string& ResolveDisplayedFieldValue(
|
||||
return field.valueText;
|
||||
}
|
||||
|
||||
UIEditorBoolFieldHitTargetKind ResolveBoolHoveredTarget(
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridField& field) {
|
||||
if (state.hoveredFieldId != field.fieldId) {
|
||||
return UIEditorBoolFieldHitTargetKind::None;
|
||||
}
|
||||
|
||||
return state.hoveredHitTarget == UIEditorPropertyGridHitTargetKind::ValueBox
|
||||
? UIEditorBoolFieldHitTargetKind::Checkbox
|
||||
: UIEditorBoolFieldHitTargetKind::Row;
|
||||
}
|
||||
|
||||
UIEditorNumberFieldHitTargetKind ResolveNumberHoveredTarget(
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridField& field) {
|
||||
if (state.hoveredFieldId != field.fieldId) {
|
||||
return UIEditorNumberFieldHitTargetKind::None;
|
||||
}
|
||||
|
||||
return state.hoveredHitTarget == UIEditorPropertyGridHitTargetKind::ValueBox
|
||||
? UIEditorNumberFieldHitTargetKind::ValueBox
|
||||
: UIEditorNumberFieldHitTargetKind::Row;
|
||||
}
|
||||
|
||||
UIEditorEnumFieldHitTargetKind ResolveEnumHoveredTarget(
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridField& field) {
|
||||
if (state.hoveredFieldId != field.fieldId) {
|
||||
return UIEditorEnumFieldHitTargetKind::None;
|
||||
}
|
||||
|
||||
return state.hoveredHitTarget == UIEditorPropertyGridHitTargetKind::ValueBox
|
||||
? UIEditorEnumFieldHitTargetKind::ValueBox
|
||||
: UIEditorEnumFieldHitTargetKind::Row;
|
||||
}
|
||||
|
||||
UIEditorTextFieldHitTargetKind ResolveTextHoveredTarget(
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridField& field) {
|
||||
if (state.hoveredFieldId != field.fieldId) {
|
||||
return UIEditorTextFieldHitTargetKind::None;
|
||||
}
|
||||
|
||||
return state.hoveredHitTarget == UIEditorPropertyGridHitTargetKind::ValueBox
|
||||
? UIEditorTextFieldHitTargetKind::ValueBox
|
||||
: UIEditorTextFieldHitTargetKind::Row;
|
||||
}
|
||||
|
||||
std::vector<UIEditorMenuPopupItem> BuildEnumPopupItems(
|
||||
const UIEditorPropertyGridField& field) {
|
||||
std::vector<UIEditorMenuPopupItem> items = {};
|
||||
if (field.kind != UIEditorPropertyGridFieldKind::Enum) {
|
||||
return items;
|
||||
}
|
||||
|
||||
items.reserve(field.enumValue.options.size());
|
||||
const std::size_t selectedIndex =
|
||||
field.enumValue.options.empty()
|
||||
? 0u
|
||||
: (std::min)(field.enumValue.selectedIndex, field.enumValue.options.size() - 1u);
|
||||
for (std::size_t index = 0u; index < field.enumValue.options.size(); ++index) {
|
||||
UIEditorMenuPopupItem item = {};
|
||||
item.itemId = field.fieldId + "." + std::to_string(index);
|
||||
item.kind = UIEditorMenuItemKind::Command;
|
||||
item.label = field.enumValue.options[index];
|
||||
item.enabled = !field.readOnly;
|
||||
item.checked = index == selectedIndex;
|
||||
items.push_back(std::move(item));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
UIRect ResolvePopupViewportRect(const UIRect& bounds) {
|
||||
return UIRect(bounds.x - 4096.0f, bounds.y - 4096.0f, 8192.0f, 8192.0f);
|
||||
}
|
||||
|
||||
bool BuildEnumPopupRuntime(
|
||||
const UIEditorPropertyGridLayout& layout,
|
||||
const std::vector<UIEditorPropertyGridSection>& sections,
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorMenuPopupMetrics& popupMetrics,
|
||||
UIEditorMenuPopupLayout& popupLayout,
|
||||
UIEditorMenuPopupState& popupState,
|
||||
std::vector<UIEditorMenuPopupItem>& popupItems) {
|
||||
if (state.popupFieldId.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t visibleFieldIndex =
|
||||
FindUIEditorPropertyGridVisibleFieldIndex(layout, state.popupFieldId, sections);
|
||||
if (visibleFieldIndex == UIEditorPropertyGridInvalidIndex ||
|
||||
visibleFieldIndex >= layout.visibleFieldSectionIndices.size() ||
|
||||
visibleFieldIndex >= layout.visibleFieldIndices.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t sectionIndex = layout.visibleFieldSectionIndices[visibleFieldIndex];
|
||||
const std::size_t fieldIndex = layout.visibleFieldIndices[visibleFieldIndex];
|
||||
if (sectionIndex >= sections.size() ||
|
||||
fieldIndex >= sections[sectionIndex].fields.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const UIEditorPropertyGridField& field = sections[sectionIndex].fields[fieldIndex];
|
||||
popupItems = BuildEnumPopupItems(field);
|
||||
if (popupItems.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const float popupWidth = (std::max)(
|
||||
layout.fieldValueRects[visibleFieldIndex].width,
|
||||
ResolveUIEditorMenuPopupDesiredWidth(popupItems, popupMetrics));
|
||||
const float popupHeight = MeasureUIEditorMenuPopupHeight(popupItems, popupMetrics);
|
||||
const auto placement = ResolvePopupPlacementRect(
|
||||
layout.fieldValueRects[visibleFieldIndex],
|
||||
UISize(popupWidth, popupHeight),
|
||||
ResolvePopupViewportRect(layout.bounds),
|
||||
UIPopupPlacement::BottomStart);
|
||||
|
||||
popupLayout = BuildUIEditorMenuPopupLayout(placement.rect, popupItems, popupMetrics);
|
||||
popupState.focused = state.focused || !state.popupFieldId.empty();
|
||||
popupState.hoveredIndex =
|
||||
state.popupHighlightedIndex < popupItems.size()
|
||||
? state.popupHighlightedIndex
|
||||
: UIEditorMenuPopupInvalidIndex;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool IsUIEditorPropertyGridPointInside(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
const ::XCEngine::UI::UIPoint& point) {
|
||||
const UIRect& rect,
|
||||
const UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
@@ -81,6 +318,24 @@ UIEditorPropertyGridFieldLocation FindUIEditorPropertyGridFieldLocation(
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string ResolveUIEditorPropertyGridFieldValueText(
|
||||
const UIEditorPropertyGridField& field) {
|
||||
switch (field.kind) {
|
||||
case UIEditorPropertyGridFieldKind::Bool:
|
||||
return field.boolValue ? "true" : "false";
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Number:
|
||||
return FormatUIEditorNumberFieldValue(BuildNumberFieldSpec(field));
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Enum:
|
||||
return ResolveUIEditorEnumFieldValueText(BuildEnumFieldSpec(field));
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Text:
|
||||
default:
|
||||
return field.valueText;
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t FindUIEditorPropertyGridVisibleFieldIndex(
|
||||
const UIEditorPropertyGridLayout& layout,
|
||||
std::string_view fieldId,
|
||||
@@ -104,12 +359,12 @@ std::size_t FindUIEditorPropertyGridVisibleFieldIndex(
|
||||
}
|
||||
|
||||
UIEditorPropertyGridLayout BuildUIEditorPropertyGridLayout(
|
||||
const ::XCEngine::UI::UIRect& bounds,
|
||||
const UIRect& bounds,
|
||||
const std::vector<UIEditorPropertyGridSection>& sections,
|
||||
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
UIEditorPropertyGridLayout layout = {};
|
||||
layout.bounds = ::XCEngine::UI::UIRect(
|
||||
layout.bounds = UIRect(
|
||||
bounds.x,
|
||||
bounds.y,
|
||||
ClampNonNegative(bounds.width),
|
||||
@@ -126,19 +381,19 @@ UIEditorPropertyGridLayout BuildUIEditorPropertyGridLayout(
|
||||
const float headerHeight = ResolveSectionHeaderHeight(section, metrics);
|
||||
const bool expanded = expansionModel.IsExpanded(section.sectionId);
|
||||
|
||||
const ::XCEngine::UI::UIRect headerRect(
|
||||
const UIRect headerRect(
|
||||
contentX,
|
||||
cursorY,
|
||||
contentWidth,
|
||||
headerHeight);
|
||||
const ::XCEngine::UI::UIRect disclosureRect(
|
||||
const UIRect disclosureRect(
|
||||
headerRect.x + metrics.horizontalPadding,
|
||||
headerRect.y + (headerRect.height - metrics.disclosureExtent) * 0.5f,
|
||||
metrics.disclosureExtent,
|
||||
metrics.disclosureExtent);
|
||||
const float titleX =
|
||||
disclosureRect.x + disclosureRect.width + metrics.disclosureLabelGap;
|
||||
const ::XCEngine::UI::UIRect titleRect(
|
||||
const UIRect titleRect(
|
||||
titleX,
|
||||
headerRect.y,
|
||||
(std::max)(0.0f, headerRect.x + headerRect.width - titleX - metrics.horizontalPadding),
|
||||
@@ -155,37 +410,19 @@ UIEditorPropertyGridLayout BuildUIEditorPropertyGridLayout(
|
||||
for (std::size_t fieldIndex = 0u; fieldIndex < section.fields.size(); ++fieldIndex) {
|
||||
const UIEditorPropertyGridField& field = section.fields[fieldIndex];
|
||||
const float rowHeight = ResolveFieldRowHeight(field, metrics);
|
||||
const ::XCEngine::UI::UIRect rowRect(
|
||||
const UIRect rowRect(
|
||||
contentX,
|
||||
cursorY,
|
||||
contentWidth,
|
||||
rowHeight);
|
||||
const float controlX =
|
||||
(std::min)(
|
||||
rowRect.x + rowRect.width - metrics.horizontalPadding,
|
||||
rowRect.x + metrics.controlColumnStart);
|
||||
const float labelWidth =
|
||||
(std::max)(
|
||||
0.0f,
|
||||
controlX - rowRect.x - metrics.horizontalPadding - metrics.labelControlGap);
|
||||
const ::XCEngine::UI::UIRect labelRect(
|
||||
rowRect.x + metrics.horizontalPadding,
|
||||
rowRect.y,
|
||||
labelWidth,
|
||||
rowRect.height);
|
||||
const ::XCEngine::UI::UIRect valueRect(
|
||||
controlX,
|
||||
rowRect.y + metrics.valueBoxInsetY,
|
||||
(std::max)(
|
||||
0.0f,
|
||||
rowRect.x + rowRect.width - controlX - metrics.horizontalPadding),
|
||||
(std::max)(0.0f, rowRect.height - metrics.valueBoxInsetY * 2.0f));
|
||||
const UIEditorPropertyGridFieldRects fieldRects =
|
||||
ResolveFieldRects(rowRect, field, metrics);
|
||||
|
||||
layout.visibleFieldSectionIndices.push_back(sectionIndex);
|
||||
layout.visibleFieldIndices.push_back(fieldIndex);
|
||||
layout.fieldRowRects.push_back(rowRect);
|
||||
layout.fieldLabelRects.push_back(labelRect);
|
||||
layout.fieldValueRects.push_back(valueRect);
|
||||
layout.fieldLabelRects.push_back(fieldRects.labelRect);
|
||||
layout.fieldValueRects.push_back(fieldRects.valueRect);
|
||||
layout.fieldReadOnly.push_back(field.readOnly);
|
||||
|
||||
cursorY += rowHeight + metrics.rowGap;
|
||||
@@ -204,7 +441,7 @@ UIEditorPropertyGridLayout BuildUIEditorPropertyGridLayout(
|
||||
|
||||
UIEditorPropertyGridHitTarget HitTestUIEditorPropertyGrid(
|
||||
const UIEditorPropertyGridLayout& layout,
|
||||
const ::XCEngine::UI::UIPoint& point) {
|
||||
const UIPoint& point) {
|
||||
for (std::size_t sectionVisibleIndex = 0u;
|
||||
sectionVisibleIndex < layout.sectionHeaderRects.size();
|
||||
++sectionVisibleIndex) {
|
||||
@@ -239,11 +476,11 @@ UIEditorPropertyGridHitTarget HitTestUIEditorPropertyGrid(
|
||||
}
|
||||
|
||||
void AppendUIEditorPropertyGridBackground(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
UIDrawList& drawList,
|
||||
const UIEditorPropertyGridLayout& layout,
|
||||
const std::vector<UIEditorPropertyGridSection>& sections,
|
||||
const ::XCEngine::UI::Widgets::UISelectionModel& selectionModel,
|
||||
const ::XCEngine::UI::Widgets::UIPropertyEditModel& propertyEditModel,
|
||||
const ::XCEngine::UI::Widgets::UIPropertyEditModel&,
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridPalette& palette,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
@@ -277,8 +514,6 @@ void AppendUIEditorPropertyGridBackground(
|
||||
section.fields[layout.visibleFieldIndices[visibleFieldIndex]];
|
||||
const bool selected = selectionModel.IsSelected(field.fieldId);
|
||||
const bool hovered = state.hoveredFieldId == field.fieldId;
|
||||
const bool editing = propertyEditModel.HasActiveEdit() &&
|
||||
propertyEditModel.GetActiveFieldId() == field.fieldId;
|
||||
|
||||
if (selected || hovered) {
|
||||
drawList.AddFilledRect(
|
||||
@@ -288,32 +523,19 @@ void AppendUIEditorPropertyGridBackground(
|
||||
: palette.fieldHoverColor,
|
||||
metrics.cornerRounding);
|
||||
}
|
||||
|
||||
const ::XCEngine::UI::UIColor valueBoxColor =
|
||||
field.readOnly
|
||||
? palette.valueBoxReadOnlyColor
|
||||
: (editing
|
||||
? palette.valueBoxEditingColor
|
||||
: (hovered ? palette.valueBoxHoverColor : palette.valueBoxColor));
|
||||
drawList.AddFilledRect(
|
||||
layout.fieldValueRects[visibleFieldIndex],
|
||||
valueBoxColor,
|
||||
metrics.valueBoxRounding);
|
||||
drawList.AddRectOutline(
|
||||
layout.fieldValueRects[visibleFieldIndex],
|
||||
editing ? palette.valueBoxEditingBorderColor : palette.valueBoxBorderColor,
|
||||
editing ? metrics.editOutlineThickness : metrics.borderThickness,
|
||||
metrics.valueBoxRounding);
|
||||
}
|
||||
}
|
||||
|
||||
void AppendUIEditorPropertyGridForeground(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
UIDrawList& drawList,
|
||||
const UIEditorPropertyGridLayout& layout,
|
||||
const std::vector<UIEditorPropertyGridSection>& sections,
|
||||
const UIEditorPropertyGridState& state,
|
||||
const ::XCEngine::UI::Widgets::UIPropertyEditModel& propertyEditModel,
|
||||
const UIEditorPropertyGridPalette& palette,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
const UIEditorPropertyGridMetrics& metrics,
|
||||
const UIEditorMenuPopupPalette& popupPalette,
|
||||
const UIEditorMenuPopupMetrics& popupMetrics) {
|
||||
drawList.PushClipRect(layout.bounds);
|
||||
|
||||
for (std::size_t sectionVisibleIndex = 0u;
|
||||
@@ -324,19 +546,36 @@ void AppendUIEditorPropertyGridForeground(
|
||||
drawList.AddText(
|
||||
ResolveDisclosureGlyphPosition(
|
||||
layout.sectionDisclosureRects[sectionVisibleIndex],
|
||||
metrics.sectionTextInsetY),
|
||||
metrics),
|
||||
layout.sectionExpanded[sectionVisibleIndex] ? "v" : ">",
|
||||
palette.disclosureColor,
|
||||
12.0f);
|
||||
metrics.disclosureGlyphFontSize);
|
||||
drawList.AddText(
|
||||
::XCEngine::UI::UIPoint(
|
||||
UIPoint(
|
||||
layout.sectionTitleRects[sectionVisibleIndex].x,
|
||||
layout.sectionTitleRects[sectionVisibleIndex].y + metrics.sectionTextInsetY),
|
||||
section.title,
|
||||
palette.sectionTextColor,
|
||||
12.0f);
|
||||
metrics.sectionFontSize);
|
||||
}
|
||||
|
||||
const UIEditorBoolFieldMetrics boolMetrics =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedBoolFieldMetrics(metrics);
|
||||
const UIEditorBoolFieldPalette boolPalette =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedBoolFieldPalette(palette);
|
||||
const UIEditorNumberFieldMetrics numberMetrics =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedNumberFieldMetrics(metrics);
|
||||
const UIEditorNumberFieldPalette numberPalette =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedNumberFieldPalette(palette);
|
||||
const UIEditorTextFieldMetrics textMetrics =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedTextFieldMetrics(metrics);
|
||||
const UIEditorTextFieldPalette textPalette =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedTextFieldPalette(palette);
|
||||
const UIEditorEnumFieldMetrics enumMetrics =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedEnumFieldMetrics(metrics);
|
||||
const UIEditorEnumFieldPalette enumPalette =
|
||||
::XCEngine::UI::Editor::BuildUIEditorHostedEnumFieldPalette(palette);
|
||||
|
||||
for (std::size_t visibleFieldIndex = 0u;
|
||||
visibleFieldIndex < layout.fieldRowRects.size();
|
||||
++visibleFieldIndex) {
|
||||
@@ -346,53 +585,133 @@ void AppendUIEditorPropertyGridForeground(
|
||||
section.fields[layout.visibleFieldIndices[visibleFieldIndex]];
|
||||
const bool editing = propertyEditModel.HasActiveEdit() &&
|
||||
propertyEditModel.GetActiveFieldId() == field.fieldId;
|
||||
const std::string& displayedValue =
|
||||
ResolveDisplayedFieldValue(field, propertyEditModel);
|
||||
|
||||
drawList.PushClipRect(layout.fieldLabelRects[visibleFieldIndex]);
|
||||
drawList.AddText(
|
||||
::XCEngine::UI::UIPoint(
|
||||
layout.fieldLabelRects[visibleFieldIndex].x,
|
||||
layout.fieldLabelRects[visibleFieldIndex].y + metrics.labelTextInsetY),
|
||||
field.label,
|
||||
palette.labelTextColor,
|
||||
12.0f);
|
||||
drawList.PopClipRect();
|
||||
|
||||
drawList.PushClipRect(layout.fieldValueRects[visibleFieldIndex]);
|
||||
drawList.AddText(
|
||||
::XCEngine::UI::UIPoint(
|
||||
layout.fieldValueRects[visibleFieldIndex].x + metrics.valueBoxInsetX,
|
||||
layout.fieldValueRects[visibleFieldIndex].y + metrics.valueTextInsetY),
|
||||
displayedValue,
|
||||
field.readOnly ? palette.readOnlyValueTextColor : palette.valueTextColor,
|
||||
12.0f);
|
||||
if (editing) {
|
||||
drawList.AddText(
|
||||
::XCEngine::UI::UIPoint(
|
||||
layout.fieldValueRects[visibleFieldIndex].x +
|
||||
(std::max)(0.0f, layout.fieldValueRects[visibleFieldIndex].width - 34.0f),
|
||||
layout.fieldValueRects[visibleFieldIndex].y + metrics.valueTextInsetY),
|
||||
"EDIT",
|
||||
palette.editTagColor,
|
||||
11.0f);
|
||||
switch (field.kind) {
|
||||
case UIEditorPropertyGridFieldKind::Bool: {
|
||||
UIEditorBoolFieldState fieldState = {};
|
||||
fieldState.hoveredTarget = ResolveBoolHoveredTarget(state, field);
|
||||
fieldState.focused = state.focused;
|
||||
fieldState.active = state.pressedFieldId == field.fieldId;
|
||||
AppendUIEditorBoolField(
|
||||
drawList,
|
||||
layout.fieldRowRects[visibleFieldIndex],
|
||||
BuildBoolFieldSpec(field),
|
||||
fieldState,
|
||||
boolPalette,
|
||||
boolMetrics);
|
||||
break;
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Number: {
|
||||
UIEditorNumberFieldState fieldState = {};
|
||||
fieldState.hoveredTarget = ResolveNumberHoveredTarget(state, field);
|
||||
fieldState.activeTarget =
|
||||
state.pressedFieldId == field.fieldId
|
||||
? UIEditorNumberFieldHitTargetKind::ValueBox
|
||||
: UIEditorNumberFieldHitTargetKind::None;
|
||||
fieldState.focused = state.focused;
|
||||
fieldState.editing = editing;
|
||||
fieldState.displayText = editing
|
||||
? propertyEditModel.GetStagedValue()
|
||||
: ResolveUIEditorPropertyGridFieldValueText(field);
|
||||
AppendUIEditorNumberField(
|
||||
drawList,
|
||||
layout.fieldRowRects[visibleFieldIndex],
|
||||
BuildNumberFieldSpec(field),
|
||||
fieldState,
|
||||
numberPalette,
|
||||
numberMetrics);
|
||||
break;
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Enum: {
|
||||
UIEditorEnumFieldState fieldState = {};
|
||||
fieldState.hoveredTarget = ResolveEnumHoveredTarget(state, field);
|
||||
fieldState.focused = state.focused;
|
||||
fieldState.active = state.pressedFieldId == field.fieldId;
|
||||
fieldState.popupOpen = state.popupFieldId == field.fieldId;
|
||||
AppendUIEditorEnumField(
|
||||
drawList,
|
||||
layout.fieldRowRects[visibleFieldIndex],
|
||||
BuildEnumFieldSpec(field),
|
||||
fieldState,
|
||||
enumPalette,
|
||||
enumMetrics);
|
||||
break;
|
||||
}
|
||||
|
||||
case UIEditorPropertyGridFieldKind::Text:
|
||||
default: {
|
||||
const std::string& displayedValue =
|
||||
ResolveDisplayedTextFieldValue(field, propertyEditModel);
|
||||
UIEditorTextFieldState fieldState = {};
|
||||
fieldState.hoveredTarget = ResolveTextHoveredTarget(state, field);
|
||||
fieldState.activeTarget =
|
||||
state.pressedFieldId == field.fieldId
|
||||
? (state.hoveredHitTarget == UIEditorPropertyGridHitTargetKind::ValueBox
|
||||
? UIEditorTextFieldHitTargetKind::ValueBox
|
||||
: UIEditorTextFieldHitTargetKind::Row)
|
||||
: UIEditorTextFieldHitTargetKind::None;
|
||||
fieldState.focused = state.focused;
|
||||
fieldState.editing = editing;
|
||||
fieldState.displayText = displayedValue;
|
||||
|
||||
UIEditorTextFieldSpec fieldSpec = BuildTextFieldSpec(field);
|
||||
fieldSpec.value = editing ? std::string() : displayedValue;
|
||||
AppendUIEditorTextField(
|
||||
drawList,
|
||||
layout.fieldRowRects[visibleFieldIndex],
|
||||
fieldSpec,
|
||||
fieldState,
|
||||
textPalette,
|
||||
textMetrics);
|
||||
|
||||
if (editing) {
|
||||
drawList.PushClipRect(
|
||||
ResolveUIEditorTextClipRect(
|
||||
layout.fieldValueRects[visibleFieldIndex],
|
||||
metrics.tagFontSize));
|
||||
drawList.AddText(
|
||||
UIPoint(
|
||||
layout.fieldValueRects[visibleFieldIndex].x +
|
||||
(std::max)(0.0f, layout.fieldValueRects[visibleFieldIndex].width - 34.0f),
|
||||
ResolveUIEditorTextTop(
|
||||
layout.fieldValueRects[visibleFieldIndex],
|
||||
metrics.tagFontSize,
|
||||
metrics.valueTextInsetY)),
|
||||
"EDIT",
|
||||
palette.editTagColor,
|
||||
metrics.tagFontSize);
|
||||
drawList.PopClipRect();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
drawList.PopClipRect();
|
||||
}
|
||||
|
||||
drawList.PopClipRect();
|
||||
|
||||
UIEditorMenuPopupLayout popupLayout = {};
|
||||
UIEditorMenuPopupState popupState = {};
|
||||
std::vector<UIEditorMenuPopupItem> popupItems = {};
|
||||
if (BuildEnumPopupRuntime(layout, sections, state, popupMetrics, popupLayout, popupState, popupItems)) {
|
||||
AppendUIEditorMenuPopupBackground(drawList, popupLayout, popupItems, popupState, popupPalette, popupMetrics);
|
||||
AppendUIEditorMenuPopupForeground(drawList, popupLayout, popupItems, popupState, popupPalette, popupMetrics);
|
||||
}
|
||||
}
|
||||
|
||||
void AppendUIEditorPropertyGrid(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
const ::XCEngine::UI::UIRect& bounds,
|
||||
UIDrawList& drawList,
|
||||
const UIRect& bounds,
|
||||
const std::vector<UIEditorPropertyGridSection>& sections,
|
||||
const ::XCEngine::UI::Widgets::UISelectionModel& selectionModel,
|
||||
const ::XCEngine::UI::Widgets::UIExpansionModel& expansionModel,
|
||||
const ::XCEngine::UI::Widgets::UIPropertyEditModel& propertyEditModel,
|
||||
const UIEditorPropertyGridState& state,
|
||||
const UIEditorPropertyGridPalette& palette,
|
||||
const UIEditorPropertyGridMetrics& metrics) {
|
||||
const UIEditorPropertyGridMetrics& metrics,
|
||||
const UIEditorMenuPopupPalette& popupPalette,
|
||||
const UIEditorMenuPopupMetrics& popupMetrics) {
|
||||
const UIEditorPropertyGridLayout layout =
|
||||
BuildUIEditorPropertyGridLayout(bounds, sections, expansionModel, metrics);
|
||||
AppendUIEditorPropertyGridBackground(
|
||||
@@ -408,9 +727,12 @@ void AppendUIEditorPropertyGrid(
|
||||
drawList,
|
||||
layout,
|
||||
sections,
|
||||
state,
|
||||
propertyEditModel,
|
||||
palette,
|
||||
metrics);
|
||||
metrics,
|
||||
popupPalette,
|
||||
popupMetrics);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Widgets
|
||||
|
||||
Reference in New Issue
Block a user