ui: add vector4 editor field validation
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <XCEditor/Widgets/UIEditorTextField.h>
|
||||
#include <XCEditor/Widgets/UIEditorVector2Field.h>
|
||||
#include <XCEditor/Widgets/UIEditorVector3Field.h>
|
||||
#include <XCEditor/Widgets/UIEditorVector4Field.h>
|
||||
|
||||
#include <XCEngine/UI/Style/Theme.h>
|
||||
|
||||
@@ -65,6 +66,14 @@ Widgets::UIEditorVector3FieldPalette ResolveUIEditorVector3FieldPalette(
|
||||
const ::XCEngine::UI::Style::UITheme& theme,
|
||||
const Widgets::UIEditorVector3FieldPalette& fallback = {});
|
||||
|
||||
Widgets::UIEditorVector4FieldMetrics ResolveUIEditorVector4FieldMetrics(
|
||||
const ::XCEngine::UI::Style::UITheme& theme,
|
||||
const Widgets::UIEditorVector4FieldMetrics& fallback = {});
|
||||
|
||||
Widgets::UIEditorVector4FieldPalette ResolveUIEditorVector4FieldPalette(
|
||||
const ::XCEngine::UI::Style::UITheme& theme,
|
||||
const Widgets::UIEditorVector4FieldPalette& fallback = {});
|
||||
|
||||
Widgets::UIEditorEnumFieldMetrics ResolveUIEditorEnumFieldMetrics(
|
||||
const ::XCEngine::UI::Style::UITheme& theme,
|
||||
const Widgets::UIEditorEnumFieldMetrics& fallback = {});
|
||||
@@ -129,6 +138,14 @@ Widgets::UIEditorVector3FieldPalette BuildUIEditorHostedVector3FieldPalette(
|
||||
const Widgets::UIEditorPropertyGridPalette& propertyGridPalette,
|
||||
const Widgets::UIEditorVector3FieldPalette& fallback = {});
|
||||
|
||||
Widgets::UIEditorVector4FieldMetrics BuildUIEditorHostedVector4FieldMetrics(
|
||||
const Widgets::UIEditorPropertyGridMetrics& propertyGridMetrics,
|
||||
const Widgets::UIEditorVector4FieldMetrics& fallback = {});
|
||||
|
||||
Widgets::UIEditorVector4FieldPalette BuildUIEditorHostedVector4FieldPalette(
|
||||
const Widgets::UIEditorPropertyGridPalette& propertyGridPalette,
|
||||
const Widgets::UIEditorVector4FieldPalette& fallback = {});
|
||||
|
||||
Widgets::UIEditorEnumFieldMetrics BuildUIEditorHostedEnumFieldMetrics(
|
||||
const Widgets::UIEditorPropertyGridMetrics& propertyGridMetrics,
|
||||
const Widgets::UIEditorEnumFieldMetrics& fallback = {});
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEditor/Widgets/UIEditorVector4Field.h>
|
||||
|
||||
#include <XCEngine/UI/Text/UITextInputController.h>
|
||||
#include <XCEngine/UI/Types.h>
|
||||
#include <XCEngine/UI/Widgets/UIPropertyEditModel.h>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine::UI::Editor {
|
||||
|
||||
struct UIEditorVector4FieldInteractionState {
|
||||
Widgets::UIEditorVector4FieldState vector4FieldState = {};
|
||||
::XCEngine::UI::Text::UITextInputState textInputState = {};
|
||||
::XCEngine::UI::Widgets::UIPropertyEditModel editModel = {};
|
||||
::XCEngine::UI::UIPoint pointerPosition = {};
|
||||
bool hasPointerPosition = false;
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldInteractionResult {
|
||||
bool consumed = false;
|
||||
bool focusChanged = false;
|
||||
bool valueChanged = false;
|
||||
bool stepApplied = false;
|
||||
bool selectionChanged = false;
|
||||
bool editStarted = false;
|
||||
bool editCommitted = false;
|
||||
bool editCommitRejected = false;
|
||||
bool editCanceled = false;
|
||||
Widgets::UIEditorVector4FieldHitTarget hitTarget = {};
|
||||
std::size_t selectedComponentIndex = Widgets::UIEditorVector4FieldInvalidComponentIndex;
|
||||
std::size_t changedComponentIndex = Widgets::UIEditorVector4FieldInvalidComponentIndex;
|
||||
std::array<double, 4u> valuesBefore = { 0.0, 0.0, 0.0, 0.0 };
|
||||
std::array<double, 4u> valuesAfter = { 0.0, 0.0, 0.0, 0.0 };
|
||||
double stepDelta = 0.0;
|
||||
std::string committedText = {};
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldInteractionFrame {
|
||||
Widgets::UIEditorVector4FieldLayout layout = {};
|
||||
UIEditorVector4FieldInteractionResult result = {};
|
||||
};
|
||||
|
||||
UIEditorVector4FieldInteractionFrame UpdateUIEditorVector4FieldInteraction(
|
||||
UIEditorVector4FieldInteractionState& state,
|
||||
Widgets::UIEditorVector4FieldSpec& spec,
|
||||
const ::XCEngine::UI::UIRect& bounds,
|
||||
const std::vector<::XCEngine::UI::UIInputEvent>& inputEvents,
|
||||
const Widgets::UIEditorVector4FieldMetrics& metrics = {});
|
||||
|
||||
} // namespace XCEngine::UI::Editor
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <XCEditor/Widgets/UIEditorMenuPopup.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -21,7 +22,10 @@ enum class UIEditorPropertyGridFieldKind : std::uint8_t {
|
||||
Text = 0,
|
||||
Bool,
|
||||
Number,
|
||||
Enum
|
||||
Enum,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4
|
||||
};
|
||||
|
||||
enum class UIEditorPropertyGridHitTargetKind : std::uint8_t {
|
||||
@@ -54,6 +58,42 @@ struct UIEditorPropertyGridEnumFieldValue {
|
||||
std::size_t selectedIndex = 0u;
|
||||
};
|
||||
|
||||
struct UIEditorPropertyGridVector2FieldValue {
|
||||
std::array<double, 2u> values = { 0.0, 0.0 };
|
||||
std::array<std::string, 2u> componentLabels = { std::string("X"), std::string("Y") };
|
||||
double step = 0.1;
|
||||
double minValue = -1000000.0;
|
||||
double maxValue = 1000000.0;
|
||||
bool integerMode = false;
|
||||
};
|
||||
|
||||
struct UIEditorPropertyGridVector3FieldValue {
|
||||
std::array<double, 3u> values = { 0.0, 0.0, 0.0 };
|
||||
std::array<std::string, 3u> componentLabels = {
|
||||
std::string("X"),
|
||||
std::string("Y"),
|
||||
std::string("Z")
|
||||
};
|
||||
double step = 0.1;
|
||||
double minValue = -1000000.0;
|
||||
double maxValue = 1000000.0;
|
||||
bool integerMode = false;
|
||||
};
|
||||
|
||||
struct UIEditorPropertyGridVector4FieldValue {
|
||||
std::array<double, 4u> values = { 0.0, 0.0, 0.0, 0.0 };
|
||||
std::array<std::string, 4u> componentLabels = {
|
||||
std::string("X"),
|
||||
std::string("Y"),
|
||||
std::string("Z"),
|
||||
std::string("W")
|
||||
};
|
||||
double step = 0.1;
|
||||
double minValue = -1000000.0;
|
||||
double maxValue = 1000000.0;
|
||||
bool integerMode = false;
|
||||
};
|
||||
|
||||
struct UIEditorPropertyGridField {
|
||||
std::string fieldId = {};
|
||||
std::string label = {};
|
||||
@@ -64,6 +104,9 @@ struct UIEditorPropertyGridField {
|
||||
bool boolValue = false;
|
||||
UIEditorPropertyGridNumberFieldValue numberValue = {};
|
||||
UIEditorPropertyGridEnumFieldValue enumValue = {};
|
||||
UIEditorPropertyGridVector2FieldValue vector2Value = {};
|
||||
UIEditorPropertyGridVector3FieldValue vector3Value = {};
|
||||
UIEditorPropertyGridVector4FieldValue vector4Value = {};
|
||||
};
|
||||
|
||||
struct UIEditorPropertyGridSection {
|
||||
|
||||
186
new_editor/include/XCEditor/Widgets/UIEditorVector4Field.h
Normal file
186
new_editor/include/XCEditor/Widgets/UIEditorVector4Field.h
Normal file
@@ -0,0 +1,186 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace XCEngine::UI::Editor::Widgets {
|
||||
|
||||
inline constexpr std::size_t UIEditorVector4FieldInvalidComponentIndex = static_cast<std::size_t>(-1);
|
||||
|
||||
enum class UIEditorVector4FieldHitTargetKind : std::uint8_t {
|
||||
None = 0,
|
||||
Row,
|
||||
Component
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldSpec {
|
||||
std::string fieldId = {};
|
||||
std::string label = {};
|
||||
std::array<double, 4u> values = { 0.0, 0.0, 0.0, 0.0 };
|
||||
std::array<std::string, 4u> componentLabels = {
|
||||
std::string("X"),
|
||||
std::string("Y"),
|
||||
std::string("Z"),
|
||||
std::string("W")
|
||||
};
|
||||
double step = 0.1;
|
||||
double minValue = -1000000.0;
|
||||
double maxValue = 1000000.0;
|
||||
bool integerMode = false;
|
||||
bool readOnly = false;
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldState {
|
||||
UIEditorVector4FieldHitTargetKind hoveredTarget = UIEditorVector4FieldHitTargetKind::None;
|
||||
UIEditorVector4FieldHitTargetKind activeTarget = UIEditorVector4FieldHitTargetKind::None;
|
||||
std::size_t hoveredComponentIndex = UIEditorVector4FieldInvalidComponentIndex;
|
||||
std::size_t activeComponentIndex = UIEditorVector4FieldInvalidComponentIndex;
|
||||
std::size_t selectedComponentIndex = UIEditorVector4FieldInvalidComponentIndex;
|
||||
bool focused = false;
|
||||
bool editing = false;
|
||||
std::array<std::string, 4u> displayTexts = {
|
||||
std::string(),
|
||||
std::string(),
|
||||
std::string(),
|
||||
std::string()
|
||||
};
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldMetrics {
|
||||
float rowHeight = 22.0f;
|
||||
float horizontalPadding = 12.0f;
|
||||
float labelControlGap = 20.0f;
|
||||
float controlColumnStart = 236.0f;
|
||||
float controlTrailingInset = 8.0f;
|
||||
float controlInsetY = 1.0f;
|
||||
float componentGap = 6.0f;
|
||||
float componentMinWidth = 72.0f;
|
||||
float componentPrefixWidth = 9.0f;
|
||||
float componentLabelGap = 4.0f;
|
||||
float labelTextInsetY = 0.0f;
|
||||
float labelFontSize = 11.0f;
|
||||
float valueTextInsetX = 5.0f;
|
||||
float valueTextInsetY = 0.0f;
|
||||
float valueFontSize = 12.0f;
|
||||
float prefixTextInsetX = 0.0f;
|
||||
float prefixTextInsetY = -1.0f;
|
||||
float prefixFontSize = 11.0f;
|
||||
float cornerRounding = 0.0f;
|
||||
float componentRounding = 2.0f;
|
||||
float borderThickness = 1.0f;
|
||||
float focusedBorderThickness = 1.0f;
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldPalette {
|
||||
::XCEngine::UI::UIColor surfaceColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor borderColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor focusedBorderColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor rowHoverColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor rowActiveColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor componentColor =
|
||||
::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
::XCEngine::UI::UIColor componentHoverColor =
|
||||
::XCEngine::UI::UIColor(0.21f, 0.21f, 0.21f, 1.0f);
|
||||
::XCEngine::UI::UIColor componentEditingColor =
|
||||
::XCEngine::UI::UIColor(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
::XCEngine::UI::UIColor readOnlyColor =
|
||||
::XCEngine::UI::UIColor(0.17f, 0.17f, 0.17f, 1.0f);
|
||||
::XCEngine::UI::UIColor componentBorderColor =
|
||||
::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
||||
::XCEngine::UI::UIColor componentFocusedBorderColor =
|
||||
::XCEngine::UI::UIColor(0.20f, 0.20f, 0.20f, 1.0f);
|
||||
::XCEngine::UI::UIColor prefixColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor prefixBorderColor =
|
||||
::XCEngine::UI::UIColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
::XCEngine::UI::UIColor labelColor =
|
||||
::XCEngine::UI::UIColor(0.80f, 0.80f, 0.80f, 1.0f);
|
||||
::XCEngine::UI::UIColor valueColor =
|
||||
::XCEngine::UI::UIColor(0.92f, 0.92f, 0.92f, 1.0f);
|
||||
::XCEngine::UI::UIColor readOnlyValueColor =
|
||||
::XCEngine::UI::UIColor(0.62f, 0.62f, 0.62f, 1.0f);
|
||||
::XCEngine::UI::UIColor axisXColor =
|
||||
::XCEngine::UI::UIColor(0.67f, 0.67f, 0.67f, 1.0f);
|
||||
::XCEngine::UI::UIColor axisYColor =
|
||||
::XCEngine::UI::UIColor(0.67f, 0.67f, 0.67f, 1.0f);
|
||||
::XCEngine::UI::UIColor axisZColor =
|
||||
::XCEngine::UI::UIColor(0.67f, 0.67f, 0.67f, 1.0f);
|
||||
::XCEngine::UI::UIColor axisWColor =
|
||||
::XCEngine::UI::UIColor(0.67f, 0.67f, 0.67f, 1.0f);
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldLayout {
|
||||
::XCEngine::UI::UIRect bounds = {};
|
||||
::XCEngine::UI::UIRect labelRect = {};
|
||||
::XCEngine::UI::UIRect controlRect = {};
|
||||
std::array<::XCEngine::UI::UIRect, 4u> componentRects = {};
|
||||
std::array<::XCEngine::UI::UIRect, 4u> componentPrefixRects = {};
|
||||
std::array<::XCEngine::UI::UIRect, 4u> componentValueRects = {};
|
||||
};
|
||||
|
||||
struct UIEditorVector4FieldHitTarget {
|
||||
UIEditorVector4FieldHitTargetKind kind = UIEditorVector4FieldHitTargetKind::None;
|
||||
std::size_t componentIndex = UIEditorVector4FieldInvalidComponentIndex;
|
||||
};
|
||||
|
||||
bool IsUIEditorVector4FieldPointInside(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
const ::XCEngine::UI::UIPoint& point);
|
||||
|
||||
double NormalizeUIEditorVector4FieldComponentValue(
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
double value);
|
||||
|
||||
bool TryParseUIEditorVector4FieldComponentValue(
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
std::string_view text,
|
||||
double& outValue);
|
||||
|
||||
std::string FormatUIEditorVector4FieldComponentValue(
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
std::size_t componentIndex);
|
||||
|
||||
UIEditorVector4FieldLayout BuildUIEditorVector4FieldLayout(
|
||||
const ::XCEngine::UI::UIRect& bounds,
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
const UIEditorVector4FieldMetrics& metrics = {});
|
||||
|
||||
UIEditorVector4FieldHitTarget HitTestUIEditorVector4Field(
|
||||
const UIEditorVector4FieldLayout& layout,
|
||||
const ::XCEngine::UI::UIPoint& point);
|
||||
|
||||
void AppendUIEditorVector4FieldBackground(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
const UIEditorVector4FieldLayout& layout,
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
const UIEditorVector4FieldState& state,
|
||||
const UIEditorVector4FieldPalette& palette = {},
|
||||
const UIEditorVector4FieldMetrics& metrics = {});
|
||||
|
||||
void AppendUIEditorVector4FieldForeground(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
const UIEditorVector4FieldLayout& layout,
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
const UIEditorVector4FieldState& state,
|
||||
const UIEditorVector4FieldPalette& palette = {},
|
||||
const UIEditorVector4FieldMetrics& metrics = {});
|
||||
|
||||
void AppendUIEditorVector4Field(
|
||||
::XCEngine::UI::UIDrawList& drawList,
|
||||
const ::XCEngine::UI::UIRect& bounds,
|
||||
const UIEditorVector4FieldSpec& spec,
|
||||
const UIEditorVector4FieldState& state,
|
||||
const UIEditorVector4FieldPalette& palette = {},
|
||||
const UIEditorVector4FieldMetrics& metrics = {});
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Widgets
|
||||
Reference in New Issue
Block a user