2026-04-10 00:41:28 +08:00
|
|
|
#include <XCEditor/Fields/UIEditorVector3FieldInteraction.h>
|
2026-04-08 02:52:28 +08:00
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
#include "Fields/VectorFieldInteractionInternal.h"
|
2026-04-08 02:52:28 +08:00
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine::UI::Editor {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::BuildUIEditorVector3FieldLayout;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::FormatUIEditorVector3FieldComponentValue;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::HitTestUIEditorVector3Field;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::IsUIEditorVector3FieldPointInside;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::NormalizeUIEditorVector3FieldComponentValue;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::TryParseUIEditorVector3FieldComponentValue;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldHitTarget;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldHitTargetKind;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldInvalidComponentIndex;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldLayout;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldMetrics;
|
|
|
|
|
using ::XCEngine::UI::Editor::Widgets::UIEditorVector3FieldSpec;
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
struct Vector3FieldInteractionTraits {
|
|
|
|
|
using InteractionState = UIEditorVector3FieldInteractionState;
|
|
|
|
|
using InteractionResult = UIEditorVector3FieldInteractionResult;
|
|
|
|
|
using Spec = UIEditorVector3FieldSpec;
|
|
|
|
|
using Layout = UIEditorVector3FieldLayout;
|
|
|
|
|
using Metrics = UIEditorVector3FieldMetrics;
|
|
|
|
|
using HitTarget = UIEditorVector3FieldHitTarget;
|
|
|
|
|
using HitTargetKind = UIEditorVector3FieldHitTargetKind;
|
2026-04-08 02:52:28 +08:00
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static constexpr std::size_t kComponentCount = 3u;
|
|
|
|
|
static constexpr std::size_t kLastComponentIndex = 2u;
|
|
|
|
|
static constexpr std::size_t kInvalidComponentIndex = UIEditorVector3FieldInvalidComponentIndex;
|
|
|
|
|
static constexpr HitTargetKind kNoneHitTargetKind = UIEditorVector3FieldHitTargetKind::None;
|
|
|
|
|
static constexpr HitTargetKind kRowHitTargetKind = UIEditorVector3FieldHitTargetKind::Row;
|
|
|
|
|
static constexpr HitTargetKind kComponentHitTargetKind = UIEditorVector3FieldHitTargetKind::Component;
|
2026-04-08 02:52:28 +08:00
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static auto& FieldState(InteractionState& state) { return state.vector3FieldState; }
|
|
|
|
|
static const auto& FieldState(const InteractionState& state) { return state.vector3FieldState; }
|
2026-04-08 02:52:28 +08:00
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static Layout BuildLayout(const ::XCEngine::UI::UIRect& bounds, const Spec& spec, const Metrics& metrics) {
|
|
|
|
|
return BuildUIEditorVector3FieldLayout(bounds, spec, metrics);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static HitTarget HitTest(const Layout& layout, const ::XCEngine::UI::UIPoint& point) {
|
|
|
|
|
return HitTestUIEditorVector3Field(layout, point);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static bool IsPointInside(const ::XCEngine::UI::UIRect& rect, const ::XCEngine::UI::UIPoint& point) {
|
|
|
|
|
return IsUIEditorVector3FieldPointInside(rect, point);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static std::string FormatComponentValue(const Spec& spec, std::size_t componentIndex) {
|
|
|
|
|
return FormatUIEditorVector3FieldComponentValue(spec, componentIndex);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static bool TryParseComponentValue(const Spec& spec, std::string_view text, double& outValue) {
|
|
|
|
|
return TryParseUIEditorVector3FieldComponentValue(spec, text, outValue);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
static double NormalizeComponentValue(const Spec& spec, double value) {
|
|
|
|
|
return NormalizeUIEditorVector3FieldComponentValue(spec, value);
|
2026-04-08 02:52:28 +08:00
|
|
|
}
|
2026-04-15 19:30:58 +08:00
|
|
|
};
|
2026-04-08 02:52:28 +08:00
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
UIEditorVector3FieldInteractionFrame UpdateUIEditorVector3FieldInteraction(
|
|
|
|
|
UIEditorVector3FieldInteractionState& state,
|
|
|
|
|
UIEditorVector3FieldSpec& spec,
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const std::vector<UIInputEvent>& inputEvents,
|
|
|
|
|
const UIEditorVector3FieldMetrics& metrics) {
|
2026-04-15 19:30:58 +08:00
|
|
|
UIEditorVector3FieldLayout layout = {};
|
|
|
|
|
UIEditorVector3FieldInteractionResult result =
|
|
|
|
|
Internal::UpdateVectorFieldInteractionImpl<Vector3FieldInteractionTraits>(
|
|
|
|
|
state,
|
|
|
|
|
spec,
|
|
|
|
|
bounds,
|
|
|
|
|
inputEvents,
|
|
|
|
|
metrics,
|
|
|
|
|
layout);
|
2026-04-08 02:52:28 +08:00
|
|
|
return {
|
|
|
|
|
std::move(layout),
|
2026-04-15 19:30:58 +08:00
|
|
|
std::move(result)
|
2026-04-08 02:52:28 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor
|