Build XCEditor menu and status shell widgets
This commit is contained in:
@@ -25,7 +25,10 @@ add_library(XCUIEditorLib STATIC
|
|||||||
src/Core/UIEditorWorkspaceSession.cpp
|
src/Core/UIEditorWorkspaceSession.cpp
|
||||||
src/Widgets/UIEditorCollectionPrimitives.cpp
|
src/Widgets/UIEditorCollectionPrimitives.cpp
|
||||||
src/Widgets/UIEditorDockHost.cpp
|
src/Widgets/UIEditorDockHost.cpp
|
||||||
|
src/Widgets/UIEditorMenuBar.cpp
|
||||||
|
src/Widgets/UIEditorMenuPopup.cpp
|
||||||
src/Widgets/UIEditorPanelFrame.cpp
|
src/Widgets/UIEditorPanelFrame.cpp
|
||||||
|
src/Widgets/UIEditorStatusBar.cpp
|
||||||
src/Widgets/UIEditorTabStrip.cpp
|
src/Widgets/UIEditorTabStrip.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,34 @@
|
|||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
namespace XCEngine::UI::Editor::Host {
|
namespace XCEngine::UI::Editor::Host {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool IsAutoCaptureOnStartupEnabled() {
|
||||||
|
const char* value = std::getenv("XCUI_AUTO_CAPTURE_ON_STARTUP");
|
||||||
|
if (value == nullptr || value[0] == '\0') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string normalized = value;
|
||||||
|
for (char& character : normalized) {
|
||||||
|
character = static_cast<char>(std::tolower(static_cast<unsigned char>(character)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalized != "0" &&
|
||||||
|
normalized != "false" &&
|
||||||
|
normalized != "off" &&
|
||||||
|
normalized != "no";
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void AutoScreenshotController::Initialize(const std::filesystem::path& captureRoot) {
|
void AutoScreenshotController::Initialize(const std::filesystem::path& captureRoot) {
|
||||||
m_captureRoot = captureRoot.lexically_normal();
|
m_captureRoot = captureRoot.lexically_normal();
|
||||||
m_historyRoot = (m_captureRoot / "history").lexically_normal();
|
m_historyRoot = (m_captureRoot / "history").lexically_normal();
|
||||||
@@ -19,6 +41,9 @@ void AutoScreenshotController::Initialize(const std::filesystem::path& captureRo
|
|||||||
m_pendingReason.clear();
|
m_pendingReason.clear();
|
||||||
m_lastCaptureSummary.clear();
|
m_lastCaptureSummary.clear();
|
||||||
m_lastCaptureError.clear();
|
m_lastCaptureError.clear();
|
||||||
|
if (IsAutoCaptureOnStartupEnabled()) {
|
||||||
|
RequestCapture("startup");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoScreenshotController::Shutdown() {
|
void AutoScreenshotController::Shutdown() {
|
||||||
@@ -37,7 +62,11 @@ void AutoScreenshotController::CaptureIfRequested(
|
|||||||
unsigned int width,
|
unsigned int width,
|
||||||
unsigned int height,
|
unsigned int height,
|
||||||
bool framePresented) {
|
bool framePresented) {
|
||||||
if (!m_capturePending || !framePresented || drawData.Empty() || width == 0u || height == 0u) {
|
if (!m_capturePending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!framePresented || drawData.Empty() || width == 0u || height == 0u) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,23 +24,29 @@ bool NativeRenderer::Initialize(HWND hwnd) {
|
|||||||
Shutdown();
|
Shutdown();
|
||||||
|
|
||||||
if (hwnd == nullptr) {
|
if (hwnd == nullptr) {
|
||||||
|
m_lastRenderError = "Initialize rejected a null hwnd.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hwnd = hwnd;
|
m_hwnd = hwnd;
|
||||||
if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, m_d2dFactory.ReleaseAndGetAddressOf()))) {
|
HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, m_d2dFactory.ReleaseAndGetAddressOf());
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
m_lastRenderError = HrToString("D2D1CreateFactory", hr);
|
||||||
Shutdown();
|
Shutdown();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(DWriteCreateFactory(
|
hr = DWriteCreateFactory(
|
||||||
DWRITE_FACTORY_TYPE_SHARED,
|
DWRITE_FACTORY_TYPE_SHARED,
|
||||||
__uuidof(IDWriteFactory),
|
__uuidof(IDWriteFactory),
|
||||||
reinterpret_cast<IUnknown**>(m_dwriteFactory.ReleaseAndGetAddressOf())))) {
|
reinterpret_cast<IUnknown**>(m_dwriteFactory.ReleaseAndGetAddressOf()));
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
m_lastRenderError = HrToString("DWriteCreateFactory", hr);
|
||||||
Shutdown();
|
Shutdown();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_lastRenderError.clear();
|
||||||
return EnsureRenderTarget();
|
return EnsureRenderTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,17 +77,31 @@ void NativeRenderer::Resize(UINT width, UINT height) {
|
|||||||
|
|
||||||
bool NativeRenderer::Render(const ::XCEngine::UI::UIDrawData& drawData) {
|
bool NativeRenderer::Render(const ::XCEngine::UI::UIDrawData& drawData) {
|
||||||
if (!EnsureRenderTarget()) {
|
if (!EnsureRenderTarget()) {
|
||||||
|
if (m_lastRenderError.empty()) {
|
||||||
|
m_lastRenderError = "EnsureRenderTarget failed.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool rendered = RenderToTarget(*m_renderTarget.Get(), *m_solidBrush.Get(), drawData);
|
const bool rendered = RenderToTarget(*m_renderTarget.Get(), *m_solidBrush.Get(), drawData);
|
||||||
const HRESULT hr = m_renderTarget->EndDraw();
|
const HRESULT hr = m_renderTarget->EndDraw();
|
||||||
if (hr == D2DERR_RECREATE_TARGET) {
|
if (hr == D2DERR_RECREATE_TARGET) {
|
||||||
|
m_lastRenderError = HrToString("ID2D1HwndRenderTarget::EndDraw", hr);
|
||||||
DiscardRenderTarget();
|
DiscardRenderTarget();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rendered && SUCCEEDED(hr);
|
if (!rendered || FAILED(hr)) {
|
||||||
|
m_lastRenderError = HrToString("ID2D1HwndRenderTarget::EndDraw", hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastRenderError.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& NativeRenderer::GetLastRenderError() const {
|
||||||
|
return m_lastRenderError;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeRenderer::CaptureToPng(
|
bool NativeRenderer::CaptureToPng(
|
||||||
@@ -231,6 +251,7 @@ bool NativeRenderer::CaptureToPng(
|
|||||||
|
|
||||||
bool NativeRenderer::EnsureRenderTarget() {
|
bool NativeRenderer::EnsureRenderTarget() {
|
||||||
if (!m_hwnd || !m_d2dFactory || !m_dwriteFactory) {
|
if (!m_hwnd || !m_d2dFactory || !m_dwriteFactory) {
|
||||||
|
m_lastRenderError = "EnsureRenderTarget requires hwnd, D2D factory, and DWrite factory.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,21 +306,26 @@ bool NativeRenderer::CreateDeviceResources() {
|
|||||||
m_hwnd,
|
m_hwnd,
|
||||||
D2D1::SizeU(width, height));
|
D2D1::SizeU(width, height));
|
||||||
|
|
||||||
if (FAILED(m_d2dFactory->CreateHwndRenderTarget(
|
const HRESULT renderTargetHr = m_d2dFactory->CreateHwndRenderTarget(
|
||||||
renderTargetProps,
|
renderTargetProps,
|
||||||
hwndProps,
|
hwndProps,
|
||||||
m_renderTarget.ReleaseAndGetAddressOf()))) {
|
m_renderTarget.ReleaseAndGetAddressOf());
|
||||||
|
if (FAILED(renderTargetHr)) {
|
||||||
|
m_lastRenderError = HrToString("ID2D1Factory::CreateHwndRenderTarget", renderTargetHr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(m_renderTarget->CreateSolidColorBrush(
|
const HRESULT brushHr = m_renderTarget->CreateSolidColorBrush(
|
||||||
D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f),
|
D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f),
|
||||||
m_solidBrush.ReleaseAndGetAddressOf()))) {
|
m_solidBrush.ReleaseAndGetAddressOf());
|
||||||
|
if (FAILED(brushHr)) {
|
||||||
|
m_lastRenderError = HrToString("ID2D1HwndRenderTarget::CreateSolidColorBrush", brushHr);
|
||||||
DiscardRenderTarget();
|
DiscardRenderTarget();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_renderTarget->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
m_renderTarget->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
|
||||||
|
m_lastRenderError.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public:
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Resize(UINT width, UINT height);
|
void Resize(UINT width, UINT height);
|
||||||
bool Render(const ::XCEngine::UI::UIDrawData& drawData);
|
bool Render(const ::XCEngine::UI::UIDrawData& drawData);
|
||||||
|
const std::string& GetLastRenderError() const;
|
||||||
bool CaptureToPng(
|
bool CaptureToPng(
|
||||||
const ::XCEngine::UI::UIDrawData& drawData,
|
const ::XCEngine::UI::UIDrawData& drawData,
|
||||||
UINT width,
|
UINT width,
|
||||||
@@ -59,6 +60,7 @@ private:
|
|||||||
Microsoft::WRL::ComPtr<ID2D1HwndRenderTarget> m_renderTarget;
|
Microsoft::WRL::ComPtr<ID2D1HwndRenderTarget> m_renderTarget;
|
||||||
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_solidBrush;
|
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_solidBrush;
|
||||||
std::unordered_map<int, Microsoft::WRL::ComPtr<IDWriteTextFormat>> m_textFormats;
|
std::unordered_map<int, Microsoft::WRL::ComPtr<IDWriteTextFormat>> m_textFormats;
|
||||||
|
std::string m_lastRenderError = {};
|
||||||
bool m_wicComInitialized = false;
|
bool m_wicComInitialized = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ public:
|
|||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
|
UIEditorMenuSessionMutationResult OpenRootMenu(
|
||||||
|
std::string_view menuId,
|
||||||
|
Widgets::UIPopupOverlayEntry entry);
|
||||||
|
|
||||||
UIEditorMenuSessionMutationResult OpenMenuBarRoot(
|
UIEditorMenuSessionMutationResult OpenMenuBarRoot(
|
||||||
std::string_view menuId,
|
std::string_view menuId,
|
||||||
Widgets::UIPopupOverlayEntry entry);
|
Widgets::UIPopupOverlayEntry entry);
|
||||||
|
|||||||
120
new_editor/include/XCEditor/Widgets/UIEditorMenuBar.h
Normal file
120
new_editor/include/XCEditor/Widgets/UIEditorMenuBar.h
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
inline constexpr std::size_t UIEditorMenuBarInvalidIndex =
|
||||||
|
static_cast<std::size_t>(-1);
|
||||||
|
|
||||||
|
struct UIEditorMenuBarItem {
|
||||||
|
std::string menuId = {};
|
||||||
|
std::string label = {};
|
||||||
|
bool enabled = true;
|
||||||
|
float desiredLabelWidth = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuBarState {
|
||||||
|
std::size_t openIndex = UIEditorMenuBarInvalidIndex;
|
||||||
|
std::size_t hoveredIndex = UIEditorMenuBarInvalidIndex;
|
||||||
|
bool focused = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuBarMetrics {
|
||||||
|
float barHeight = 34.0f;
|
||||||
|
float horizontalInset = 10.0f;
|
||||||
|
float verticalInset = 4.0f;
|
||||||
|
float buttonGap = 6.0f;
|
||||||
|
float buttonPaddingX = 14.0f;
|
||||||
|
float estimatedGlyphWidth = 7.0f;
|
||||||
|
float labelInsetY = -1.0f;
|
||||||
|
float barCornerRounding = 8.0f;
|
||||||
|
float buttonCornerRounding = 7.0f;
|
||||||
|
float baseBorderThickness = 1.0f;
|
||||||
|
float focusedBorderThickness = 2.0f;
|
||||||
|
float openBorderThickness = 1.5f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuBarPalette {
|
||||||
|
::XCEngine::UI::UIColor barColor =
|
||||||
|
::XCEngine::UI::UIColor(0.16f, 0.16f, 0.16f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor buttonColor =
|
||||||
|
::XCEngine::UI::UIColor(0.23f, 0.23f, 0.23f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor buttonHoveredColor =
|
||||||
|
::XCEngine::UI::UIColor(0.29f, 0.29f, 0.29f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor buttonOpenColor =
|
||||||
|
::XCEngine::UI::UIColor(0.35f, 0.35f, 0.35f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor borderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.30f, 0.30f, 0.30f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor focusedBorderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.84f, 0.84f, 0.84f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor openBorderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.68f, 0.68f, 0.68f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textPrimary =
|
||||||
|
::XCEngine::UI::UIColor(0.94f, 0.94f, 0.94f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textMuted =
|
||||||
|
::XCEngine::UI::UIColor(0.74f, 0.74f, 0.74f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textDisabled =
|
||||||
|
::XCEngine::UI::UIColor(0.52f, 0.52f, 0.52f, 1.0f);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuBarLayout {
|
||||||
|
::XCEngine::UI::UIRect bounds = {};
|
||||||
|
::XCEngine::UI::UIRect contentRect = {};
|
||||||
|
std::vector<::XCEngine::UI::UIRect> buttonRects = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class UIEditorMenuBarHitTargetKind : std::uint8_t {
|
||||||
|
None = 0,
|
||||||
|
BarBackground,
|
||||||
|
Button
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuBarHitTarget {
|
||||||
|
UIEditorMenuBarHitTargetKind kind = UIEditorMenuBarHitTargetKind::None;
|
||||||
|
std::size_t index = UIEditorMenuBarInvalidIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
float ResolveUIEditorMenuBarDesiredButtonWidth(
|
||||||
|
const UIEditorMenuBarItem& item,
|
||||||
|
const UIEditorMenuBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorMenuBarLayout BuildUIEditorMenuBarLayout(
|
||||||
|
const ::XCEngine::UI::UIRect& bounds,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorMenuBarHitTarget HitTestUIEditorMenuBar(
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const ::XCEngine::UI::UIPoint& point);
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBarBackground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState& state,
|
||||||
|
const UIEditorMenuBarPalette& palette = {},
|
||||||
|
const UIEditorMenuBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBarForeground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState& state,
|
||||||
|
const UIEditorMenuBarPalette& palette = {},
|
||||||
|
const UIEditorMenuBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBar(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const ::XCEngine::UI::UIRect& bounds,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState& state,
|
||||||
|
const UIEditorMenuBarPalette& palette = {},
|
||||||
|
const UIEditorMenuBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
134
new_editor/include/XCEditor/Widgets/UIEditorMenuPopup.h
Normal file
134
new_editor/include/XCEditor/Widgets/UIEditorMenuPopup.h
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <XCEditor/Core/UIEditorMenuModel.h>
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
inline constexpr std::size_t UIEditorMenuPopupInvalidIndex =
|
||||||
|
static_cast<std::size_t>(-1);
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupItem {
|
||||||
|
std::string itemId = {};
|
||||||
|
::XCEngine::UI::Editor::UIEditorMenuItemKind kind =
|
||||||
|
::XCEngine::UI::Editor::UIEditorMenuItemKind::Command;
|
||||||
|
std::string label = {};
|
||||||
|
std::string shortcutText = {};
|
||||||
|
bool enabled = true;
|
||||||
|
bool checked = false;
|
||||||
|
bool hasSubmenu = false;
|
||||||
|
float desiredLabelWidth = 0.0f;
|
||||||
|
float desiredShortcutWidth = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupState {
|
||||||
|
std::size_t hoveredIndex = UIEditorMenuPopupInvalidIndex;
|
||||||
|
std::size_t submenuOpenIndex = UIEditorMenuPopupInvalidIndex;
|
||||||
|
bool focused = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupMetrics {
|
||||||
|
float contentPaddingX = 6.0f;
|
||||||
|
float contentPaddingY = 6.0f;
|
||||||
|
float itemHeight = 28.0f;
|
||||||
|
float separatorHeight = 9.0f;
|
||||||
|
float checkColumnWidth = 18.0f;
|
||||||
|
float shortcutGap = 20.0f;
|
||||||
|
float submenuIndicatorWidth = 14.0f;
|
||||||
|
float rowCornerRounding = 5.0f;
|
||||||
|
float popupCornerRounding = 8.0f;
|
||||||
|
float labelInsetX = 14.0f;
|
||||||
|
float labelInsetY = -1.0f;
|
||||||
|
float shortcutInsetRight = 24.0f;
|
||||||
|
float estimatedGlyphWidth = 7.0f;
|
||||||
|
float separatorThickness = 1.0f;
|
||||||
|
float borderThickness = 1.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupPalette {
|
||||||
|
::XCEngine::UI::UIColor popupColor =
|
||||||
|
::XCEngine::UI::UIColor(0.17f, 0.17f, 0.17f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor borderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.31f, 0.31f, 0.31f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor itemHoverColor =
|
||||||
|
::XCEngine::UI::UIColor(0.28f, 0.28f, 0.28f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor itemOpenColor =
|
||||||
|
::XCEngine::UI::UIColor(0.34f, 0.34f, 0.34f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor separatorColor =
|
||||||
|
::XCEngine::UI::UIColor(0.32f, 0.32f, 0.32f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textPrimary =
|
||||||
|
::XCEngine::UI::UIColor(0.94f, 0.94f, 0.94f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textMuted =
|
||||||
|
::XCEngine::UI::UIColor(0.76f, 0.76f, 0.76f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textDisabled =
|
||||||
|
::XCEngine::UI::UIColor(0.50f, 0.50f, 0.50f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor glyphColor =
|
||||||
|
::XCEngine::UI::UIColor(0.90f, 0.90f, 0.90f, 1.0f);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupLayout {
|
||||||
|
::XCEngine::UI::UIRect popupRect = {};
|
||||||
|
::XCEngine::UI::UIRect contentRect = {};
|
||||||
|
std::vector<::XCEngine::UI::UIRect> itemRects = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class UIEditorMenuPopupHitTargetKind : std::uint8_t {
|
||||||
|
None = 0,
|
||||||
|
PopupSurface,
|
||||||
|
Item
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorMenuPopupHitTarget {
|
||||||
|
UIEditorMenuPopupHitTargetKind kind = UIEditorMenuPopupHitTargetKind::None;
|
||||||
|
std::size_t index = UIEditorMenuPopupInvalidIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
float ResolveUIEditorMenuPopupDesiredWidth(
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
float MeasureUIEditorMenuPopupHeight(
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorMenuPopupLayout BuildUIEditorMenuPopupLayout(
|
||||||
|
const ::XCEngine::UI::UIRect& popupRect,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorMenuPopupHitTarget HitTestUIEditorMenuPopup(
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const ::XCEngine::UI::UIPoint& point);
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopupBackground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState& state,
|
||||||
|
const UIEditorMenuPopupPalette& palette = {},
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopupForeground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState& state,
|
||||||
|
const UIEditorMenuPopupPalette& palette = {},
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopup(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const ::XCEngine::UI::UIRect& popupRect,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState& state,
|
||||||
|
const UIEditorMenuPopupPalette& palette = {},
|
||||||
|
const UIEditorMenuPopupMetrics& metrics = {});
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
144
new_editor/include/XCEditor/Widgets/UIEditorStatusBar.h
Normal file
144
new_editor/include/XCEditor/Widgets/UIEditorStatusBar.h
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
inline constexpr std::size_t UIEditorStatusBarInvalidIndex =
|
||||||
|
static_cast<std::size_t>(-1);
|
||||||
|
|
||||||
|
enum class UIEditorStatusBarSlot : std::uint8_t {
|
||||||
|
Leading = 0,
|
||||||
|
Trailing
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class UIEditorStatusBarTextTone : std::uint8_t {
|
||||||
|
Primary = 0,
|
||||||
|
Muted,
|
||||||
|
Accent
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class UIEditorStatusBarHitTargetKind : std::uint8_t {
|
||||||
|
None = 0,
|
||||||
|
Background,
|
||||||
|
Segment,
|
||||||
|
Separator
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarSegment {
|
||||||
|
std::string segmentId = {};
|
||||||
|
std::string label = {};
|
||||||
|
UIEditorStatusBarSlot slot = UIEditorStatusBarSlot::Leading;
|
||||||
|
UIEditorStatusBarTextTone tone = UIEditorStatusBarTextTone::Primary;
|
||||||
|
bool interactive = true;
|
||||||
|
bool showSeparator = false;
|
||||||
|
float desiredWidth = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarState {
|
||||||
|
std::size_t hoveredIndex = UIEditorStatusBarInvalidIndex;
|
||||||
|
std::size_t activeIndex = UIEditorStatusBarInvalidIndex;
|
||||||
|
bool focused = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarMetrics {
|
||||||
|
float barHeight = 28.0f;
|
||||||
|
float outerPaddingX = 10.0f;
|
||||||
|
float segmentPaddingX = 10.0f;
|
||||||
|
float segmentPaddingY = 6.0f;
|
||||||
|
float segmentGap = 4.0f;
|
||||||
|
float separatorWidth = 1.0f;
|
||||||
|
float separatorInsetY = 6.0f;
|
||||||
|
float slotGapMin = 18.0f;
|
||||||
|
float cornerRounding = 8.0f;
|
||||||
|
float estimatedGlyphWidth = 7.0f;
|
||||||
|
float borderThickness = 1.0f;
|
||||||
|
float focusedBorderThickness = 1.5f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarPalette {
|
||||||
|
::XCEngine::UI::UIColor surfaceColor =
|
||||||
|
::XCEngine::UI::UIColor(0.15f, 0.15f, 0.15f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor borderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.28f, 0.28f, 0.28f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor focusedBorderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.78f, 0.78f, 0.78f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor segmentColor =
|
||||||
|
::XCEngine::UI::UIColor(0.17f, 0.17f, 0.17f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor segmentHoveredColor =
|
||||||
|
::XCEngine::UI::UIColor(0.23f, 0.23f, 0.23f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor segmentActiveColor =
|
||||||
|
::XCEngine::UI::UIColor(0.29f, 0.29f, 0.29f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor segmentBorderColor =
|
||||||
|
::XCEngine::UI::UIColor(0.35f, 0.35f, 0.35f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor separatorColor =
|
||||||
|
::XCEngine::UI::UIColor(0.32f, 0.32f, 0.32f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textPrimary =
|
||||||
|
::XCEngine::UI::UIColor(0.92f, 0.92f, 0.92f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textMuted =
|
||||||
|
::XCEngine::UI::UIColor(0.66f, 0.66f, 0.66f, 1.0f);
|
||||||
|
::XCEngine::UI::UIColor textAccent =
|
||||||
|
::XCEngine::UI::UIColor(0.94f, 0.94f, 0.94f, 1.0f);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarLayout {
|
||||||
|
::XCEngine::UI::UIRect bounds = {};
|
||||||
|
::XCEngine::UI::UIRect leadingSlotRect = {};
|
||||||
|
::XCEngine::UI::UIRect trailingSlotRect = {};
|
||||||
|
std::vector<::XCEngine::UI::UIRect> segmentRects = {};
|
||||||
|
std::vector<::XCEngine::UI::UIRect> separatorRects = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UIEditorStatusBarHitTarget {
|
||||||
|
UIEditorStatusBarHitTargetKind kind = UIEditorStatusBarHitTargetKind::None;
|
||||||
|
std::size_t index = UIEditorStatusBarInvalidIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
float ResolveUIEditorStatusBarDesiredSegmentWidth(
|
||||||
|
const UIEditorStatusBarSegment& segment,
|
||||||
|
const UIEditorStatusBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorStatusBarLayout BuildUIEditorStatusBarLayout(
|
||||||
|
const ::XCEngine::UI::UIRect& bounds,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
UIEditorStatusBarHitTarget HitTestUIEditorStatusBar(
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const ::XCEngine::UI::UIPoint& point);
|
||||||
|
|
||||||
|
::XCEngine::UI::UIColor ResolveUIEditorStatusBarTextColor(
|
||||||
|
UIEditorStatusBarTextTone tone,
|
||||||
|
const UIEditorStatusBarPalette& palette = {});
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBarBackground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState& state,
|
||||||
|
const UIEditorStatusBarPalette& palette = {},
|
||||||
|
const UIEditorStatusBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBarForeground(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState& state,
|
||||||
|
const UIEditorStatusBarPalette& palette = {},
|
||||||
|
const UIEditorStatusBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBar(
|
||||||
|
::XCEngine::UI::UIDrawList& drawList,
|
||||||
|
const ::XCEngine::UI::UIRect& bounds,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState& state,
|
||||||
|
const UIEditorStatusBarPalette& palette = {},
|
||||||
|
const UIEditorStatusBarMetrics& metrics = {});
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
@@ -5,6 +5,27 @@
|
|||||||
|
|
||||||
namespace XCEngine::UI::Editor {
|
namespace XCEngine::UI::Editor {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
bool AreEquivalentPopupEntries(
|
||||||
|
const Widgets::UIPopupOverlayEntry& lhs,
|
||||||
|
const Widgets::UIPopupOverlayEntry& rhs) {
|
||||||
|
return lhs.popupId == rhs.popupId &&
|
||||||
|
lhs.parentPopupId == rhs.parentPopupId &&
|
||||||
|
lhs.anchorRect.x == rhs.anchorRect.x &&
|
||||||
|
lhs.anchorRect.y == rhs.anchorRect.y &&
|
||||||
|
lhs.anchorRect.width == rhs.anchorRect.width &&
|
||||||
|
lhs.anchorRect.height == rhs.anchorRect.height &&
|
||||||
|
lhs.anchorPath == rhs.anchorPath &&
|
||||||
|
lhs.surfacePath == rhs.surfacePath &&
|
||||||
|
lhs.placement == rhs.placement &&
|
||||||
|
lhs.dismissOnPointerOutside == rhs.dismissOnPointerOutside &&
|
||||||
|
lhs.dismissOnEscape == rhs.dismissOnEscape &&
|
||||||
|
lhs.dismissOnFocusLoss == rhs.dismissOnFocusLoss;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
bool UIEditorMenuSession::IsPopupOpen(std::string_view popupId) const {
|
bool UIEditorMenuSession::IsPopupOpen(std::string_view popupId) const {
|
||||||
return m_popupOverlayModel.FindPopup(popupId) != nullptr;
|
return m_popupOverlayModel.FindPopup(popupId) != nullptr;
|
||||||
}
|
}
|
||||||
@@ -28,6 +49,12 @@ void UIEditorMenuSession::Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UIEditorMenuSessionMutationResult UIEditorMenuSession::OpenMenuBarRoot(
|
UIEditorMenuSessionMutationResult UIEditorMenuSession::OpenMenuBarRoot(
|
||||||
|
std::string_view menuId,
|
||||||
|
Widgets::UIPopupOverlayEntry entry) {
|
||||||
|
return OpenRootMenu(menuId, std::move(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorMenuSessionMutationResult UIEditorMenuSession::OpenRootMenu(
|
||||||
std::string_view menuId,
|
std::string_view menuId,
|
||||||
Widgets::UIPopupOverlayEntry entry) {
|
Widgets::UIPopupOverlayEntry entry) {
|
||||||
if (menuId.empty() || entry.popupId.empty()) {
|
if (menuId.empty() || entry.popupId.empty()) {
|
||||||
@@ -37,7 +64,7 @@ UIEditorMenuSessionMutationResult UIEditorMenuSession::OpenMenuBarRoot(
|
|||||||
const Widgets::UIPopupOverlayEntry* rootPopup = m_popupOverlayModel.GetRootPopup();
|
const Widgets::UIPopupOverlayEntry* rootPopup = m_popupOverlayModel.GetRootPopup();
|
||||||
if (rootPopup != nullptr &&
|
if (rootPopup != nullptr &&
|
||||||
m_openRootMenuId == menuId &&
|
m_openRootMenuId == menuId &&
|
||||||
rootPopup->popupId == entry.popupId) {
|
AreEquivalentPopupEntries(*rootPopup, entry)) {
|
||||||
return BuildResult({});
|
return BuildResult({});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +91,7 @@ UIEditorMenuSessionMutationResult UIEditorMenuSession::HoverMenuBarRoot(
|
|||||||
return BuildResult({});
|
return BuildResult({});
|
||||||
}
|
}
|
||||||
|
|
||||||
return OpenMenuBarRoot(menuId, std::move(entry));
|
return OpenRootMenu(menuId, std::move(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
UIEditorMenuSessionMutationResult UIEditorMenuSession::HoverSubmenu(
|
UIEditorMenuSessionMutationResult UIEditorMenuSession::HoverSubmenu(
|
||||||
|
|||||||
215
new_editor/src/Widgets/UIEditorMenuBar.cpp
Normal file
215
new_editor/src/Widgets/UIEditorMenuBar.cpp
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
#include <XCEditor/Widgets/UIEditorMenuBar.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ::XCEngine::UI::UIColor;
|
||||||
|
using ::XCEngine::UI::UIDrawList;
|
||||||
|
using ::XCEngine::UI::UIPoint;
|
||||||
|
using ::XCEngine::UI::UIRect;
|
||||||
|
|
||||||
|
constexpr float kMenuBarFontSize = 13.0f;
|
||||||
|
|
||||||
|
float ClampNonNegative(float value) {
|
||||||
|
return (std::max)(value, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsPointInsideRect(const UIRect& rect, const UIPoint& point) {
|
||||||
|
return point.x >= rect.x &&
|
||||||
|
point.x <= rect.x + rect.width &&
|
||||||
|
point.y >= rect.y &&
|
||||||
|
point.y <= rect.y + rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveEstimatedLabelWidth(
|
||||||
|
const UIEditorMenuBarItem& item,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
if (item.desiredLabelWidth > 0.0f) {
|
||||||
|
return item.desiredLabelWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<float>(item.label.size()) * ClampNonNegative(metrics.estimatedGlyphWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveLabelTop(const UIRect& rect, const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
return rect.y + (std::max)(0.0f, (rect.height - kMenuBarFontSize) * 0.5f) + metrics.labelInsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIColor ResolveButtonFillColor(
|
||||||
|
bool open,
|
||||||
|
bool hovered,
|
||||||
|
const UIEditorMenuBarPalette& palette) {
|
||||||
|
if (open) {
|
||||||
|
return palette.buttonOpenColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hovered) {
|
||||||
|
return palette.buttonHoveredColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return palette.buttonColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIColor ResolveButtonBorderColor(
|
||||||
|
bool open,
|
||||||
|
bool focused,
|
||||||
|
const UIEditorMenuBarPalette& palette) {
|
||||||
|
if (focused) {
|
||||||
|
return palette.focusedBorderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
return palette.openBorderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return palette.borderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveButtonBorderThickness(
|
||||||
|
bool open,
|
||||||
|
bool focused,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
if (focused) {
|
||||||
|
return metrics.focusedBorderThickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
return metrics.openBorderThickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
return metrics.baseBorderThickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
float ResolveUIEditorMenuBarDesiredButtonWidth(
|
||||||
|
const UIEditorMenuBarItem& item,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
return ResolveEstimatedLabelWidth(item, metrics) + ClampNonNegative(metrics.buttonPaddingX) * 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorMenuBarLayout BuildUIEditorMenuBarLayout(
|
||||||
|
const UIRect& bounds,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
UIEditorMenuBarLayout layout = {};
|
||||||
|
layout.bounds = UIRect(
|
||||||
|
bounds.x,
|
||||||
|
bounds.y,
|
||||||
|
ClampNonNegative(bounds.width),
|
||||||
|
ClampNonNegative(bounds.height));
|
||||||
|
layout.contentRect = UIRect(
|
||||||
|
layout.bounds.x + ClampNonNegative(metrics.horizontalInset),
|
||||||
|
layout.bounds.y + ClampNonNegative(metrics.verticalInset),
|
||||||
|
(std::max)(
|
||||||
|
layout.bounds.width - ClampNonNegative(metrics.horizontalInset) * 2.0f,
|
||||||
|
0.0f),
|
||||||
|
(std::max)(
|
||||||
|
layout.bounds.height - ClampNonNegative(metrics.verticalInset) * 2.0f,
|
||||||
|
0.0f));
|
||||||
|
|
||||||
|
layout.buttonRects.reserve(items.size());
|
||||||
|
float cursorX = layout.contentRect.x;
|
||||||
|
for (const UIEditorMenuBarItem& item : items) {
|
||||||
|
const float width = ResolveUIEditorMenuBarDesiredButtonWidth(item, metrics);
|
||||||
|
layout.buttonRects.emplace_back(
|
||||||
|
cursorX,
|
||||||
|
layout.contentRect.y,
|
||||||
|
width,
|
||||||
|
layout.contentRect.height);
|
||||||
|
cursorX += width + ClampNonNegative(metrics.buttonGap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorMenuBarHitTarget HitTestUIEditorMenuBar(
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const UIPoint& point) {
|
||||||
|
UIEditorMenuBarHitTarget target = {};
|
||||||
|
if (!IsPointInsideRect(layout.bounds, point)) {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t index = 0; index < layout.buttonRects.size(); ++index) {
|
||||||
|
if (IsPointInsideRect(layout.buttonRects[index], point)) {
|
||||||
|
target.kind = UIEditorMenuBarHitTargetKind::Button;
|
||||||
|
target.index = index;
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.kind = UIEditorMenuBarHitTargetKind::BarBackground;
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBarBackground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState& state,
|
||||||
|
const UIEditorMenuBarPalette& palette,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
drawList.AddFilledRect(layout.bounds, palette.barColor, metrics.barCornerRounding);
|
||||||
|
drawList.AddRectOutline(
|
||||||
|
layout.bounds,
|
||||||
|
state.focused ? palette.focusedBorderColor : palette.borderColor,
|
||||||
|
state.focused ? metrics.focusedBorderThickness : metrics.baseBorderThickness,
|
||||||
|
metrics.barCornerRounding);
|
||||||
|
|
||||||
|
for (std::size_t index = 0; index < layout.buttonRects.size() && index < items.size(); ++index) {
|
||||||
|
const bool open = state.openIndex == index;
|
||||||
|
const bool hovered = state.hoveredIndex == index;
|
||||||
|
drawList.AddFilledRect(
|
||||||
|
layout.buttonRects[index],
|
||||||
|
ResolveButtonFillColor(open, hovered, palette),
|
||||||
|
metrics.buttonCornerRounding);
|
||||||
|
drawList.AddRectOutline(
|
||||||
|
layout.buttonRects[index],
|
||||||
|
ResolveButtonBorderColor(open, state.focused && open, palette),
|
||||||
|
ResolveButtonBorderThickness(open, state.focused && open, metrics),
|
||||||
|
metrics.buttonCornerRounding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBarForeground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorMenuBarLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState&,
|
||||||
|
const UIEditorMenuBarPalette& palette,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
for (std::size_t index = 0; index < layout.buttonRects.size() && index < items.size(); ++index) {
|
||||||
|
const UIRect& rect = layout.buttonRects[index];
|
||||||
|
const float textLeft = rect.x + ClampNonNegative(metrics.buttonPaddingX);
|
||||||
|
const float textRight = rect.x + rect.width - ClampNonNegative(metrics.buttonPaddingX);
|
||||||
|
if (textRight <= textLeft) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList.PushClipRect(UIRect(textLeft, rect.y, textRight - textLeft, rect.height), true);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(textLeft, ResolveLabelTop(rect, metrics)),
|
||||||
|
items[index].label,
|
||||||
|
items[index].enabled ? palette.textPrimary : palette.textDisabled,
|
||||||
|
kMenuBarFontSize);
|
||||||
|
drawList.PopClipRect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuBar(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIRect& bounds,
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
const UIEditorMenuBarState& state,
|
||||||
|
const UIEditorMenuBarPalette& palette,
|
||||||
|
const UIEditorMenuBarMetrics& metrics) {
|
||||||
|
const UIEditorMenuBarLayout layout = BuildUIEditorMenuBarLayout(bounds, items, metrics);
|
||||||
|
AppendUIEditorMenuBarBackground(drawList, layout, items, state, palette, metrics);
|
||||||
|
AppendUIEditorMenuBarForeground(drawList, layout, items, state, palette, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
289
new_editor/src/Widgets/UIEditorMenuPopup.cpp
Normal file
289
new_editor/src/Widgets/UIEditorMenuPopup.cpp
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
#include <XCEditor/Widgets/UIEditorMenuPopup.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ::XCEngine::UI::UIColor;
|
||||||
|
using ::XCEngine::UI::UIDrawList;
|
||||||
|
using ::XCEngine::UI::UIPoint;
|
||||||
|
using ::XCEngine::UI::UIRect;
|
||||||
|
using ::XCEngine::UI::Editor::UIEditorMenuItemKind;
|
||||||
|
|
||||||
|
constexpr float kPopupFontSize = 13.0f;
|
||||||
|
constexpr float kGlyphFontSize = 12.0f;
|
||||||
|
|
||||||
|
float ClampNonNegative(float value) {
|
||||||
|
return (std::max)(value, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsPointInsideRect(const UIRect& rect, const UIPoint& point) {
|
||||||
|
return point.x >= rect.x &&
|
||||||
|
point.x <= rect.x + rect.width &&
|
||||||
|
point.y >= rect.y &&
|
||||||
|
point.y <= rect.y + rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveEstimatedWidth(float explicitWidth, std::string_view text, float glyphWidth) {
|
||||||
|
if (explicitWidth > 0.0f) {
|
||||||
|
return explicitWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<float>(text.size()) * glyphWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsInteractiveItem(const UIEditorMenuPopupItem& item) {
|
||||||
|
return item.kind != UIEditorMenuItemKind::Separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveRowTextTop(const UIRect& rect, const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
return rect.y + (std::max)(0.0f, (rect.height - kPopupFontSize) * 0.5f) + metrics.labelInsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ResolveGlyphTop(const UIRect& rect) {
|
||||||
|
return rect.y + (std::max)(0.0f, (rect.height - kGlyphFontSize) * 0.5f) - 0.5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsHighlighted(const UIEditorMenuPopupState& state, std::size_t index) {
|
||||||
|
return state.hoveredIndex == index || state.submenuOpenIndex == index;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
float ResolveUIEditorMenuPopupDesiredWidth(
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
float widestRow = 0.0f;
|
||||||
|
for (const UIEditorMenuPopupItem& item : items) {
|
||||||
|
if (item.kind == UIEditorMenuItemKind::Separator) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float labelWidth =
|
||||||
|
ResolveEstimatedWidth(item.desiredLabelWidth, item.label, metrics.estimatedGlyphWidth);
|
||||||
|
const float shortcutWidth =
|
||||||
|
item.shortcutText.empty()
|
||||||
|
? 0.0f
|
||||||
|
: ResolveEstimatedWidth(
|
||||||
|
item.desiredShortcutWidth,
|
||||||
|
item.shortcutText,
|
||||||
|
metrics.estimatedGlyphWidth);
|
||||||
|
const float submenuWidth =
|
||||||
|
item.hasSubmenu ? ClampNonNegative(metrics.submenuIndicatorWidth) : 0.0f;
|
||||||
|
const float rowWidth =
|
||||||
|
ClampNonNegative(metrics.labelInsetX) +
|
||||||
|
ClampNonNegative(metrics.checkColumnWidth) +
|
||||||
|
labelWidth +
|
||||||
|
(shortcutWidth > 0.0f ? ClampNonNegative(metrics.shortcutGap) + shortcutWidth : 0.0f) +
|
||||||
|
submenuWidth +
|
||||||
|
ClampNonNegative(metrics.shortcutInsetRight);
|
||||||
|
widestRow = (std::max)(widestRow, rowWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return widestRow + ClampNonNegative(metrics.contentPaddingX) * 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float MeasureUIEditorMenuPopupHeight(
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
float height = ClampNonNegative(metrics.contentPaddingY) * 2.0f;
|
||||||
|
for (const UIEditorMenuPopupItem& item : items) {
|
||||||
|
height += item.kind == UIEditorMenuItemKind::Separator
|
||||||
|
? ClampNonNegative(metrics.separatorHeight)
|
||||||
|
: ClampNonNegative(metrics.itemHeight);
|
||||||
|
}
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorMenuPopupLayout BuildUIEditorMenuPopupLayout(
|
||||||
|
const UIRect& popupRect,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
UIEditorMenuPopupLayout layout = {};
|
||||||
|
layout.popupRect = UIRect(
|
||||||
|
popupRect.x,
|
||||||
|
popupRect.y,
|
||||||
|
ClampNonNegative(popupRect.width),
|
||||||
|
ClampNonNegative(popupRect.height));
|
||||||
|
layout.contentRect = UIRect(
|
||||||
|
layout.popupRect.x + ClampNonNegative(metrics.contentPaddingX),
|
||||||
|
layout.popupRect.y + ClampNonNegative(metrics.contentPaddingY),
|
||||||
|
(std::max)(
|
||||||
|
layout.popupRect.width - ClampNonNegative(metrics.contentPaddingX) * 2.0f,
|
||||||
|
0.0f),
|
||||||
|
(std::max)(
|
||||||
|
layout.popupRect.height - ClampNonNegative(metrics.contentPaddingY) * 2.0f,
|
||||||
|
0.0f));
|
||||||
|
|
||||||
|
float cursorY = layout.contentRect.y;
|
||||||
|
layout.itemRects.reserve(items.size());
|
||||||
|
for (const UIEditorMenuPopupItem& item : items) {
|
||||||
|
const float itemHeight = item.kind == UIEditorMenuItemKind::Separator
|
||||||
|
? ClampNonNegative(metrics.separatorHeight)
|
||||||
|
: ClampNonNegative(metrics.itemHeight);
|
||||||
|
layout.itemRects.emplace_back(
|
||||||
|
layout.contentRect.x,
|
||||||
|
cursorY,
|
||||||
|
layout.contentRect.width,
|
||||||
|
itemHeight);
|
||||||
|
cursorY += itemHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorMenuPopupHitTarget HitTestUIEditorMenuPopup(
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIPoint& point) {
|
||||||
|
UIEditorMenuPopupHitTarget target = {};
|
||||||
|
if (!IsPointInsideRect(layout.popupRect, point)) {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t index = 0; index < layout.itemRects.size() && index < items.size(); ++index) {
|
||||||
|
if (IsInteractiveItem(items[index]) && IsPointInsideRect(layout.itemRects[index], point)) {
|
||||||
|
target.kind = UIEditorMenuPopupHitTargetKind::Item;
|
||||||
|
target.index = index;
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.kind = UIEditorMenuPopupHitTargetKind::PopupSurface;
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopupBackground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState& state,
|
||||||
|
const UIEditorMenuPopupPalette& palette,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
drawList.AddFilledRect(layout.popupRect, palette.popupColor, metrics.popupCornerRounding);
|
||||||
|
drawList.AddRectOutline(
|
||||||
|
layout.popupRect,
|
||||||
|
palette.borderColor,
|
||||||
|
metrics.borderThickness,
|
||||||
|
metrics.popupCornerRounding);
|
||||||
|
|
||||||
|
for (std::size_t index = 0; index < layout.itemRects.size() && index < items.size(); ++index) {
|
||||||
|
const UIEditorMenuPopupItem& item = items[index];
|
||||||
|
const UIRect& rect = layout.itemRects[index];
|
||||||
|
if (item.kind == UIEditorMenuItemKind::Separator) {
|
||||||
|
const float lineY = rect.y + rect.height * 0.5f;
|
||||||
|
drawList.AddFilledRect(
|
||||||
|
UIRect(rect.x + 8.0f, lineY, (std::max)(rect.width - 16.0f, 0.0f), metrics.separatorThickness),
|
||||||
|
palette.separatorColor);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsHighlighted(state, index)) {
|
||||||
|
drawList.AddFilledRect(
|
||||||
|
rect,
|
||||||
|
state.submenuOpenIndex == index ? palette.itemOpenColor : palette.itemHoverColor,
|
||||||
|
metrics.rowCornerRounding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopupForeground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorMenuPopupLayout& layout,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState&,
|
||||||
|
const UIEditorMenuPopupPalette& palette,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
for (std::size_t index = 0; index < layout.itemRects.size() && index < items.size(); ++index) {
|
||||||
|
const UIEditorMenuPopupItem& item = items[index];
|
||||||
|
if (item.kind == UIEditorMenuItemKind::Separator) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UIRect& rect = layout.itemRects[index];
|
||||||
|
const UIColor mainColor = item.enabled ? palette.textPrimary : palette.textDisabled;
|
||||||
|
const UIColor secondaryColor = item.enabled ? palette.textMuted : palette.textDisabled;
|
||||||
|
|
||||||
|
const float checkLeft = rect.x + 6.0f;
|
||||||
|
if (item.checked) {
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(checkLeft, ResolveGlyphTop(rect)),
|
||||||
|
"*",
|
||||||
|
palette.glyphColor,
|
||||||
|
kGlyphFontSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float labelLeft =
|
||||||
|
rect.x + ClampNonNegative(metrics.labelInsetX) + ClampNonNegative(metrics.checkColumnWidth);
|
||||||
|
const float labelRight =
|
||||||
|
rect.x + rect.width - ClampNonNegative(metrics.shortcutInsetRight);
|
||||||
|
float labelClipWidth = (std::max)(labelRight - labelLeft, 0.0f);
|
||||||
|
if (!item.shortcutText.empty()) {
|
||||||
|
const float shortcutWidth =
|
||||||
|
ResolveEstimatedWidth(
|
||||||
|
item.desiredShortcutWidth,
|
||||||
|
item.shortcutText,
|
||||||
|
metrics.estimatedGlyphWidth);
|
||||||
|
labelClipWidth = (std::max)(
|
||||||
|
labelClipWidth - shortcutWidth - ClampNonNegative(metrics.shortcutGap),
|
||||||
|
0.0f);
|
||||||
|
}
|
||||||
|
if (item.hasSubmenu) {
|
||||||
|
labelClipWidth = (std::max)(
|
||||||
|
labelClipWidth - ClampNonNegative(metrics.submenuIndicatorWidth),
|
||||||
|
0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList.PushClipRect(UIRect(labelLeft, rect.y, labelClipWidth, rect.height), true);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(labelLeft, ResolveRowTextTop(rect, metrics)),
|
||||||
|
item.label,
|
||||||
|
mainColor,
|
||||||
|
kPopupFontSize);
|
||||||
|
drawList.PopClipRect();
|
||||||
|
|
||||||
|
if (!item.shortcutText.empty()) {
|
||||||
|
const float shortcutWidth =
|
||||||
|
ResolveEstimatedWidth(
|
||||||
|
item.desiredShortcutWidth,
|
||||||
|
item.shortcutText,
|
||||||
|
metrics.estimatedGlyphWidth);
|
||||||
|
const float shortcutLeft = rect.x + rect.width -
|
||||||
|
ClampNonNegative(metrics.shortcutInsetRight) -
|
||||||
|
shortcutWidth -
|
||||||
|
(item.hasSubmenu ? ClampNonNegative(metrics.submenuIndicatorWidth) : 0.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(shortcutLeft, ResolveRowTextTop(rect, metrics)),
|
||||||
|
item.shortcutText,
|
||||||
|
secondaryColor,
|
||||||
|
kPopupFontSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.hasSubmenu) {
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(
|
||||||
|
rect.x + rect.width - ClampNonNegative(metrics.shortcutInsetRight),
|
||||||
|
ResolveGlyphTop(rect)),
|
||||||
|
">",
|
||||||
|
palette.glyphColor,
|
||||||
|
kGlyphFontSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorMenuPopup(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIRect& popupRect,
|
||||||
|
const std::vector<UIEditorMenuPopupItem>& items,
|
||||||
|
const UIEditorMenuPopupState& state,
|
||||||
|
const UIEditorMenuPopupPalette& palette,
|
||||||
|
const UIEditorMenuPopupMetrics& metrics) {
|
||||||
|
const UIEditorMenuPopupLayout layout =
|
||||||
|
BuildUIEditorMenuPopupLayout(popupRect, items, metrics);
|
||||||
|
AppendUIEditorMenuPopupBackground(drawList, layout, items, state, palette, metrics);
|
||||||
|
AppendUIEditorMenuPopupForeground(drawList, layout, items, state, palette, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
279
new_editor/src/Widgets/UIEditorStatusBar.cpp
Normal file
279
new_editor/src/Widgets/UIEditorStatusBar.cpp
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
#include <XCEditor/Widgets/UIEditorStatusBar.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace XCEngine::UI::Editor::Widgets {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using ::XCEngine::UI::UIColor;
|
||||||
|
using ::XCEngine::UI::UIDrawList;
|
||||||
|
using ::XCEngine::UI::UIPoint;
|
||||||
|
using ::XCEngine::UI::UIRect;
|
||||||
|
|
||||||
|
bool ContainsPoint(const UIRect& rect, const UIPoint& point) {
|
||||||
|
return point.x >= rect.x &&
|
||||||
|
point.x <= rect.x + rect.width &&
|
||||||
|
point.y >= rect.y &&
|
||||||
|
point.y <= rect.y + rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HasArea(const UIRect& rect) {
|
||||||
|
return rect.width > 0.0f && rect.height > 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ClampNonNegative(float value) {
|
||||||
|
return (std::max)(value, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
UIColor ResolveSegmentFillColor(
|
||||||
|
bool hovered,
|
||||||
|
bool active,
|
||||||
|
const UIEditorStatusBarPalette& palette) {
|
||||||
|
if (active) {
|
||||||
|
return palette.segmentActiveColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hovered) {
|
||||||
|
return palette.segmentHoveredColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return palette.segmentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
float ResolveUIEditorStatusBarDesiredSegmentWidth(
|
||||||
|
const UIEditorStatusBarSegment& segment,
|
||||||
|
const UIEditorStatusBarMetrics& metrics) {
|
||||||
|
if (segment.desiredWidth > 0.0f) {
|
||||||
|
return segment.desiredWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return segment.label.empty()
|
||||||
|
? metrics.segmentPaddingX * 2.0f
|
||||||
|
: metrics.segmentPaddingX * 2.0f +
|
||||||
|
static_cast<float>(segment.label.size()) * metrics.estimatedGlyphWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorStatusBarLayout BuildUIEditorStatusBarLayout(
|
||||||
|
const UIRect& bounds,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarMetrics& metrics) {
|
||||||
|
UIEditorStatusBarLayout layout = {};
|
||||||
|
layout.bounds = UIRect(
|
||||||
|
bounds.x,
|
||||||
|
bounds.y,
|
||||||
|
ClampNonNegative(bounds.width),
|
||||||
|
ClampNonNegative(bounds.height));
|
||||||
|
layout.segmentRects.resize(segments.size(), UIRect{});
|
||||||
|
layout.separatorRects.resize(segments.size(), UIRect{});
|
||||||
|
|
||||||
|
const float contentTop = layout.bounds.y;
|
||||||
|
const float contentHeight = layout.bounds.height;
|
||||||
|
const float leftStart = layout.bounds.x + metrics.outerPaddingX;
|
||||||
|
const float rightLimit = layout.bounds.x + layout.bounds.width - metrics.outerPaddingX;
|
||||||
|
|
||||||
|
float leadingCursor = leftStart;
|
||||||
|
float leadingRight = leftStart;
|
||||||
|
for (std::size_t index = 0u; index < segments.size(); ++index) {
|
||||||
|
const auto& segment = segments[index];
|
||||||
|
if (segment.slot != UIEditorStatusBarSlot::Leading) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float segmentWidth = ResolveUIEditorStatusBarDesiredSegmentWidth(segment, metrics);
|
||||||
|
layout.segmentRects[index] = UIRect(
|
||||||
|
leadingCursor,
|
||||||
|
contentTop,
|
||||||
|
segmentWidth,
|
||||||
|
contentHeight);
|
||||||
|
leadingCursor += segmentWidth;
|
||||||
|
leadingRight = leadingCursor;
|
||||||
|
|
||||||
|
if (segment.showSeparator) {
|
||||||
|
layout.separatorRects[index] = UIRect(
|
||||||
|
leadingCursor,
|
||||||
|
contentTop + metrics.separatorInsetY,
|
||||||
|
metrics.separatorWidth,
|
||||||
|
(std::max)(contentHeight - metrics.separatorInsetY * 2.0f, 0.0f));
|
||||||
|
leadingCursor += metrics.separatorWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
leadingCursor += metrics.segmentGap;
|
||||||
|
leadingRight = (std::max)(leadingRight, leadingCursor - metrics.segmentGap);
|
||||||
|
}
|
||||||
|
|
||||||
|
float trailingCursor = rightLimit;
|
||||||
|
float trailingLeft = rightLimit;
|
||||||
|
for (std::size_t reverseIndex = segments.size(); reverseIndex > 0u; --reverseIndex) {
|
||||||
|
const std::size_t index = reverseIndex - 1u;
|
||||||
|
const auto& segment = segments[index];
|
||||||
|
if (segment.slot != UIEditorStatusBarSlot::Trailing) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float segmentWidth = ResolveUIEditorStatusBarDesiredSegmentWidth(segment, metrics);
|
||||||
|
const bool hasSeparator = segment.showSeparator;
|
||||||
|
|
||||||
|
if (hasSeparator) {
|
||||||
|
trailingCursor -= metrics.separatorWidth;
|
||||||
|
layout.separatorRects[index] = UIRect(
|
||||||
|
trailingCursor,
|
||||||
|
contentTop + metrics.separatorInsetY,
|
||||||
|
metrics.separatorWidth,
|
||||||
|
(std::max)(contentHeight - metrics.separatorInsetY * 2.0f, 0.0f));
|
||||||
|
trailingCursor -= metrics.segmentGap;
|
||||||
|
}
|
||||||
|
|
||||||
|
trailingCursor -= segmentWidth;
|
||||||
|
layout.segmentRects[index] = UIRect(
|
||||||
|
trailingCursor,
|
||||||
|
contentTop,
|
||||||
|
segmentWidth,
|
||||||
|
contentHeight);
|
||||||
|
trailingCursor -= metrics.segmentGap;
|
||||||
|
trailingLeft = (std::min)(trailingLeft, layout.segmentRects[index].x);
|
||||||
|
}
|
||||||
|
|
||||||
|
const float leadingWidth =
|
||||||
|
leadingRight > leftStart ? leadingRight - leftStart : 0.0f;
|
||||||
|
layout.leadingSlotRect = UIRect(leftStart, contentTop, leadingWidth, contentHeight);
|
||||||
|
|
||||||
|
const float trailingWidth =
|
||||||
|
trailingLeft < rightLimit ? rightLimit - trailingLeft : 0.0f;
|
||||||
|
layout.trailingSlotRect = UIRect(trailingLeft, contentTop, trailingWidth, contentHeight);
|
||||||
|
|
||||||
|
if (HasArea(layout.leadingSlotRect) &&
|
||||||
|
HasArea(layout.trailingSlotRect) &&
|
||||||
|
layout.leadingSlotRect.x + layout.leadingSlotRect.width + metrics.slotGapMin >
|
||||||
|
layout.trailingSlotRect.x) {
|
||||||
|
const float overlap =
|
||||||
|
layout.leadingSlotRect.x + layout.leadingSlotRect.width + metrics.slotGapMin -
|
||||||
|
layout.trailingSlotRect.x;
|
||||||
|
layout.trailingSlotRect.x += overlap;
|
||||||
|
layout.trailingSlotRect.width = (std::max)(layout.trailingSlotRect.width - overlap, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
UIEditorStatusBarHitTarget HitTestUIEditorStatusBar(
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const UIPoint& point) {
|
||||||
|
if (!ContainsPoint(layout.bounds, point)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t index = 0u; index < layout.separatorRects.size(); ++index) {
|
||||||
|
if (HasArea(layout.separatorRects[index]) &&
|
||||||
|
ContainsPoint(layout.separatorRects[index], point)) {
|
||||||
|
return { UIEditorStatusBarHitTargetKind::Separator, index };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t index = 0u; index < layout.segmentRects.size(); ++index) {
|
||||||
|
if (HasArea(layout.segmentRects[index]) &&
|
||||||
|
ContainsPoint(layout.segmentRects[index], point)) {
|
||||||
|
return { UIEditorStatusBarHitTargetKind::Segment, index };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { UIEditorStatusBarHitTargetKind::Background, UIEditorStatusBarInvalidIndex };
|
||||||
|
}
|
||||||
|
|
||||||
|
UIColor ResolveUIEditorStatusBarTextColor(
|
||||||
|
UIEditorStatusBarTextTone tone,
|
||||||
|
const UIEditorStatusBarPalette& palette) {
|
||||||
|
switch (tone) {
|
||||||
|
case UIEditorStatusBarTextTone::Muted:
|
||||||
|
return palette.textMuted;
|
||||||
|
case UIEditorStatusBarTextTone::Accent:
|
||||||
|
return palette.textAccent;
|
||||||
|
case UIEditorStatusBarTextTone::Primary:
|
||||||
|
default:
|
||||||
|
return palette.textPrimary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBarBackground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState& state,
|
||||||
|
const UIEditorStatusBarPalette& palette,
|
||||||
|
const UIEditorStatusBarMetrics& metrics) {
|
||||||
|
drawList.AddFilledRect(layout.bounds, palette.surfaceColor, metrics.cornerRounding);
|
||||||
|
drawList.AddRectOutline(
|
||||||
|
layout.bounds,
|
||||||
|
state.focused ? palette.focusedBorderColor : palette.borderColor,
|
||||||
|
state.focused ? metrics.focusedBorderThickness : metrics.borderThickness,
|
||||||
|
metrics.cornerRounding);
|
||||||
|
|
||||||
|
for (std::size_t index = 0u; index < segments.size(); ++index) {
|
||||||
|
if (!HasArea(layout.segmentRects[index])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool hovered = state.hoveredIndex == index;
|
||||||
|
const bool active = state.activeIndex == index;
|
||||||
|
if (!hovered && !active) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList.AddFilledRect(
|
||||||
|
layout.segmentRects[index],
|
||||||
|
ResolveSegmentFillColor(hovered, active, palette),
|
||||||
|
6.0f);
|
||||||
|
drawList.AddRectOutline(
|
||||||
|
layout.segmentRects[index],
|
||||||
|
palette.segmentBorderColor,
|
||||||
|
1.0f,
|
||||||
|
6.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const UIRect& separatorRect : layout.separatorRects) {
|
||||||
|
if (!HasArea(separatorRect)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList.AddFilledRect(separatorRect, palette.separatorColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBarForeground(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIEditorStatusBarLayout& layout,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState&,
|
||||||
|
const UIEditorStatusBarPalette& palette,
|
||||||
|
const UIEditorStatusBarMetrics& metrics) {
|
||||||
|
for (std::size_t index = 0u; index < segments.size(); ++index) {
|
||||||
|
if (!HasArea(layout.segmentRects[index]) || segments[index].label.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(
|
||||||
|
layout.segmentRects[index].x + metrics.segmentPaddingX,
|
||||||
|
layout.segmentRects[index].y + metrics.segmentPaddingY),
|
||||||
|
segments[index].label,
|
||||||
|
ResolveUIEditorStatusBarTextColor(segments[index].tone, palette),
|
||||||
|
12.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppendUIEditorStatusBar(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIRect& bounds,
|
||||||
|
const std::vector<UIEditorStatusBarSegment>& segments,
|
||||||
|
const UIEditorStatusBarState& state,
|
||||||
|
const UIEditorStatusBarPalette& palette,
|
||||||
|
const UIEditorStatusBarMetrics& metrics) {
|
||||||
|
const UIEditorStatusBarLayout layout =
|
||||||
|
BuildUIEditorStatusBarLayout(bounds, segments, metrics);
|
||||||
|
AppendUIEditorStatusBarBackground(drawList, layout, segments, state, palette, metrics);
|
||||||
|
AppendUIEditorStatusBarForeground(drawList, layout, segments, state, palette, metrics);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace XCEngine::UI::Editor::Widgets
|
||||||
@@ -4,13 +4,27 @@ add_subdirectory(shared)
|
|||||||
add_subdirectory(shell)
|
add_subdirectory(shell)
|
||||||
add_subdirectory(state)
|
add_subdirectory(state)
|
||||||
|
|
||||||
|
set(EDITOR_UI_INTEGRATION_TARGETS
|
||||||
|
editor_ui_workspace_shell_compose_validation
|
||||||
|
editor_ui_menu_bar_basic_validation
|
||||||
|
editor_ui_panel_frame_basic_validation
|
||||||
|
editor_ui_tab_strip_basic_validation
|
||||||
|
editor_ui_panel_session_flow_validation
|
||||||
|
editor_ui_layout_persistence_validation
|
||||||
|
editor_ui_shortcut_dispatch_validation
|
||||||
|
)
|
||||||
|
|
||||||
|
if(TARGET editor_ui_status_bar_basic_validation)
|
||||||
|
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
|
||||||
|
editor_ui_status_bar_basic_validation)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET editor_ui_context_menu_basic_validation)
|
||||||
|
list(APPEND EDITOR_UI_INTEGRATION_TARGETS
|
||||||
|
editor_ui_context_menu_basic_validation)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_target(editor_ui_integration_tests
|
add_custom_target(editor_ui_integration_tests
|
||||||
DEPENDS
|
DEPENDS
|
||||||
editor_ui_workspace_shell_compose_validation
|
${EDITOR_UI_INTEGRATION_TARGETS}
|
||||||
editor_ui_menu_bar_basic_validation
|
|
||||||
editor_ui_panel_frame_basic_validation
|
|
||||||
editor_ui_tab_strip_basic_validation
|
|
||||||
editor_ui_panel_session_flow_validation
|
|
||||||
editor_ui_layout_persistence_validation
|
|
||||||
editor_ui_shortcut_dispatch_validation
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ Layout:
|
|||||||
- `shared/`: shared host wrapper, scenario registry, shared theme
|
- `shared/`: shared host wrapper, scenario registry, shared theme
|
||||||
- `shell/workspace_shell_compose/`: split/tab/panel shell compose only
|
- `shell/workspace_shell_compose/`: split/tab/panel shell compose only
|
||||||
- `shell/menu_bar_basic/`: menu bar open/close/hover/dispatch only
|
- `shell/menu_bar_basic/`: menu bar open/close/hover/dispatch only
|
||||||
|
- `shell/context_menu_basic/`: context menu root/submenu/dismiss/dispatch only
|
||||||
- `shell/panel_frame_basic/`: panel frame layout/state/hit-test only
|
- `shell/panel_frame_basic/`: panel frame layout/state/hit-test only
|
||||||
|
- `shell/status_bar_basic/`: status bar slot/segment/hit-test only
|
||||||
- `shell/tab_strip_basic/`: tab strip layout/state/hit-test/close/navigation only
|
- `shell/tab_strip_basic/`: tab strip layout/state/hit-test/close/navigation only
|
||||||
- `state/panel_session_flow/`: panel session state flow only
|
- `state/panel_session_flow/`: panel session state flow only
|
||||||
- `state/layout_persistence/`: layout save/load/reset only
|
- `state/layout_persistence/`: layout save/load/reset only
|
||||||
@@ -32,11 +34,21 @@ Scenarios:
|
|||||||
Executable: `XCUIEditorMenuBarBasicValidation.exe`
|
Executable: `XCUIEditorMenuBarBasicValidation.exe`
|
||||||
Scope: menu bar open/close, hover, dismiss, menu command dispatch only
|
Scope: menu bar open/close, hover, dismiss, menu command dispatch only
|
||||||
|
|
||||||
|
- `editor.shell.context_menu_basic`
|
||||||
|
Build target: `editor_ui_context_menu_basic_validation`
|
||||||
|
Executable: `XCUIEditorContextMenuBasicValidation.exe`
|
||||||
|
Scope: context menu root anchor, submenu hover, outside/Esc dismiss, command dispatch only
|
||||||
|
|
||||||
- `editor.shell.panel_frame_basic`
|
- `editor.shell.panel_frame_basic`
|
||||||
Build target: `editor_ui_panel_frame_basic_validation`
|
Build target: `editor_ui_panel_frame_basic_validation`
|
||||||
Executable: `XCUIEditorPanelFrameBasicValidation.exe`
|
Executable: `XCUIEditorPanelFrameBasicValidation.exe`
|
||||||
Scope: panel frame header/body/footer layout, focus/active/hover chrome, pin/close hit target only
|
Scope: panel frame header/body/footer layout, focus/active/hover chrome, pin/close hit target only
|
||||||
|
|
||||||
|
- `editor.shell.status_bar_basic`
|
||||||
|
Build target: `editor_ui_status_bar_basic_validation`
|
||||||
|
Executable: `XCUIEditorStatusBarBasicValidation.exe`
|
||||||
|
Scope: status bar slot layout, hover/active segment hit target, separator layout only
|
||||||
|
|
||||||
- `editor.shell.tab_strip_basic`
|
- `editor.shell.tab_strip_basic`
|
||||||
Build target: `editor_ui_tab_strip_basic_validation`
|
Build target: `editor_ui_tab_strip_basic_validation`
|
||||||
Executable: `XCUIEditorTabStripBasicValidation.exe`
|
Executable: `XCUIEditorTabStripBasicValidation.exe`
|
||||||
@@ -63,6 +75,11 @@ Run:
|
|||||||
cmake --build build --config Debug --target editor_ui_integration_tests
|
cmake --build build --config Debug --target editor_ui_integration_tests
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Auto capture:
|
||||||
|
|
||||||
|
- Set `XCUI_AUTO_CAPTURE_ON_STARTUP=1` before launching a validation executable to force a first-frame screenshot into that scenario's `captures/` directory.
|
||||||
|
- Manual validation still uses `F12`; startup auto capture is only for deterministic self-check / automation.
|
||||||
|
|
||||||
Selected controls:
|
Selected controls:
|
||||||
|
|
||||||
- `shell/workspace_shell_compose/`
|
- `shell/workspace_shell_compose/`
|
||||||
@@ -71,9 +88,15 @@ Selected controls:
|
|||||||
- `shell/menu_bar_basic/`
|
- `shell/menu_bar_basic/`
|
||||||
Click `File / Window / Layout`, move the mouse across menu items, click outside the menu or press `Esc`, press `F12`.
|
Click `File / Window / Layout`, move the mouse across menu items, click outside the menu or press `Esc`, press `F12`.
|
||||||
|
|
||||||
|
- `shell/context_menu_basic/`
|
||||||
|
Right click inside `Context Target`, hover `Workspace Tools`, click actions, click outside the menu or press `Esc`, press `F12`.
|
||||||
|
|
||||||
- `shell/panel_frame_basic/`
|
- `shell/panel_frame_basic/`
|
||||||
Move the mouse over the preview panel, click `Body / Pin / Close`, toggle `Active / Focus / Closable / Footer`, press `F12`.
|
Move the mouse over the preview panel, click `Body / Pin / Close`, toggle `Active / Focus / Closable / Footer`, press `F12`.
|
||||||
|
|
||||||
|
- `shell/status_bar_basic/`
|
||||||
|
Move the mouse across leading/trailing segments, click interactive segments, toggle focus/active, press `F12`.
|
||||||
|
|
||||||
- `shell/tab_strip_basic/`
|
- `shell/tab_strip_basic/`
|
||||||
Click `Document A / B / C`, click `X` on closable tabs, click content to focus, press `Left / Right / Home / End`, press `Reset`, press `F12`.
|
Click `Document A / B / C`, click `X` on closable tabs, click content to focus, press `Left / Right / Home / End`, press `Reset`, press `F12`.
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,9 @@ add_subdirectory(tab_strip_basic)
|
|||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/menu_bar_basic/CMakeLists.txt")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/menu_bar_basic/CMakeLists.txt")
|
||||||
add_subdirectory(menu_bar_basic)
|
add_subdirectory(menu_bar_basic)
|
||||||
endif()
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/status_bar_basic/CMakeLists.txt")
|
||||||
|
add_subdirectory(status_bar_basic)
|
||||||
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/context_menu_basic/CMakeLists.txt")
|
||||||
|
add_subdirectory(context_menu_basic)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
add_executable(editor_ui_context_menu_basic_validation WIN32
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(editor_ui_context_menu_basic_validation PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/engine/include
|
||||||
|
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||||
|
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||||
|
${CMAKE_SOURCE_DIR}/new_editor/src
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(editor_ui_context_menu_basic_validation PRIVATE
|
||||||
|
UNICODE
|
||||||
|
_UNICODE
|
||||||
|
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(editor_ui_context_menu_basic_validation PRIVATE /utf-8 /FS)
|
||||||
|
set_property(TARGET editor_ui_context_menu_basic_validation PROPERTY
|
||||||
|
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(editor_ui_context_menu_basic_validation PRIVATE
|
||||||
|
XCUIEditorLib
|
||||||
|
XCUIEditorHost
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(editor_ui_context_menu_basic_validation PROPERTIES
|
||||||
|
OUTPUT_NAME "XCUIEditorContextMenuBasicValidation"
|
||||||
|
)
|
||||||
1249
tests/UI/Editor/integration/shell/context_menu_basic/main.cpp
Normal file
1249
tests/UI/Editor/integration/shell/context_menu_basic/main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@
|
|||||||
#include <XCEditor/Core/UIEditorMenuModel.h>
|
#include <XCEditor/Core/UIEditorMenuModel.h>
|
||||||
#include <XCEditor/Core/UIEditorMenuSession.h>
|
#include <XCEditor/Core/UIEditorMenuSession.h>
|
||||||
#include <XCEditor/Core/UIEditorShortcutManager.h>
|
#include <XCEditor/Core/UIEditorShortcutManager.h>
|
||||||
|
#include <XCEditor/Widgets/UIEditorMenuBar.h>
|
||||||
|
#include <XCEditor/Widgets/UIEditorMenuPopup.h>
|
||||||
#include "Host/AutoScreenshot.h"
|
#include "Host/AutoScreenshot.h"
|
||||||
#include "Host/NativeRenderer.h"
|
#include "Host/NativeRenderer.h"
|
||||||
|
|
||||||
@@ -77,6 +79,20 @@ using XCEngine::UI::UIShortcutScope;
|
|||||||
using XCEngine::UI::Widgets::ResolvePopupPlacementRect;
|
using XCEngine::UI::Widgets::ResolvePopupPlacementRect;
|
||||||
using XCEngine::UI::Widgets::UIPopupOverlayEntry;
|
using XCEngine::UI::Widgets::UIPopupOverlayEntry;
|
||||||
using XCEngine::UI::Widgets::UIPopupPlacement;
|
using XCEngine::UI::Widgets::UIPopupPlacement;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuBarBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuBarForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuPopupBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuPopupForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorMenuBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorMenuPopupLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::MeasureUIEditorMenuPopupHeight;
|
||||||
|
using XCEngine::UI::Editor::Widgets::ResolveUIEditorMenuPopupDesiredWidth;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarItem;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarState;
|
||||||
|
using UIEditorMenuPopupWidgetItem = XCEngine::UI::Editor::Widgets::UIEditorMenuPopupItem;
|
||||||
|
using UIEditorMenuPopupWidgetState = XCEngine::UI::Editor::Widgets::UIEditorMenuPopupState;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarInvalidIndex;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuPopupInvalidIndex;
|
||||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||||
|
|
||||||
@@ -159,8 +175,11 @@ std::string JoinClosedPopupIds(const UIEditorMenuSessionMutationResult& result);
|
|||||||
const UIEditorResolvedMenuDescriptor* FindResolvedMenu(const UIEditorResolvedMenuModel& model, std::string_view menuId);
|
const UIEditorResolvedMenuDescriptor* FindResolvedMenu(const UIEditorResolvedMenuModel& model, std::string_view menuId);
|
||||||
const UIEditorResolvedMenuItem* FindResolvedMenuItemRecursive(const std::vector<UIEditorResolvedMenuItem>& items, std::string_view itemId);
|
const UIEditorResolvedMenuItem* FindResolvedMenuItemRecursive(const std::vector<UIEditorResolvedMenuItem>& items, std::string_view itemId);
|
||||||
const std::vector<UIEditorResolvedMenuItem>* ResolvePopupItems(const UIEditorResolvedMenuModel& model, const UIEditorMenuPopupState& popupState);
|
const std::vector<UIEditorResolvedMenuItem>* ResolvePopupItems(const UIEditorResolvedMenuModel& model, const UIEditorMenuPopupState& popupState);
|
||||||
|
std::vector<UIEditorMenuBarItem> BuildMenuBarWidgetItems(const UIEditorResolvedMenuModel& model);
|
||||||
|
std::vector<UIEditorMenuPopupWidgetItem> BuildMenuPopupWidgetItems(const std::vector<UIEditorResolvedMenuItem>& items);
|
||||||
|
std::size_t FindMenuBarWidgetIndex(const std::vector<UIEditorMenuBarItem>& items, std::string_view menuId);
|
||||||
|
std::size_t FindMenuPopupWidgetIndex(const std::vector<UIEditorMenuPopupWidgetItem>& items, std::string_view itemId);
|
||||||
std::uint64_t HashText(std::string_view text);
|
std::uint64_t HashText(std::string_view text);
|
||||||
float MeasureMenuPopupHeight(const std::vector<UIEditorResolvedMenuItem>& items);
|
|
||||||
|
|
||||||
class ScenarioApp {
|
class ScenarioApp {
|
||||||
public:
|
public:
|
||||||
@@ -602,13 +621,61 @@ const std::vector<UIEditorResolvedMenuItem>* ResolvePopupItems(
|
|||||||
return &item->children;
|
return &item->children;
|
||||||
}
|
}
|
||||||
|
|
||||||
float MeasureMenuPopupHeight(const std::vector<UIEditorResolvedMenuItem>& items) {
|
std::vector<UIEditorMenuBarItem> BuildMenuBarWidgetItems(
|
||||||
float contentHeight = 10.0f;
|
const UIEditorResolvedMenuModel& model) {
|
||||||
|
std::vector<UIEditorMenuBarItem> items = {};
|
||||||
|
items.reserve(model.menus.size());
|
||||||
|
for (const UIEditorResolvedMenuDescriptor& menu : model.menus) {
|
||||||
|
UIEditorMenuBarItem item = {};
|
||||||
|
item.menuId = menu.menuId;
|
||||||
|
item.label = menu.label;
|
||||||
|
item.enabled = true;
|
||||||
|
items.push_back(std::move(item));
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<UIEditorMenuPopupWidgetItem> BuildMenuPopupWidgetItems(
|
||||||
|
const std::vector<UIEditorResolvedMenuItem>& items) {
|
||||||
|
std::vector<UIEditorMenuPopupWidgetItem> popupItems = {};
|
||||||
|
popupItems.reserve(items.size());
|
||||||
for (const UIEditorResolvedMenuItem& item : items) {
|
for (const UIEditorResolvedMenuItem& item : items) {
|
||||||
contentHeight += item.kind == UIEditorMenuItemKind::Separator ? 12.0f : 34.0f;
|
UIEditorMenuPopupWidgetItem popupItem = {};
|
||||||
|
popupItem.itemId = item.itemId;
|
||||||
|
popupItem.kind = item.kind;
|
||||||
|
popupItem.label = item.label;
|
||||||
|
popupItem.shortcutText = item.shortcutText;
|
||||||
|
popupItem.enabled = item.enabled;
|
||||||
|
popupItem.checked = item.checked;
|
||||||
|
popupItem.hasSubmenu =
|
||||||
|
item.kind == UIEditorMenuItemKind::Submenu && !item.children.empty();
|
||||||
|
popupItems.push_back(std::move(popupItem));
|
||||||
|
}
|
||||||
|
return popupItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t FindMenuBarWidgetIndex(
|
||||||
|
const std::vector<UIEditorMenuBarItem>& items,
|
||||||
|
std::string_view menuId) {
|
||||||
|
for (std::size_t index = 0; index < items.size(); ++index) {
|
||||||
|
if (items[index].menuId == menuId) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentHeight + 8.0f;
|
return UIEditorMenuBarInvalidIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t FindMenuPopupWidgetIndex(
|
||||||
|
const std::vector<UIEditorMenuPopupWidgetItem>& items,
|
||||||
|
std::string_view itemId) {
|
||||||
|
for (std::size_t index = 0; index < items.size(); ++index) {
|
||||||
|
if (items[index].itemId == itemId) {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UIEditorMenuPopupInvalidIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScenarioApp::Run(HINSTANCE hInstance, int nCmdShow) {
|
int ScenarioApp::Run(HINSTANCE hInstance, int nCmdShow) {
|
||||||
@@ -867,7 +934,8 @@ const MenuPopupLayout* ScenarioApp::HitTestMenuPopup(float x, float y) const {
|
|||||||
|
|
||||||
const MenuItemLayout* ScenarioApp::HitTestMenuItem(float x, float y) const {
|
const MenuItemLayout* ScenarioApp::HitTestMenuItem(float x, float y) const {
|
||||||
for (auto it = m_menuItems.rbegin(); it != m_menuItems.rend(); ++it) {
|
for (auto it = m_menuItems.rbegin(); it != m_menuItems.rend(); ++it) {
|
||||||
if (ContainsPoint(it->rect, x, y)) {
|
if (it->kind != UIEditorMenuItemKind::Separator &&
|
||||||
|
ContainsPoint(it->rect, x, y)) {
|
||||||
return &(*it);
|
return &(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1234,31 +1302,25 @@ void ScenarioApp::DrawMenuBar(
|
|||||||
UIDrawList& drawList,
|
UIDrawList& drawList,
|
||||||
const UIRect& rect,
|
const UIRect& rect,
|
||||||
const UIEditorResolvedMenuModel& resolvedModel) {
|
const UIEditorResolvedMenuModel& resolvedModel) {
|
||||||
drawList.AddFilledRect(rect, kMenuBarBg, 8.0f);
|
const auto barItems = BuildMenuBarWidgetItems(resolvedModel);
|
||||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 8.0f);
|
UIEditorMenuBarState barState = {};
|
||||||
|
barState.openIndex = FindMenuBarWidgetIndex(barItems, m_menuSession.GetOpenRootMenuId());
|
||||||
|
barState.hoveredIndex = FindMenuBarWidgetIndex(barItems, m_hoveredMenuId);
|
||||||
|
barState.focused = m_menuSession.HasOpenMenu();
|
||||||
|
|
||||||
float buttonX = rect.x + 12.0f;
|
const auto barLayout = BuildUIEditorMenuBarLayout(rect, barItems);
|
||||||
for (const UIEditorResolvedMenuDescriptor& menu : resolvedModel.menus) {
|
AppendUIEditorMenuBarBackground(drawList, barLayout, barItems, barState);
|
||||||
const bool open = m_menuSession.IsMenuOpen(menu.menuId);
|
AppendUIEditorMenuBarForeground(drawList, barLayout, barItems, barState);
|
||||||
const bool hovered = m_hoveredMenuId == menu.menuId;
|
|
||||||
const float buttonWidth = 104.0f;
|
|
||||||
const UIRect buttonRect(buttonX, rect.y + 6.0f, buttonWidth, rect.height - 12.0f);
|
|
||||||
|
|
||||||
drawList.AddFilledRect(
|
|
||||||
buttonRect,
|
|
||||||
open ? kMenuButtonOpen : (hovered ? kMenuButtonHover : kMenuButtonBg),
|
|
||||||
6.0f);
|
|
||||||
drawList.AddRectOutline(buttonRect, kCardBorder, 1.0f, 6.0f);
|
|
||||||
drawList.AddText(
|
|
||||||
UIPoint(buttonRect.x + 14.0f, buttonRect.y + 10.0f),
|
|
||||||
menu.label,
|
|
||||||
kTextPrimary,
|
|
||||||
14.0f);
|
|
||||||
|
|
||||||
|
for (std::size_t index = 0; index < barItems.size() && index < barLayout.buttonRects.size(); ++index) {
|
||||||
m_menuButtons.push_back(
|
m_menuButtons.push_back(
|
||||||
{ menu.menuId, menu.label, BuildRootPopupId(menu.menuId), buttonRect, BuildMenuButtonPath(menu.menuId) });
|
{
|
||||||
|
barItems[index].menuId,
|
||||||
buttonX += buttonWidth + 10.0f;
|
barItems[index].label,
|
||||||
|
BuildRootPopupId(barItems[index].menuId),
|
||||||
|
barLayout.buttonRects[index],
|
||||||
|
BuildMenuButtonPath(barItems[index].menuId)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1269,75 +1331,45 @@ void ScenarioApp::DrawPopup(
|
|||||||
const std::vector<UIEditorResolvedMenuItem>& items,
|
const std::vector<UIEditorResolvedMenuItem>& items,
|
||||||
const UIPopupOverlayEntry& popupEntry,
|
const UIPopupOverlayEntry& popupEntry,
|
||||||
const UIRect& viewportRect) {
|
const UIRect& viewportRect) {
|
||||||
|
const auto popupItems = BuildMenuPopupWidgetItems(items);
|
||||||
|
const float popupWidth = (std::max)(
|
||||||
|
kMenuPopupWidth,
|
||||||
|
ResolveUIEditorMenuPopupDesiredWidth(popupItems));
|
||||||
const auto placementResult =
|
const auto placementResult =
|
||||||
ResolvePopupPlacementRect(
|
ResolvePopupPlacementRect(
|
||||||
popupEntry.anchorRect,
|
popupEntry.anchorRect,
|
||||||
XCEngine::UI::UISize(kMenuPopupWidth, MeasureMenuPopupHeight(items)),
|
XCEngine::UI::UISize(popupWidth, MeasureUIEditorMenuPopupHeight(popupItems)),
|
||||||
viewportRect,
|
viewportRect,
|
||||||
popupEntry.placement);
|
popupEntry.placement);
|
||||||
const UIRect popupRect = placementResult.rect;
|
const UIRect popupRect = placementResult.rect;
|
||||||
|
|
||||||
drawList.AddFilledRect(popupRect, kMenuDropBg, 8.0f);
|
UIEditorMenuPopupWidgetState popupState = {};
|
||||||
drawList.AddRectOutline(popupRect, kCardBorder, 1.0f, 8.0f);
|
popupState.hoveredIndex = FindMenuPopupWidgetIndex(popupItems, m_hoveredItemId);
|
||||||
|
popupState.focused = true;
|
||||||
|
for (std::size_t index = 0; index < popupItems.size(); ++index) {
|
||||||
|
if (!popupItems[index].hasSubmenu) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_menuSession.IsPopupOpen(BuildSubmenuPopupId(popupItems[index].itemId))) {
|
||||||
|
popupState.submenuOpenIndex = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto popupLayout = BuildUIEditorMenuPopupLayout(popupRect, popupItems);
|
||||||
|
AppendUIEditorMenuPopupBackground(drawList, popupLayout, popupItems, popupState);
|
||||||
|
AppendUIEditorMenuPopupForeground(drawList, popupLayout, popupItems, popupState);
|
||||||
|
|
||||||
m_menuPopups.push_back(
|
m_menuPopups.push_back(
|
||||||
{ std::string(popupId), std::string(menuId), popupEntry.parentPopupId, popupRect, popupEntry.surfacePath });
|
{ std::string(popupId), std::string(menuId), popupEntry.parentPopupId, popupRect, popupEntry.surfacePath });
|
||||||
|
|
||||||
float itemY = popupRect.y + 8.0f;
|
for (std::size_t index = 0; index < items.size() && index < popupItems.size() && index < popupLayout.itemRects.size(); ++index) {
|
||||||
for (const UIEditorResolvedMenuItem& item : items) {
|
const UIEditorResolvedMenuItem& item = items[index];
|
||||||
if (item.kind == UIEditorMenuItemKind::Separator) {
|
|
||||||
drawList.AddFilledRect(
|
|
||||||
UIRect(popupRect.x + 12.0f, itemY + 4.0f, popupRect.width - 24.0f, 1.0f),
|
|
||||||
kMenuDivider);
|
|
||||||
itemY += 12.0f;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool hasSubmenu =
|
const bool hasSubmenu =
|
||||||
item.kind == UIEditorMenuItemKind::Submenu && !item.children.empty();
|
item.kind == UIEditorMenuItemKind::Submenu && !item.children.empty();
|
||||||
const std::string childPopupId =
|
const std::string childPopupId =
|
||||||
hasSubmenu ? BuildSubmenuPopupId(item.itemId) : std::string();
|
hasSubmenu ? BuildSubmenuPopupId(item.itemId) : std::string();
|
||||||
const bool submenuOpen =
|
|
||||||
hasSubmenu && m_menuSession.IsPopupOpen(childPopupId);
|
|
||||||
const bool hovered = m_hoveredItemId == item.itemId;
|
|
||||||
|
|
||||||
const UIRect itemRect(popupRect.x + 8.0f, itemY, popupRect.width - 16.0f, 30.0f);
|
|
||||||
if (hovered || submenuOpen) {
|
|
||||||
drawList.AddFilledRect(itemRect, kMenuItemHover, 6.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
drawList.AddRectOutline(
|
|
||||||
UIRect(itemRect.x + 10.0f, itemRect.y + 8.0f, 10.0f, 10.0f),
|
|
||||||
item.checked ? kAccent : kMenuDivider,
|
|
||||||
item.checked ? 2.0f : 1.0f,
|
|
||||||
3.0f);
|
|
||||||
if (item.checked) {
|
|
||||||
drawList.AddFilledRect(
|
|
||||||
UIRect(itemRect.x + 12.0f, itemRect.y + 10.0f, 6.0f, 6.0f),
|
|
||||||
kAccent,
|
|
||||||
2.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
drawList.AddText(
|
|
||||||
UIPoint(itemRect.x + 30.0f, itemRect.y + 7.0f),
|
|
||||||
item.label,
|
|
||||||
item.enabled ? kTextPrimary : kTextDisabled,
|
|
||||||
13.0f);
|
|
||||||
if (!item.shortcutText.empty()) {
|
|
||||||
drawList.AddText(
|
|
||||||
UIPoint(itemRect.x + itemRect.width - 92.0f, itemRect.y + 7.0f),
|
|
||||||
item.shortcutText,
|
|
||||||
item.enabled ? kTextMuted : kTextDisabled,
|
|
||||||
12.0f);
|
|
||||||
}
|
|
||||||
if (hasSubmenu) {
|
|
||||||
drawList.AddText(
|
|
||||||
UIPoint(itemRect.x + itemRect.width - 24.0f, itemRect.y + 7.0f),
|
|
||||||
">",
|
|
||||||
kTextMuted,
|
|
||||||
13.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_menuItems.push_back(
|
m_menuItems.push_back(
|
||||||
{
|
{
|
||||||
std::string(popupId),
|
std::string(popupId),
|
||||||
@@ -1348,13 +1380,12 @@ void ScenarioApp::DrawPopup(
|
|||||||
item.commandId,
|
item.commandId,
|
||||||
item.shortcutText,
|
item.shortcutText,
|
||||||
childPopupId,
|
childPopupId,
|
||||||
itemRect,
|
popupLayout.itemRects[index],
|
||||||
BuildMenuItemPath(popupId, item.itemId),
|
BuildMenuItemPath(popupId, item.itemId),
|
||||||
item.enabled,
|
item.enabled,
|
||||||
item.checked,
|
item.checked,
|
||||||
hasSubmenu
|
hasSubmenu
|
||||||
});
|
});
|
||||||
itemY += 34.0f;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1410,7 +1441,7 @@ void ScenarioApp::BuildDrawData(UIDrawData& drawData, float width, float height)
|
|||||||
shellRect.y,
|
shellRect.y,
|
||||||
width - shellRect.width - margin * 2.0f - 16.0f,
|
width - shellRect.width - margin * 2.0f - 16.0f,
|
||||||
height - 312.0f);
|
height - 312.0f);
|
||||||
const UIRect footerRect(margin, height - 100.0f, width - margin * 2.0f, 80.0f);
|
const UIRect footerRect(margin, height - 124.0f, width - margin * 2.0f, 104.0f);
|
||||||
|
|
||||||
DrawCard(
|
DrawCard(
|
||||||
drawList,
|
drawList,
|
||||||
@@ -1461,8 +1492,8 @@ void ScenarioApp::BuildDrawData(UIDrawData& drawData, float width, float height)
|
|||||||
drawList.AddText(UIPoint(stateRect.x + 18.0f, stateRect.y + 482.0f), "menu model validation", kTextMuted, 12.0f);
|
drawList.AddText(UIPoint(stateRect.x + 18.0f, stateRect.y + 482.0f), "menu model validation", kTextMuted, 12.0f);
|
||||||
drawList.AddText(UIPoint(stateRect.x + 18.0f, stateRect.y + 502.0f), menuValidation.IsValid() ? "OK" : menuValidation.message, menuValidation.IsValid() ? kSuccess : kDanger, 12.0f);
|
drawList.AddText(UIPoint(stateRect.x + 18.0f, stateRect.y + 502.0f), menuValidation.IsValid() ? "OK" : menuValidation.message, menuValidation.IsValid() ? kSuccess : kDanger, 12.0f);
|
||||||
|
|
||||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 28.0f), "Last interaction: " + m_lastActionName + " | Result: " + m_lastStatusLabel, m_lastStatusColor, 13.0f);
|
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 56.0f), "Last interaction: " + m_lastActionName + " | Result: " + m_lastStatusLabel, m_lastStatusColor, 13.0f);
|
||||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 48.0f), m_lastMessage, kTextPrimary, 12.0f);
|
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 74.0f), m_lastMessage, kTextPrimary, 12.0f);
|
||||||
|
|
||||||
const std::string captureSummary =
|
const std::string captureSummary =
|
||||||
m_autoScreenshot.HasPendingCapture()
|
m_autoScreenshot.HasPendingCapture()
|
||||||
@@ -1470,7 +1501,7 @@ void ScenarioApp::BuildDrawData(UIDrawData& drawData, float width, float height)
|
|||||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||||
? std::string("F12 -> tests/UI/Editor/integration/shell/menu_bar_basic/captures/")
|
? std::string("F12 -> tests/UI/Editor/integration/shell/menu_bar_basic/captures/")
|
||||||
: m_autoScreenshot.GetLastCaptureSummary());
|
: m_autoScreenshot.GetLastCaptureSummary());
|
||||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 66.0f), captureSummary, kTextMuted, 12.0f);
|
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 92.0f), captureSummary, kTextMuted, 12.0f);
|
||||||
|
|
||||||
DrawOpenPopups(drawList, resolvedModel, viewportRect);
|
DrawOpenPopups(drawList, resolvedModel, viewportRect);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
add_executable(editor_ui_status_bar_basic_validation WIN32
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(editor_ui_status_bar_basic_validation PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/new_editor/include
|
||||||
|
${CMAKE_SOURCE_DIR}/new_editor/app
|
||||||
|
${CMAKE_SOURCE_DIR}/engine/include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(editor_ui_status_bar_basic_validation PRIVATE
|
||||||
|
UNICODE
|
||||||
|
_UNICODE
|
||||||
|
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_compile_options(editor_ui_status_bar_basic_validation PRIVATE /utf-8 /FS)
|
||||||
|
set_property(TARGET editor_ui_status_bar_basic_validation PROPERTY
|
||||||
|
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(editor_ui_status_bar_basic_validation PRIVATE
|
||||||
|
XCUIEditorLib
|
||||||
|
XCUIEditorHost
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(editor_ui_status_bar_basic_validation PROPERTIES
|
||||||
|
OUTPUT_NAME "XCUIEditorStatusBarBasicValidation"
|
||||||
|
)
|
||||||
531
tests/UI/Editor/integration/shell/status_bar_basic/main.cpp
Normal file
531
tests/UI/Editor/integration/shell/status_bar_basic/main.cpp
Normal file
@@ -0,0 +1,531 @@
|
|||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <XCEditor/Widgets/UIEditorStatusBar.h>
|
||||||
|
#include "Host/AutoScreenshot.h"
|
||||||
|
#include "Host/NativeRenderer.h"
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||||
|
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using XCEngine::UI::UIColor;
|
||||||
|
using XCEngine::UI::UIDrawData;
|
||||||
|
using XCEngine::UI::UIDrawList;
|
||||||
|
using XCEngine::UI::UIPoint;
|
||||||
|
using XCEngine::UI::UIRect;
|
||||||
|
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||||
|
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorStatusBarBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorStatusBarForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorStatusBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::HitTestUIEditorStatusBar;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarHitTarget;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarHitTargetKind;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarInvalidIndex;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSegment;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSlot;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarState;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarTextTone;
|
||||||
|
|
||||||
|
constexpr const wchar_t* kWindowClassName = L"XCUIEditorStatusBarBasicValidation";
|
||||||
|
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | StatusBar Basic";
|
||||||
|
|
||||||
|
constexpr UIColor kWindowBg(0.13f, 0.13f, 0.13f, 1.0f);
|
||||||
|
constexpr UIColor kCardBg(0.18f, 0.18f, 0.18f, 1.0f);
|
||||||
|
constexpr UIColor kCardBorder(0.30f, 0.30f, 0.30f, 1.0f);
|
||||||
|
constexpr UIColor kCardAccent(0.82f, 0.82f, 0.82f, 1.0f);
|
||||||
|
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||||
|
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||||
|
constexpr UIColor kTextWeak(0.56f, 0.56f, 0.56f, 1.0f);
|
||||||
|
constexpr UIColor kButtonBg(0.26f, 0.26f, 0.26f, 1.0f);
|
||||||
|
constexpr UIColor kButtonOnBg(0.40f, 0.40f, 0.40f, 1.0f);
|
||||||
|
constexpr UIColor kButtonBorder(0.48f, 0.48f, 0.48f, 1.0f);
|
||||||
|
|
||||||
|
enum class ActionId : unsigned char {
|
||||||
|
ToggleAccent = 0,
|
||||||
|
ToggleSeparator,
|
||||||
|
MoveToTrailing,
|
||||||
|
Reset,
|
||||||
|
Capture
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ButtonState {
|
||||||
|
ActionId action = ActionId::ToggleAccent;
|
||||||
|
std::string label = {};
|
||||||
|
UIRect rect = {};
|
||||||
|
bool selected = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::filesystem::path ResolveRepoRootPath() {
|
||||||
|
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
|
||||||
|
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
|
||||||
|
root = root.substr(1u, root.size() - 2u);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::filesystem::path(root).lexically_normal();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ContainsPoint(const UIRect& rect, float x, float y) {
|
||||||
|
return x >= rect.x &&
|
||||||
|
x <= rect.x + rect.width &&
|
||||||
|
y >= rect.y &&
|
||||||
|
y <= rect.y + rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DescribeHitTarget(const UIEditorStatusBarHitTarget& hit) {
|
||||||
|
switch (hit.kind) {
|
||||||
|
case UIEditorStatusBarHitTargetKind::Segment:
|
||||||
|
return "Segment[" + std::to_string(hit.index) + "]";
|
||||||
|
case UIEditorStatusBarHitTargetKind::Separator:
|
||||||
|
return "Separator[" + std::to_string(hit.index) + "]";
|
||||||
|
case UIEditorStatusBarHitTargetKind::Background:
|
||||||
|
return "Background";
|
||||||
|
case UIEditorStatusBarHitTargetKind::None:
|
||||||
|
default:
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DescribeSlot(UIEditorStatusBarSlot slot) {
|
||||||
|
return slot == UIEditorStatusBarSlot::Leading ? "Leading" : "Trailing";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawCard(
|
||||||
|
UIDrawList& drawList,
|
||||||
|
const UIRect& rect,
|
||||||
|
std::string_view title,
|
||||||
|
std::string_view subtitle = {}) {
|
||||||
|
drawList.AddFilledRect(rect, kCardBg, 10.0f);
|
||||||
|
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 10.0f);
|
||||||
|
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 14.0f), std::string(title), kTextPrimary, 17.0f);
|
||||||
|
if (!subtitle.empty()) {
|
||||||
|
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 38.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawButton(UIDrawList& drawList, const ButtonState& button) {
|
||||||
|
drawList.AddFilledRect(button.rect, button.selected ? kButtonOnBg : kButtonBg, 8.0f);
|
||||||
|
drawList.AddRectOutline(button.rect, button.selected ? kCardAccent : kButtonBorder, 1.0f, 8.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(button.rect.x + 12.0f, button.rect.y + 10.0f),
|
||||||
|
button.label,
|
||||||
|
kTextPrimary,
|
||||||
|
12.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ScenarioApp {
|
||||||
|
public:
|
||||||
|
int Run(HINSTANCE hInstance, int nCmdShow) {
|
||||||
|
if (!Initialize(hInstance, nCmdShow)) {
|
||||||
|
Shutdown();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MSG message = {};
|
||||||
|
while (message.message != WM_QUIT) {
|
||||||
|
if (PeekMessageW(&message, nullptr, 0U, 0U, PM_REMOVE)) {
|
||||||
|
TranslateMessage(&message);
|
||||||
|
DispatchMessageW(&message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderFrame();
|
||||||
|
Sleep(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
Shutdown();
|
||||||
|
return static_cast<int>(message.wParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||||
|
if (message == WM_NCCREATE) {
|
||||||
|
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||||
|
auto* app = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||||
|
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||||
|
switch (message) {
|
||||||
|
case WM_SIZE:
|
||||||
|
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||||
|
app->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
case WM_MOUSEMOVE:
|
||||||
|
if (app != nullptr) {
|
||||||
|
app->HandleMouseMove(
|
||||||
|
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||||
|
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_MOUSELEAVE:
|
||||||
|
if (app != nullptr) {
|
||||||
|
app->HandleMouseLeave();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
if (app != nullptr) {
|
||||||
|
app->HandleClick(
|
||||||
|
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||||
|
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
case WM_SYSKEYDOWN:
|
||||||
|
if (app != nullptr && wParam == VK_F12) {
|
||||||
|
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||||
|
InvalidateRect(hwnd, nullptr, FALSE);
|
||||||
|
UpdateWindow(hwnd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_PAINT:
|
||||||
|
if (app != nullptr) {
|
||||||
|
PAINTSTRUCT paintStruct = {};
|
||||||
|
BeginPaint(hwnd, &paintStruct);
|
||||||
|
app->RenderFrame();
|
||||||
|
EndPaint(hwnd, &paintStruct);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WM_ERASEBKGND:
|
||||||
|
return 1;
|
||||||
|
case WM_DESTROY:
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||||
|
m_captureRoot =
|
||||||
|
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/status_bar_basic/captures";
|
||||||
|
m_autoScreenshot.Initialize(m_captureRoot);
|
||||||
|
|
||||||
|
WNDCLASSEXW windowClass = {};
|
||||||
|
windowClass.cbSize = sizeof(windowClass);
|
||||||
|
windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
windowClass.lpfnWndProc = &ScenarioApp::WndProc;
|
||||||
|
windowClass.hInstance = hInstance;
|
||||||
|
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
||||||
|
windowClass.lpszClassName = kWindowClassName;
|
||||||
|
|
||||||
|
m_windowClassAtom = RegisterClassExW(&windowClass);
|
||||||
|
if (m_windowClassAtom == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_hwnd = CreateWindowExW(
|
||||||
|
0,
|
||||||
|
kWindowClassName,
|
||||||
|
kWindowTitle,
|
||||||
|
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
1440,
|
||||||
|
920,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
hInstance,
|
||||||
|
this);
|
||||||
|
if (m_hwnd == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_renderer.Initialize(m_hwnd)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowWindow(m_hwnd, nCmdShow);
|
||||||
|
|
||||||
|
ResetState();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shutdown() {
|
||||||
|
m_autoScreenshot.Shutdown();
|
||||||
|
m_renderer.Shutdown();
|
||||||
|
|
||||||
|
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
|
||||||
|
DestroyWindow(m_hwnd);
|
||||||
|
}
|
||||||
|
m_hwnd = nullptr;
|
||||||
|
|
||||||
|
if (m_windowClassAtom != 0) {
|
||||||
|
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
|
||||||
|
m_windowClassAtom = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnResize(UINT width, UINT height) {
|
||||||
|
m_renderer.Resize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleMouseMove(float x, float y) {
|
||||||
|
m_mousePosition = UIPoint(x, y);
|
||||||
|
TRACKMOUSEEVENT event = {};
|
||||||
|
event.cbSize = sizeof(event);
|
||||||
|
event.dwFlags = TME_LEAVE;
|
||||||
|
event.hwndTrack = m_hwnd;
|
||||||
|
TrackMouseEvent(&event);
|
||||||
|
UpdateHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleMouseLeave() {
|
||||||
|
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||||
|
m_state.hoveredIndex = UIEditorStatusBarInvalidIndex;
|
||||||
|
m_hoverTarget = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleClick(float x, float y) {
|
||||||
|
for (const ButtonState& button : m_buttons) {
|
||||||
|
if (ContainsPoint(button.rect, x, y)) {
|
||||||
|
ExecuteAction(button.action);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_hoverTarget = HitTestUIEditorStatusBar(m_layout, UIPoint(x, y));
|
||||||
|
if (m_hoverTarget.kind == UIEditorStatusBarHitTargetKind::Segment) {
|
||||||
|
m_state.activeIndex = m_hoverTarget.index;
|
||||||
|
m_state.focused = true;
|
||||||
|
m_lastResult = "激活 segment: " + m_segments[m_hoverTarget.index].segmentId;
|
||||||
|
} else if (m_hoverTarget.kind == UIEditorStatusBarHitTargetKind::Background) {
|
||||||
|
m_state.activeIndex = UIEditorStatusBarInvalidIndex;
|
||||||
|
m_lastResult = "点击 status bar background";
|
||||||
|
} else {
|
||||||
|
m_lastResult = "命中 " + DescribeHitTarget(m_hoverTarget);
|
||||||
|
}
|
||||||
|
UpdateHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExecuteAction(ActionId action) {
|
||||||
|
switch (action) {
|
||||||
|
case ActionId::ToggleAccent:
|
||||||
|
m_segments[1].tone =
|
||||||
|
m_segments[1].tone == UIEditorStatusBarTextTone::Accent
|
||||||
|
? UIEditorStatusBarTextTone::Primary
|
||||||
|
: UIEditorStatusBarTextTone::Accent;
|
||||||
|
m_lastResult = "切换 Selection 文本强调";
|
||||||
|
break;
|
||||||
|
case ActionId::ToggleSeparator:
|
||||||
|
m_segments[0].showSeparator = !m_segments[0].showSeparator;
|
||||||
|
m_lastResult = m_segments[0].showSeparator ? "开启 Leading separator" : "关闭 Leading separator";
|
||||||
|
break;
|
||||||
|
case ActionId::MoveToTrailing:
|
||||||
|
m_segments[1].slot =
|
||||||
|
m_segments[1].slot == UIEditorStatusBarSlot::Leading
|
||||||
|
? UIEditorStatusBarSlot::Trailing
|
||||||
|
: UIEditorStatusBarSlot::Leading;
|
||||||
|
m_lastResult = "切换 Selection slot -> " + DescribeSlot(m_segments[1].slot);
|
||||||
|
break;
|
||||||
|
case ActionId::Reset:
|
||||||
|
ResetState();
|
||||||
|
m_lastResult = "状态重置";
|
||||||
|
break;
|
||||||
|
case ActionId::Capture:
|
||||||
|
m_autoScreenshot.RequestCapture("manual_button");
|
||||||
|
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||||
|
UpdateWindow(m_hwnd);
|
||||||
|
m_lastResult = "截图已排队";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UpdateHover();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetState() {
|
||||||
|
m_segments = {
|
||||||
|
{ "scene", "Scene: Main", UIEditorStatusBarSlot::Leading, UIEditorStatusBarTextTone::Primary, true, true, 96.0f },
|
||||||
|
{ "selection", "Selection: Camera", UIEditorStatusBarSlot::Leading, UIEditorStatusBarTextTone::Accent, true, false, 140.0f },
|
||||||
|
{ "frame", "16.7 ms", UIEditorStatusBarSlot::Trailing, UIEditorStatusBarTextTone::Muted, true, true, 64.0f },
|
||||||
|
{ "gpu", "GPU Ready", UIEditorStatusBarSlot::Trailing, UIEditorStatusBarTextTone::Primary, true, false, 86.0f }
|
||||||
|
};
|
||||||
|
m_state = {};
|
||||||
|
m_state.focused = true;
|
||||||
|
m_state.activeIndex = 1u;
|
||||||
|
m_hoverTarget = {};
|
||||||
|
m_lastResult = "Ready";
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateHover() {
|
||||||
|
m_hoverTarget = HitTestUIEditorStatusBar(m_layout, m_mousePosition);
|
||||||
|
m_state.hoveredIndex =
|
||||||
|
m_hoverTarget.kind == UIEditorStatusBarHitTargetKind::Segment
|
||||||
|
? m_hoverTarget.index
|
||||||
|
: UIEditorStatusBarInvalidIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildButtons(float left, float top, float width) {
|
||||||
|
const float buttonHeight = 34.0f;
|
||||||
|
const float gap = 10.0f;
|
||||||
|
m_buttons = {
|
||||||
|
{ ActionId::ToggleAccent, "强调文本", UIRect(left, top, width, buttonHeight), m_segments[1].tone == UIEditorStatusBarTextTone::Accent },
|
||||||
|
{ ActionId::ToggleSeparator, "Leading 分隔线", UIRect(left, top + (buttonHeight + gap), width, buttonHeight), m_segments[0].showSeparator },
|
||||||
|
{ ActionId::MoveToTrailing, "切换 Selection Slot", UIRect(left, top + (buttonHeight + gap) * 2.0f, width, buttonHeight), m_segments[1].slot == UIEditorStatusBarSlot::Trailing },
|
||||||
|
{ ActionId::Reset, "Reset", UIRect(left, top + (buttonHeight + gap) * 3.0f, width, buttonHeight), false },
|
||||||
|
{ ActionId::Capture, "截图", UIRect(left, top + (buttonHeight + gap) * 4.0f, width, buttonHeight), false }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderFrame() {
|
||||||
|
RECT clientRect = {};
|
||||||
|
GetClientRect(m_hwnd, &clientRect);
|
||||||
|
const float width = static_cast<float>((std::max)(1L, clientRect.right - clientRect.left));
|
||||||
|
const float height = static_cast<float>((std::max)(1L, clientRect.bottom - clientRect.top));
|
||||||
|
|
||||||
|
const float leftColumnWidth = 340.0f;
|
||||||
|
const float outerPadding = 20.0f;
|
||||||
|
const UIRect introRect(outerPadding, outerPadding, leftColumnWidth, 156.0f);
|
||||||
|
const UIRect controlsRect(outerPadding, 196.0f, leftColumnWidth, 276.0f);
|
||||||
|
const UIRect stateRect(outerPadding, 492.0f, leftColumnWidth, 244.0f);
|
||||||
|
const UIRect previewRect(
|
||||||
|
leftColumnWidth + outerPadding * 2.0f,
|
||||||
|
outerPadding,
|
||||||
|
width - leftColumnWidth - outerPadding * 3.0f,
|
||||||
|
height - outerPadding * 2.0f);
|
||||||
|
const UIRect viewportRect(
|
||||||
|
previewRect.x,
|
||||||
|
previewRect.y,
|
||||||
|
previewRect.width,
|
||||||
|
previewRect.height - 28.0f);
|
||||||
|
const UIRect statusBarRect(
|
||||||
|
previewRect.x,
|
||||||
|
previewRect.y + previewRect.height - 28.0f,
|
||||||
|
previewRect.width,
|
||||||
|
28.0f);
|
||||||
|
|
||||||
|
BuildButtons(controlsRect.x + 16.0f, controlsRect.y + 54.0f, controlsRect.width - 32.0f);
|
||||||
|
m_layout = BuildUIEditorStatusBarLayout(statusBarRect, m_segments);
|
||||||
|
UpdateHover();
|
||||||
|
|
||||||
|
UIDrawData drawData = {};
|
||||||
|
UIDrawList& drawList = drawData.EmplaceDrawList("StatusBarBasic");
|
||||||
|
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||||
|
|
||||||
|
DrawCard(
|
||||||
|
drawList,
|
||||||
|
introRect,
|
||||||
|
"测试功能:StatusBar 基础壳层",
|
||||||
|
"重点检查:Leading / Trailing slot 对齐,文本强调,separator 开关,hover / active 命中。");
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(introRect.x + 16.0f, introRect.y + 66.0f),
|
||||||
|
"操作:hover 观察 segment 高亮;点击 segment 切 active;切换左侧按钮检查 slot / separator / emphasis;按 F12 或点“截图”。",
|
||||||
|
kTextMuted,
|
||||||
|
12.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(introRect.x + 16.0f, introRect.y + 90.0f),
|
||||||
|
"这个场景只验证 Editor 基础层 StatusBar,不混入任何业务面板。",
|
||||||
|
kTextWeak,
|
||||||
|
12.0f);
|
||||||
|
|
||||||
|
DrawCard(drawList, controlsRect, "开关", "只保留和当前 StatusBar contract 直接相关的操作。");
|
||||||
|
for (const ButtonState& button : m_buttons) {
|
||||||
|
DrawButton(drawList, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawCard(drawList, stateRect, "状态", "命中、active、slot 和结果统一回显在这里。");
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 66.0f),
|
||||||
|
"Hover: " + DescribeHitTarget(m_hoverTarget),
|
||||||
|
kTextPrimary,
|
||||||
|
13.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 92.0f),
|
||||||
|
"Active: " + (m_state.activeIndex == UIEditorStatusBarInvalidIndex ? std::string("None") : m_segments[m_state.activeIndex].segmentId),
|
||||||
|
kTextPrimary,
|
||||||
|
13.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 118.0f),
|
||||||
|
"Selection Slot: " + DescribeSlot(m_segments[1].slot),
|
||||||
|
kTextPrimary,
|
||||||
|
13.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 144.0f),
|
||||||
|
std::string("Leading Separator: ") + (m_segments[0].showSeparator ? "On" : "Off"),
|
||||||
|
kTextPrimary,
|
||||||
|
13.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 170.0f),
|
||||||
|
"Result: " + m_lastResult,
|
||||||
|
kTextMuted,
|
||||||
|
12.0f);
|
||||||
|
const std::string captureSummary =
|
||||||
|
m_autoScreenshot.HasPendingCapture()
|
||||||
|
? "截图排队中..."
|
||||||
|
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||||
|
? std::string("截图: F12 或按钮 -> status_bar_basic/captures/")
|
||||||
|
: m_autoScreenshot.GetLastCaptureSummary());
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(stateRect.x + 16.0f, stateRect.y + 196.0f),
|
||||||
|
captureSummary,
|
||||||
|
kTextWeak,
|
||||||
|
12.0f);
|
||||||
|
|
||||||
|
drawList.AddFilledRect(viewportRect, UIColor(0.17f, 0.17f, 0.17f, 1.0f), 10.0f);
|
||||||
|
drawList.AddRectOutline(viewportRect, kCardBorder, 1.0f, 10.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(viewportRect.x + 18.0f, viewportRect.y + 18.0f),
|
||||||
|
"Preview Host",
|
||||||
|
kTextPrimary,
|
||||||
|
18.0f);
|
||||||
|
drawList.AddText(
|
||||||
|
UIPoint(viewportRect.x + 18.0f, viewportRect.y + 48.0f),
|
||||||
|
"这里只保留一个空白宿主区域,专门看底部 StatusBar 的对齐和交互。",
|
||||||
|
kTextMuted,
|
||||||
|
12.0f);
|
||||||
|
|
||||||
|
AppendUIEditorStatusBarBackground(drawList, m_layout, m_segments, m_state);
|
||||||
|
AppendUIEditorStatusBarForeground(drawList, m_layout, m_segments, m_state);
|
||||||
|
|
||||||
|
const bool framePresented = m_renderer.Render(drawData);
|
||||||
|
m_autoScreenshot.CaptureIfRequested(
|
||||||
|
m_renderer,
|
||||||
|
drawData,
|
||||||
|
static_cast<unsigned int>(width),
|
||||||
|
static_cast<unsigned int>(height),
|
||||||
|
framePresented);
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND m_hwnd = nullptr;
|
||||||
|
ATOM m_windowClassAtom = 0;
|
||||||
|
NativeRenderer m_renderer = {};
|
||||||
|
AutoScreenshotController m_autoScreenshot = {};
|
||||||
|
std::filesystem::path m_captureRoot = {};
|
||||||
|
std::vector<ButtonState> m_buttons = {};
|
||||||
|
std::vector<UIEditorStatusBarSegment> m_segments = {};
|
||||||
|
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
|
||||||
|
UIEditorStatusBarState m_state = {};
|
||||||
|
UIEditorStatusBarLayout m_layout = {};
|
||||||
|
UIEditorStatusBarHitTarget m_hoverTarget = {};
|
||||||
|
std::string m_lastResult = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||||
|
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||||
|
}
|
||||||
@@ -6,11 +6,14 @@ set(EDITOR_UI_UNIT_TEST_SOURCES
|
|||||||
test_ui_editor_command_registry.cpp
|
test_ui_editor_command_registry.cpp
|
||||||
test_ui_editor_menu_model.cpp
|
test_ui_editor_menu_model.cpp
|
||||||
test_ui_editor_menu_session.cpp
|
test_ui_editor_menu_session.cpp
|
||||||
|
test_ui_editor_menu_bar.cpp
|
||||||
|
test_ui_editor_menu_popup.cpp
|
||||||
test_ui_editor_panel_registry.cpp
|
test_ui_editor_panel_registry.cpp
|
||||||
test_ui_editor_collection_primitives.cpp
|
test_ui_editor_collection_primitives.cpp
|
||||||
test_ui_editor_dock_host.cpp
|
test_ui_editor_dock_host.cpp
|
||||||
test_ui_editor_panel_chrome.cpp
|
test_ui_editor_panel_chrome.cpp
|
||||||
test_ui_editor_panel_frame.cpp
|
test_ui_editor_panel_frame.cpp
|
||||||
|
test_ui_editor_status_bar.cpp
|
||||||
test_ui_editor_tab_strip.cpp
|
test_ui_editor_tab_strip.cpp
|
||||||
test_ui_editor_shortcut_manager.cpp
|
test_ui_editor_shortcut_manager.cpp
|
||||||
test_ui_editor_workspace_controller.cpp
|
test_ui_editor_workspace_controller.cpp
|
||||||
|
|||||||
117
tests/UI/Editor/unit/test_ui_editor_menu_bar.cpp
Normal file
117
tests/UI/Editor/unit/test_ui_editor_menu_bar.cpp
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
#include <XCEditor/Widgets/UIEditorMenuBar.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using XCEngine::UI::UIDrawCommandType;
|
||||||
|
using XCEngine::UI::UIDrawList;
|
||||||
|
using XCEngine::UI::UIPoint;
|
||||||
|
using XCEngine::UI::UIRect;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuBarBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuBarForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorMenuBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::HitTestUIEditorMenuBar;
|
||||||
|
using XCEngine::UI::Editor::Widgets::ResolveUIEditorMenuBarDesiredButtonWidth;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarHitTargetKind;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarInvalidIndex;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarItem;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuBarState;
|
||||||
|
|
||||||
|
TEST(UIEditorMenuBarTest, DesiredWidthUsesLabelEstimateAndHorizontalPadding) {
|
||||||
|
XCEngine::UI::Editor::Widgets::UIEditorMenuBarMetrics metrics = {};
|
||||||
|
metrics.estimatedGlyphWidth = 8.0f;
|
||||||
|
metrics.buttonPaddingX = 12.0f;
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(
|
||||||
|
ResolveUIEditorMenuBarDesiredButtonWidth(
|
||||||
|
UIEditorMenuBarItem{ "file", "File", true, 0.0f },
|
||||||
|
metrics),
|
||||||
|
56.0f);
|
||||||
|
EXPECT_FLOAT_EQ(
|
||||||
|
ResolveUIEditorMenuBarDesiredButtonWidth(
|
||||||
|
UIEditorMenuBarItem{ "window", "Window", true, 50.0f },
|
||||||
|
metrics),
|
||||||
|
74.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuBarTest, LayoutBuildsHorizontalButtonsInsideBarInsets) {
|
||||||
|
XCEngine::UI::Editor::Widgets::UIEditorMenuBarMetrics metrics = {};
|
||||||
|
metrics.horizontalInset = 8.0f;
|
||||||
|
metrics.verticalInset = 3.0f;
|
||||||
|
metrics.buttonGap = 4.0f;
|
||||||
|
metrics.buttonPaddingX = 10.0f;
|
||||||
|
metrics.estimatedGlyphWidth = 8.0f;
|
||||||
|
|
||||||
|
const std::vector<UIEditorMenuBarItem> items = {
|
||||||
|
{ "file", "File", true, 0.0f },
|
||||||
|
{ "window", "Window", true, 32.0f }
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto layout =
|
||||||
|
BuildUIEditorMenuBarLayout(UIRect(10.0f, 20.0f, 240.0f, 32.0f), items, metrics);
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.x, 18.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.y, 23.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.width, 224.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.height, 26.0f);
|
||||||
|
|
||||||
|
ASSERT_EQ(layout.buttonRects.size(), 2u);
|
||||||
|
EXPECT_FLOAT_EQ(layout.buttonRects[0].x, 18.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.buttonRects[0].width, 52.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.buttonRects[1].x, 74.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.buttonRects[1].width, 52.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuBarTest, HitTestResolvesButtonBeforeBarBackground) {
|
||||||
|
const std::vector<UIEditorMenuBarItem> items = {
|
||||||
|
{ "file", "File", true, 0.0f },
|
||||||
|
{ "window", "Window", true, 32.0f }
|
||||||
|
};
|
||||||
|
const auto layout =
|
||||||
|
BuildUIEditorMenuBarLayout(UIRect(10.0f, 20.0f, 240.0f, 32.0f), items);
|
||||||
|
|
||||||
|
const auto buttonHit = HitTestUIEditorMenuBar(layout, UIPoint(30.0f, 32.0f));
|
||||||
|
EXPECT_EQ(buttonHit.kind, UIEditorMenuBarHitTargetKind::Button);
|
||||||
|
EXPECT_EQ(buttonHit.index, 0u);
|
||||||
|
|
||||||
|
const auto backgroundHit = HitTestUIEditorMenuBar(layout, UIPoint(220.0f, 32.0f));
|
||||||
|
EXPECT_EQ(backgroundHit.kind, UIEditorMenuBarHitTargetKind::BarBackground);
|
||||||
|
EXPECT_EQ(backgroundHit.index, UIEditorMenuBarInvalidIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuBarTest, BackgroundAndForegroundEmitStableCommands) {
|
||||||
|
const std::vector<UIEditorMenuBarItem> items = {
|
||||||
|
{ "file", "File", true, 0.0f },
|
||||||
|
{ "window", "Window", false, 32.0f }
|
||||||
|
};
|
||||||
|
|
||||||
|
UIEditorMenuBarState state = {};
|
||||||
|
state.openIndex = 0u;
|
||||||
|
state.hoveredIndex = 1u;
|
||||||
|
state.focused = true;
|
||||||
|
const auto layout =
|
||||||
|
BuildUIEditorMenuBarLayout(UIRect(10.0f, 20.0f, 240.0f, 32.0f), items);
|
||||||
|
|
||||||
|
UIDrawList background("MenuBarBackground");
|
||||||
|
AppendUIEditorMenuBarBackground(background, layout, items, state);
|
||||||
|
ASSERT_EQ(background.GetCommandCount(), 6u);
|
||||||
|
const auto& backgroundCommands = background.GetCommands();
|
||||||
|
EXPECT_EQ(backgroundCommands[0].type, UIDrawCommandType::FilledRect);
|
||||||
|
EXPECT_EQ(backgroundCommands[1].type, UIDrawCommandType::RectOutline);
|
||||||
|
EXPECT_EQ(backgroundCommands[2].type, UIDrawCommandType::FilledRect);
|
||||||
|
EXPECT_EQ(backgroundCommands[5].type, UIDrawCommandType::RectOutline);
|
||||||
|
|
||||||
|
UIDrawList foreground("MenuBarForeground");
|
||||||
|
AppendUIEditorMenuBarForeground(foreground, layout, items, state);
|
||||||
|
ASSERT_EQ(foreground.GetCommandCount(), 6u);
|
||||||
|
const auto& foregroundCommands = foreground.GetCommands();
|
||||||
|
EXPECT_EQ(foregroundCommands[0].type, UIDrawCommandType::PushClipRect);
|
||||||
|
EXPECT_EQ(foregroundCommands[1].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[1].text, "File");
|
||||||
|
EXPECT_EQ(foregroundCommands[4].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[4].text, "Window");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
136
tests/UI/Editor/unit/test_ui_editor_menu_popup.cpp
Normal file
136
tests/UI/Editor/unit/test_ui_editor_menu_popup.cpp
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
#include <XCEditor/Widgets/UIEditorMenuPopup.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using XCEngine::UI::UIDrawCommandType;
|
||||||
|
using XCEngine::UI::UIDrawList;
|
||||||
|
using XCEngine::UI::UIPoint;
|
||||||
|
using XCEngine::UI::UIRect;
|
||||||
|
using XCEngine::UI::Editor::UIEditorMenuItemKind;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuPopupBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorMenuPopupForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorMenuPopupLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::HitTestUIEditorMenuPopup;
|
||||||
|
using XCEngine::UI::Editor::Widgets::MeasureUIEditorMenuPopupHeight;
|
||||||
|
using XCEngine::UI::Editor::Widgets::ResolveUIEditorMenuPopupDesiredWidth;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuPopupHitTargetKind;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuPopupInvalidIndex;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuPopupItem;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorMenuPopupState;
|
||||||
|
|
||||||
|
std::vector<UIEditorMenuPopupItem> BuildItems() {
|
||||||
|
return {
|
||||||
|
{ "show-inspector", UIEditorMenuItemKind::Command, "Show Inspector", "Ctrl+I", true, true, false, 0.0f, 0.0f },
|
||||||
|
{ "separator-1", UIEditorMenuItemKind::Separator, {}, {}, false, false, false, 0.0f, 0.0f },
|
||||||
|
{ "layout", UIEditorMenuItemKind::Submenu, "Layout", {}, true, false, true, 0.0f, 0.0f },
|
||||||
|
{ "close", UIEditorMenuItemKind::Command, "Close", "Ctrl+W", false, false, false, 0.0f, 0.0f }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST(UIEditorMenuPopupTest, DesiredWidthAndHeightUseLabelShortcutAndSeparatorMetrics) {
|
||||||
|
XCEngine::UI::Editor::Widgets::UIEditorMenuPopupMetrics metrics = {};
|
||||||
|
metrics.contentPaddingX = 8.0f;
|
||||||
|
metrics.contentPaddingY = 5.0f;
|
||||||
|
metrics.labelInsetX = 12.0f;
|
||||||
|
metrics.checkColumnWidth = 20.0f;
|
||||||
|
metrics.shortcutGap = 18.0f;
|
||||||
|
metrics.shortcutInsetRight = 22.0f;
|
||||||
|
metrics.submenuIndicatorWidth = 14.0f;
|
||||||
|
metrics.estimatedGlyphWidth = 8.0f;
|
||||||
|
metrics.itemHeight = 30.0f;
|
||||||
|
metrics.separatorHeight = 10.0f;
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(
|
||||||
|
ResolveUIEditorMenuPopupDesiredWidth(BuildItems(), metrics),
|
||||||
|
248.0f);
|
||||||
|
EXPECT_FLOAT_EQ(
|
||||||
|
MeasureUIEditorMenuPopupHeight(BuildItems(), metrics),
|
||||||
|
110.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuPopupTest, LayoutBuildsStackedRowsAndSeparatorSlots) {
|
||||||
|
XCEngine::UI::Editor::Widgets::UIEditorMenuPopupMetrics metrics = {};
|
||||||
|
metrics.contentPaddingX = 6.0f;
|
||||||
|
metrics.contentPaddingY = 4.0f;
|
||||||
|
metrics.itemHeight = 26.0f;
|
||||||
|
metrics.separatorHeight = 8.0f;
|
||||||
|
|
||||||
|
const auto layout = BuildUIEditorMenuPopupLayout(
|
||||||
|
UIRect(100.0f, 50.0f, 220.0f, 94.0f),
|
||||||
|
BuildItems(),
|
||||||
|
metrics);
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.x, 106.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.y, 54.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.width, 208.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.contentRect.height, 86.0f);
|
||||||
|
|
||||||
|
ASSERT_EQ(layout.itemRects.size(), 4u);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[0].y, 54.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[0].height, 26.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[1].y, 80.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[1].height, 8.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[2].y, 88.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.itemRects[3].y, 114.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuPopupTest, HitTestIgnoresSeparatorsAndFallsBackToPopupSurface) {
|
||||||
|
const auto items = BuildItems();
|
||||||
|
const auto layout = BuildUIEditorMenuPopupLayout(
|
||||||
|
UIRect(100.0f, 50.0f, 220.0f, 118.0f),
|
||||||
|
items);
|
||||||
|
|
||||||
|
const auto itemHit = HitTestUIEditorMenuPopup(layout, items, UIPoint(130.0f, 66.0f));
|
||||||
|
EXPECT_EQ(itemHit.kind, UIEditorMenuPopupHitTargetKind::Item);
|
||||||
|
EXPECT_EQ(itemHit.index, 0u);
|
||||||
|
|
||||||
|
const auto separatorHit = HitTestUIEditorMenuPopup(layout, items, UIPoint(130.0f, 88.0f));
|
||||||
|
EXPECT_EQ(separatorHit.kind, UIEditorMenuPopupHitTargetKind::PopupSurface);
|
||||||
|
EXPECT_EQ(separatorHit.index, UIEditorMenuPopupInvalidIndex);
|
||||||
|
|
||||||
|
const auto outsideHit = HitTestUIEditorMenuPopup(layout, items, UIPoint(20.0f, 20.0f));
|
||||||
|
EXPECT_EQ(outsideHit.kind, UIEditorMenuPopupHitTargetKind::None);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuPopupTest, BackgroundAndForegroundEmitStableCommands) {
|
||||||
|
const auto items = BuildItems();
|
||||||
|
UIEditorMenuPopupState state = {};
|
||||||
|
state.hoveredIndex = 0u;
|
||||||
|
state.submenuOpenIndex = 2u;
|
||||||
|
const auto layout = BuildUIEditorMenuPopupLayout(
|
||||||
|
UIRect(100.0f, 50.0f, 220.0f, 118.0f),
|
||||||
|
items);
|
||||||
|
|
||||||
|
UIDrawList background("MenuPopupBackground");
|
||||||
|
AppendUIEditorMenuPopupBackground(background, layout, items, state);
|
||||||
|
ASSERT_EQ(background.GetCommandCount(), 5u);
|
||||||
|
const auto& backgroundCommands = background.GetCommands();
|
||||||
|
EXPECT_EQ(backgroundCommands[0].type, UIDrawCommandType::FilledRect);
|
||||||
|
EXPECT_EQ(backgroundCommands[1].type, UIDrawCommandType::RectOutline);
|
||||||
|
EXPECT_EQ(backgroundCommands[2].type, UIDrawCommandType::FilledRect);
|
||||||
|
EXPECT_EQ(backgroundCommands[4].type, UIDrawCommandType::FilledRect);
|
||||||
|
|
||||||
|
UIDrawList foreground("MenuPopupForeground");
|
||||||
|
AppendUIEditorMenuPopupForeground(foreground, layout, items, state);
|
||||||
|
ASSERT_EQ(foreground.GetCommandCount(), 13u);
|
||||||
|
const auto& foregroundCommands = foreground.GetCommands();
|
||||||
|
EXPECT_EQ(foregroundCommands[0].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[0].text, "*");
|
||||||
|
EXPECT_EQ(foregroundCommands[2].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[2].text, "Show Inspector");
|
||||||
|
EXPECT_EQ(foregroundCommands[4].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[4].text, "Ctrl+I");
|
||||||
|
EXPECT_EQ(foregroundCommands[6].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[6].text, "Layout");
|
||||||
|
EXPECT_EQ(foregroundCommands[8].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[8].text, ">");
|
||||||
|
EXPECT_EQ(foregroundCommands[10].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[10].text, "Close");
|
||||||
|
EXPECT_EQ(foregroundCommands[12].type, UIDrawCommandType::Text);
|
||||||
|
EXPECT_EQ(foregroundCommands[12].text, "Ctrl+W");
|
||||||
|
}
|
||||||
@@ -73,6 +73,45 @@ TEST(UIEditorMenuSessionTest, OpenMenuBarRootTracksActiveMenuAndRootPopup) {
|
|||||||
EXPECT_TRUE(session.GetOpenSubmenuItemIds().empty());
|
EXPECT_TRUE(session.GetOpenSubmenuItemIds().empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuSessionTest, OpenRootMenuSupportsGenericRootPopupEntry) {
|
||||||
|
UIEditorMenuSession session = {};
|
||||||
|
|
||||||
|
const auto result = session.OpenRootMenu(
|
||||||
|
"context.scene",
|
||||||
|
MakePopup("menu.context.scene.root", "", UIInputPath{500u, 510u}, UIInputPath{5u, 6u}));
|
||||||
|
|
||||||
|
EXPECT_TRUE(result.changed);
|
||||||
|
EXPECT_EQ(result.openRootMenuId, "context.scene");
|
||||||
|
EXPECT_EQ(result.openedPopupId, "menu.context.scene.root");
|
||||||
|
EXPECT_TRUE(result.closedPopupIds.empty());
|
||||||
|
EXPECT_TRUE(session.IsMenuOpen("context.scene"));
|
||||||
|
EXPECT_TRUE(session.IsPopupOpen("menu.context.scene.root"));
|
||||||
|
ASSERT_EQ(session.GetPopupOverlayModel().GetPopupCount(), 1u);
|
||||||
|
ASSERT_EQ(session.GetPopupStates().size(), 1u);
|
||||||
|
EXPECT_TRUE(session.GetPopupStates().front().IsRootPopup());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorMenuSessionTest, OpenRootMenuRepositionsPopupWhenAnchorChanges) {
|
||||||
|
UIEditorMenuSession session = {};
|
||||||
|
ASSERT_TRUE(session.OpenRootMenu(
|
||||||
|
"context.scene",
|
||||||
|
MakePopup("menu.context.scene.root", "", UIInputPath{500u, 510u}, UIInputPath{5u, 6u}))
|
||||||
|
.changed);
|
||||||
|
|
||||||
|
UIPopupOverlayEntry movedPopup =
|
||||||
|
MakePopup("menu.context.scene.root", "", UIInputPath{500u, 510u}, UIInputPath{5u, 6u});
|
||||||
|
movedPopup.anchorRect = { 320.0f, 180.0f, 1.0f, 1.0f };
|
||||||
|
|
||||||
|
const auto result = session.OpenRootMenu("context.scene", movedPopup);
|
||||||
|
|
||||||
|
EXPECT_TRUE(result.changed);
|
||||||
|
EXPECT_EQ(result.openRootMenuId, "context.scene");
|
||||||
|
EXPECT_EQ(result.openedPopupId, "menu.context.scene.root");
|
||||||
|
ASSERT_NE(session.GetPopupOverlayModel().GetRootPopup(), nullptr);
|
||||||
|
EXPECT_FLOAT_EQ(session.GetPopupOverlayModel().GetRootPopup()->anchorRect.x, 320.0f);
|
||||||
|
EXPECT_FLOAT_EQ(session.GetPopupOverlayModel().GetRootPopup()->anchorRect.y, 180.0f);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(UIEditorMenuSessionTest, HoverMenuBarRootReplacesOpenRootAndClearsSubmenuPath) {
|
TEST(UIEditorMenuSessionTest, HoverMenuBarRootReplacesOpenRootAndClearsSubmenuPath) {
|
||||||
UIEditorMenuSession session = {};
|
UIEditorMenuSession session = {};
|
||||||
ASSERT_TRUE(session.OpenMenuBarRoot(
|
ASSERT_TRUE(session.OpenMenuBarRoot(
|
||||||
|
|||||||
120
tests/UI/Editor/unit/test_ui_editor_status_bar.cpp
Normal file
120
tests/UI/Editor/unit/test_ui_editor_status_bar.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <XCEngine/UI/DrawData.h>
|
||||||
|
#include <XCEditor/Widgets/UIEditorStatusBar.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
using XCEngine::UI::UIColor;
|
||||||
|
using XCEngine::UI::UIDrawCommandType;
|
||||||
|
using XCEngine::UI::UIDrawList;
|
||||||
|
using XCEngine::UI::UIPoint;
|
||||||
|
using XCEngine::UI::UIRect;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorStatusBarBackground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::AppendUIEditorStatusBarForeground;
|
||||||
|
using XCEngine::UI::Editor::Widgets::BuildUIEditorStatusBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::HitTestUIEditorStatusBar;
|
||||||
|
using XCEngine::UI::Editor::Widgets::ResolveUIEditorStatusBarDesiredSegmentWidth;
|
||||||
|
using XCEngine::UI::Editor::Widgets::ResolveUIEditorStatusBarTextColor;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarHitTargetKind;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarInvalidIndex;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarLayout;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarPalette;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSegment;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSlot;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarState;
|
||||||
|
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarTextTone;
|
||||||
|
|
||||||
|
void ExpectColorEq(const UIColor& actual, const UIColor& expected) {
|
||||||
|
EXPECT_FLOAT_EQ(actual.r, expected.r);
|
||||||
|
EXPECT_FLOAT_EQ(actual.g, expected.g);
|
||||||
|
EXPECT_FLOAT_EQ(actual.b, expected.b);
|
||||||
|
EXPECT_FLOAT_EQ(actual.a, expected.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<UIEditorStatusBarSegment> BuildSegments() {
|
||||||
|
return {
|
||||||
|
{ "scene", "Scene: Main", UIEditorStatusBarSlot::Leading, UIEditorStatusBarTextTone::Primary, true, true, 92.0f },
|
||||||
|
{ "selection", "Selection: Camera", UIEditorStatusBarSlot::Leading, UIEditorStatusBarTextTone::Accent, true, false, 138.0f },
|
||||||
|
{ "frame", "16.7 ms", UIEditorStatusBarSlot::Trailing, UIEditorStatusBarTextTone::Muted, true, true, 64.0f },
|
||||||
|
{ "gpu", "GPU Ready", UIEditorStatusBarSlot::Trailing, UIEditorStatusBarTextTone::Primary, true, false, 86.0f }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorStatusBarTest, DesiredWidthUsesExplicitValueBeforeLabelEstimate) {
|
||||||
|
UIEditorStatusBarSegment explicitWidth = {};
|
||||||
|
explicitWidth.label = "Scene";
|
||||||
|
explicitWidth.desiredWidth = 84.0f;
|
||||||
|
|
||||||
|
UIEditorStatusBarSegment inferredWidth = {};
|
||||||
|
inferredWidth.label = "Scene";
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(ResolveUIEditorStatusBarDesiredSegmentWidth(explicitWidth), 84.0f);
|
||||||
|
EXPECT_FLOAT_EQ(ResolveUIEditorStatusBarDesiredSegmentWidth(inferredWidth), 55.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorStatusBarTest, LayoutBuildsLeadingAndTrailingSlotsWithSeparators) {
|
||||||
|
const UIEditorStatusBarLayout layout =
|
||||||
|
BuildUIEditorStatusBarLayout(UIRect(20.0f, 40.0f, 520.0f, 28.0f), BuildSegments());
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(layout.leadingSlotRect.x, 30.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.leadingSlotRect.width, 235.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.trailingSlotRect.x, 371.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.trailingSlotRect.width, 159.0f);
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(layout.segmentRects[0].x, 30.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.segmentRects[1].x, 127.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.segmentRects[2].x, 371.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.segmentRects[3].x, 444.0f);
|
||||||
|
|
||||||
|
EXPECT_FLOAT_EQ(layout.separatorRects[0].x, 122.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.separatorRects[2].x, 439.0f);
|
||||||
|
EXPECT_FLOAT_EQ(layout.separatorRects[1].width, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorStatusBarTest, HitTestReturnsSeparatorThenSegmentThenBackground) {
|
||||||
|
const UIEditorStatusBarLayout layout =
|
||||||
|
BuildUIEditorStatusBarLayout(UIRect(20.0f, 40.0f, 520.0f, 28.0f), BuildSegments());
|
||||||
|
|
||||||
|
auto hit = HitTestUIEditorStatusBar(layout, UIPoint(122.5f, 54.0f));
|
||||||
|
EXPECT_EQ(hit.kind, UIEditorStatusBarHitTargetKind::Separator);
|
||||||
|
EXPECT_EQ(hit.index, 0u);
|
||||||
|
|
||||||
|
hit = HitTestUIEditorStatusBar(layout, UIPoint(150.0f, 54.0f));
|
||||||
|
EXPECT_EQ(hit.kind, UIEditorStatusBarHitTargetKind::Segment);
|
||||||
|
EXPECT_EQ(hit.index, 1u);
|
||||||
|
|
||||||
|
hit = HitTestUIEditorStatusBar(layout, UIPoint(300.0f, 54.0f));
|
||||||
|
EXPECT_EQ(hit.kind, UIEditorStatusBarHitTargetKind::Background);
|
||||||
|
EXPECT_EQ(hit.index, UIEditorStatusBarInvalidIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UIEditorStatusBarTest, BackgroundAndForegroundEmitStableChromeAndTextCommands) {
|
||||||
|
const auto segments = BuildSegments();
|
||||||
|
UIEditorStatusBarState state = {};
|
||||||
|
state.hoveredIndex = 0u;
|
||||||
|
state.activeIndex = 1u;
|
||||||
|
state.focused = true;
|
||||||
|
|
||||||
|
const UIEditorStatusBarPalette palette = {};
|
||||||
|
const UIEditorStatusBarLayout layout =
|
||||||
|
BuildUIEditorStatusBarLayout(UIRect(12.0f, 16.0f, 520.0f, 28.0f), segments);
|
||||||
|
|
||||||
|
UIDrawList background("StatusBarBackground");
|
||||||
|
AppendUIEditorStatusBarBackground(background, layout, segments, state, palette);
|
||||||
|
ASSERT_EQ(background.GetCommandCount(), 8u);
|
||||||
|
EXPECT_EQ(background.GetCommands()[0].type, UIDrawCommandType::FilledRect);
|
||||||
|
EXPECT_EQ(background.GetCommands()[1].type, UIDrawCommandType::RectOutline);
|
||||||
|
ExpectColorEq(background.GetCommands()[1].color, palette.focusedBorderColor);
|
||||||
|
|
||||||
|
UIDrawList foreground("StatusBarForeground");
|
||||||
|
AppendUIEditorStatusBarForeground(foreground, layout, segments, state, palette);
|
||||||
|
ASSERT_EQ(foreground.GetCommandCount(), 4u);
|
||||||
|
EXPECT_EQ(foreground.GetCommands()[0].text, "Scene: Main");
|
||||||
|
EXPECT_EQ(foreground.GetCommands()[1].text, "Selection: Camera");
|
||||||
|
ExpectColorEq(
|
||||||
|
foreground.GetCommands()[1].color,
|
||||||
|
ResolveUIEditorStatusBarTextColor(UIEditorStatusBarTextTone::Accent, palette));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
Reference in New Issue
Block a user