2026-04-08 02:52:28 +08:00
|
|
|
#include <XCEditor/Widgets/UIEditorFieldRowLayout.h>
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2026-04-10 00:41:28 +08:00
|
|
|
#include <cmath>
|
2026-04-08 02:52:28 +08:00
|
|
|
|
|
|
|
|
namespace XCEngine::UI::Editor::Widgets {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
float ClampNonNegative(float value) {
|
|
|
|
|
return (std::max)(0.0f, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 00:41:28 +08:00
|
|
|
bool AreEqual(float lhs, float rhs) {
|
|
|
|
|
return std::abs(lhs - rhs) <= 0.001f;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 02:52:28 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
2026-04-10 00:41:28 +08:00
|
|
|
const UIEditorInspectorFieldStyleTokens& GetUIEditorInspectorFieldStyleTokens() {
|
2026-04-14 14:41:45 +08:00
|
|
|
static const UIEditorInspectorFieldStyleTokens kTokens = [] {
|
|
|
|
|
UIEditorInspectorFieldStyleTokens tokens = {};
|
|
|
|
|
tokens.rowHoverColor = ::XCEngine::UI::UIColor(0.12f, 0.12f, 0.12f, 1.0f);
|
|
|
|
|
tokens.rowActiveColor = ::XCEngine::UI::UIColor(0.15f, 0.15f, 0.15f, 1.0f);
|
|
|
|
|
tokens.labelColor = ::XCEngine::UI::UIColor(0.78f, 0.78f, 0.78f, 1.0f);
|
|
|
|
|
tokens.valueColor = ::XCEngine::UI::UIColor(0.92f, 0.92f, 0.92f, 1.0f);
|
|
|
|
|
tokens.readOnlyValueColor = ::XCEngine::UI::UIColor(0.60f, 0.60f, 0.60f, 1.0f);
|
|
|
|
|
tokens.controlColor = ::XCEngine::UI::UIColor(0.12f, 0.12f, 0.12f, 1.0f);
|
|
|
|
|
tokens.controlHoverColor = ::XCEngine::UI::UIColor(0.15f, 0.15f, 0.15f, 1.0f);
|
|
|
|
|
tokens.controlEditingColor = ::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
|
|
|
tokens.controlReadOnlyColor = ::XCEngine::UI::UIColor(0.10f, 0.10f, 0.10f, 1.0f);
|
|
|
|
|
tokens.controlBorderColor = ::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
tokens.controlFocusedBorderColor = ::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
|
|
|
tokens.prefixColor = ::XCEngine::UI::UIColor(0.12f, 0.12f, 0.12f, 1.0f);
|
|
|
|
|
tokens.prefixBorderColor = ::XCEngine::UI::UIColor(0.15f, 0.15f, 0.15f, 1.0f);
|
|
|
|
|
tokens.popupColor = ::XCEngine::UI::UIColor(0.10f, 0.10f, 0.10f, 1.0f);
|
|
|
|
|
tokens.popupBorderColor = ::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
tokens.popupHeaderColor = ::XCEngine::UI::UIColor(0.11f, 0.11f, 0.11f, 1.0f);
|
|
|
|
|
tokens.popupTitleColor = ::XCEngine::UI::UIColor(0.93f, 0.93f, 0.93f, 1.0f);
|
|
|
|
|
tokens.popupTextColor = ::XCEngine::UI::UIColor(0.86f, 0.86f, 0.86f, 1.0f);
|
|
|
|
|
tokens.popupTextMutedColor = ::XCEngine::UI::UIColor(0.68f, 0.68f, 0.68f, 1.0f);
|
|
|
|
|
tokens.previewBorderColor = ::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
tokens.previewBaseColor = ::XCEngine::UI::UIColor(0.12f, 0.12f, 0.12f, 1.0f);
|
|
|
|
|
tokens.checkerLightColor = ::XCEngine::UI::UIColor(0.26f, 0.26f, 0.26f, 1.0f);
|
|
|
|
|
tokens.checkerDarkColor = ::XCEngine::UI::UIColor(0.16f, 0.16f, 0.16f, 1.0f);
|
|
|
|
|
tokens.sliderBorderColor = ::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
tokens.numericBoxColor = ::XCEngine::UI::UIColor(0.12f, 0.12f, 0.12f, 1.0f);
|
|
|
|
|
tokens.numericBoxBorderColor = ::XCEngine::UI::UIColor(0.14f, 0.14f, 0.14f, 1.0f);
|
|
|
|
|
tokens.numericBoxTextColor = ::XCEngine::UI::UIColor(0.92f, 0.92f, 0.92f, 1.0f);
|
|
|
|
|
tokens.closeButtonHoverColor = ::XCEngine::UI::UIColor(0.15f, 0.15f, 0.15f, 1.0f);
|
|
|
|
|
tokens.closeGlyphColor = ::XCEngine::UI::UIColor(0.85f, 0.85f, 0.85f, 1.0f);
|
|
|
|
|
return tokens;
|
|
|
|
|
}();
|
2026-04-10 00:41:28 +08:00
|
|
|
return kTokens;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AreUIEditorFieldMetricsEqual(float lhs, float rhs) {
|
|
|
|
|
return AreEqual(lhs, rhs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AreUIEditorFieldColorsEqual(
|
|
|
|
|
const ::XCEngine::UI::UIColor& lhs,
|
|
|
|
|
const ::XCEngine::UI::UIColor& rhs) {
|
|
|
|
|
return AreEqual(lhs.r, rhs.r) &&
|
|
|
|
|
AreEqual(lhs.g, rhs.g) &&
|
|
|
|
|
AreEqual(lhs.b, rhs.b) &&
|
|
|
|
|
AreEqual(lhs.a, rhs.a);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 02:52:28 +08:00
|
|
|
UIEditorFieldRowLayout BuildUIEditorFieldRowLayout(
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
float minimumControlWidth,
|
|
|
|
|
const UIEditorFieldRowLayoutMetrics& metrics) {
|
|
|
|
|
const float rowHeight = bounds.height > 0.0f ? bounds.height : metrics.rowHeight;
|
|
|
|
|
const ::XCEngine::UI::UIRect rowBounds(bounds.x, bounds.y, bounds.width, rowHeight);
|
|
|
|
|
|
|
|
|
|
const float resolvedMinimumControlWidth =
|
|
|
|
|
ClampNonNegative((std::min)(minimumControlWidth, rowBounds.width));
|
|
|
|
|
const float preferredControlX = rowBounds.x + metrics.controlColumnStart;
|
|
|
|
|
const float maximumControlX =
|
|
|
|
|
rowBounds.x + rowBounds.width - metrics.controlTrailingInset - resolvedMinimumControlWidth;
|
|
|
|
|
const float controlX =
|
|
|
|
|
(std::clamp)(
|
|
|
|
|
(std::min)(preferredControlX, maximumControlX),
|
|
|
|
|
rowBounds.x,
|
|
|
|
|
rowBounds.x + rowBounds.width - metrics.controlTrailingInset);
|
|
|
|
|
const float controlInsetY = (std::min)(metrics.controlInsetY, rowBounds.height * 0.25f);
|
|
|
|
|
const float controlWidth =
|
|
|
|
|
ClampNonNegative(rowBounds.x + rowBounds.width - metrics.controlTrailingInset - controlX);
|
|
|
|
|
|
|
|
|
|
UIEditorFieldRowLayout layout = {};
|
|
|
|
|
layout.bounds = rowBounds;
|
|
|
|
|
layout.labelRect = ::XCEngine::UI::UIRect(
|
|
|
|
|
rowBounds.x + metrics.horizontalPadding,
|
|
|
|
|
rowBounds.y,
|
|
|
|
|
ClampNonNegative(controlX - metrics.labelControlGap - rowBounds.x - metrics.horizontalPadding),
|
|
|
|
|
rowBounds.height);
|
|
|
|
|
layout.controlRect = ::XCEngine::UI::UIRect(
|
|
|
|
|
controlX,
|
|
|
|
|
rowBounds.y + controlInsetY,
|
|
|
|
|
controlWidth,
|
|
|
|
|
ClampNonNegative(rowBounds.height - controlInsetY * 2.0f));
|
|
|
|
|
return layout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor::Widgets
|