182 lines
6.7 KiB
C++
182 lines
6.7 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
#include <XCEngine/UI/Layout/UITabStripLayout.h>
|
|
#include <XCEngine/UI/Widgets/UITabStripModel.h>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace XCEngine::UI::Editor::Widgets {
|
|
|
|
inline constexpr std::size_t UIEditorTabStripInvalidIndex =
|
|
::XCEngine::UI::Widgets::UITabStripModel::InvalidIndex;
|
|
|
|
struct UIEditorTabStripItem {
|
|
std::string tabId = {};
|
|
std::string title = {};
|
|
bool closable = true;
|
|
float desiredHeaderLabelWidth = 0.0f;
|
|
};
|
|
|
|
struct UIEditorTabStripReorderState {
|
|
::XCEngine::UI::UIPoint pressPosition = {};
|
|
std::size_t pressedIndex = UIEditorTabStripInvalidIndex;
|
|
std::size_t sourceIndex = UIEditorTabStripInvalidIndex;
|
|
std::size_t previewInsertionIndex = UIEditorTabStripInvalidIndex;
|
|
bool armed = false;
|
|
bool dragging = false;
|
|
};
|
|
|
|
struct UIEditorTabStripState {
|
|
std::size_t selectedIndex = UIEditorTabStripInvalidIndex;
|
|
std::size_t hoveredIndex = UIEditorTabStripInvalidIndex;
|
|
std::size_t closeHoveredIndex = UIEditorTabStripInvalidIndex;
|
|
bool focused = false;
|
|
UIEditorTabStripReorderState reorder = {};
|
|
};
|
|
|
|
struct UIEditorTabStripMetrics {
|
|
::XCEngine::UI::Layout::UITabStripMetrics layoutMetrics =
|
|
::XCEngine::UI::Layout::UITabStripMetrics{ 22.0f, 68.0f, 8.0f, 1.0f };
|
|
float estimatedGlyphWidth = 6.0f;
|
|
float closeButtonExtent = 10.0f;
|
|
float closeButtonGap = 4.0f;
|
|
float closeInsetRight = 6.0f;
|
|
float closeInsetY = 0.0f;
|
|
float labelInsetX = 8.0f;
|
|
float labelInsetY = -0.5f;
|
|
float baseBorderThickness = 1.0f;
|
|
float selectedBorderThickness = 1.0f;
|
|
float focusedBorderThickness = 1.0f;
|
|
float reorderDragThreshold = 6.0f;
|
|
float reorderPreviewThickness = 2.0f;
|
|
float reorderPreviewInsetY = 3.0f;
|
|
};
|
|
|
|
struct UIEditorTabStripPalette {
|
|
::XCEngine::UI::UIColor stripBackgroundColor =
|
|
::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
::XCEngine::UI::UIColor headerBackgroundColor =
|
|
::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
::XCEngine::UI::UIColor contentBackgroundColor =
|
|
::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
::XCEngine::UI::UIColor stripBorderColor =
|
|
::XCEngine::UI::UIColor(0.24f, 0.24f, 0.24f, 1.0f);
|
|
::XCEngine::UI::UIColor headerContentSeparatorColor =
|
|
::XCEngine::UI::UIColor(0.27f, 0.27f, 0.27f, 1.0f);
|
|
::XCEngine::UI::UIColor focusedBorderColor =
|
|
::XCEngine::UI::UIColor(0.36f, 0.36f, 0.36f, 1.0f);
|
|
::XCEngine::UI::UIColor tabColor =
|
|
::XCEngine::UI::UIColor(0.20f, 0.20f, 0.20f, 1.0f);
|
|
::XCEngine::UI::UIColor tabHoveredColor =
|
|
::XCEngine::UI::UIColor(0.23f, 0.23f, 0.23f, 1.0f);
|
|
::XCEngine::UI::UIColor tabSelectedColor =
|
|
::XCEngine::UI::UIColor(0.18f, 0.18f, 0.18f, 1.0f);
|
|
::XCEngine::UI::UIColor tabBorderColor =
|
|
::XCEngine::UI::UIColor(0.24f, 0.24f, 0.24f, 1.0f);
|
|
::XCEngine::UI::UIColor tabHoveredBorderColor =
|
|
::XCEngine::UI::UIColor(0.31f, 0.31f, 0.31f, 1.0f);
|
|
::XCEngine::UI::UIColor tabSelectedBorderColor =
|
|
::XCEngine::UI::UIColor(0.34f, 0.34f, 0.34f, 1.0f);
|
|
::XCEngine::UI::UIColor textPrimary =
|
|
::XCEngine::UI::UIColor(0.86f, 0.86f, 0.86f, 1.0f);
|
|
::XCEngine::UI::UIColor textSecondary =
|
|
::XCEngine::UI::UIColor(0.67f, 0.67f, 0.67f, 1.0f);
|
|
::XCEngine::UI::UIColor textMuted =
|
|
::XCEngine::UI::UIColor(0.58f, 0.58f, 0.58f, 1.0f);
|
|
::XCEngine::UI::UIColor closeButtonColor =
|
|
::XCEngine::UI::UIColor(0.20f, 0.20f, 0.20f, 1.0f);
|
|
::XCEngine::UI::UIColor closeButtonHoveredColor =
|
|
::XCEngine::UI::UIColor(0.25f, 0.25f, 0.25f, 1.0f);
|
|
::XCEngine::UI::UIColor closeButtonBorderColor =
|
|
::XCEngine::UI::UIColor(0.30f, 0.30f, 0.30f, 1.0f);
|
|
::XCEngine::UI::UIColor closeGlyphColor =
|
|
::XCEngine::UI::UIColor(0.83f, 0.83f, 0.83f, 1.0f);
|
|
::XCEngine::UI::UIColor reorderPreviewColor =
|
|
::XCEngine::UI::UIColor(0.82f, 0.82f, 0.82f, 1.0f);
|
|
};
|
|
|
|
struct UIEditorTabStripInsertionPreview {
|
|
bool visible = false;
|
|
std::size_t insertionIndex = UIEditorTabStripInvalidIndex;
|
|
::XCEngine::UI::UIRect indicatorRect = {};
|
|
};
|
|
|
|
struct UIEditorTabStripLayout {
|
|
::XCEngine::UI::UIRect bounds = {};
|
|
::XCEngine::UI::UIRect headerRect = {};
|
|
::XCEngine::UI::UIRect contentRect = {};
|
|
std::vector<::XCEngine::UI::UIRect> tabHeaderRects = {};
|
|
std::vector<::XCEngine::UI::UIRect> closeButtonRects = {};
|
|
std::vector<bool> showCloseButtons = {};
|
|
std::size_t selectedIndex = UIEditorTabStripInvalidIndex;
|
|
UIEditorTabStripInsertionPreview insertionPreview = {};
|
|
};
|
|
|
|
enum class UIEditorTabStripHitTargetKind : std::uint8_t {
|
|
None = 0,
|
|
HeaderBackground,
|
|
Tab,
|
|
CloseButton,
|
|
Content
|
|
};
|
|
|
|
struct UIEditorTabStripHitTarget {
|
|
UIEditorTabStripHitTargetKind kind = UIEditorTabStripHitTargetKind::None;
|
|
std::size_t index = UIEditorTabStripInvalidIndex;
|
|
};
|
|
|
|
float ResolveUIEditorTabStripDesiredHeaderLabelWidth(
|
|
const UIEditorTabStripItem& item,
|
|
const UIEditorTabStripMetrics& metrics = {});
|
|
|
|
std::size_t ResolveUIEditorTabStripSelectedIndex(
|
|
const std::vector<UIEditorTabStripItem>& items,
|
|
std::string_view selectedTabId,
|
|
std::size_t fallbackIndex = UIEditorTabStripInvalidIndex);
|
|
|
|
std::size_t ResolveUIEditorTabStripSelectedIndexAfterClose(
|
|
std::size_t selectedIndex,
|
|
std::size_t closedIndex,
|
|
std::size_t itemCountBeforeClose);
|
|
|
|
UIEditorTabStripLayout BuildUIEditorTabStripLayout(
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
const std::vector<UIEditorTabStripItem>& items,
|
|
const UIEditorTabStripState& state,
|
|
const UIEditorTabStripMetrics& metrics = {});
|
|
|
|
UIEditorTabStripHitTarget HitTestUIEditorTabStrip(
|
|
const UIEditorTabStripLayout& layout,
|
|
const UIEditorTabStripState& state,
|
|
const ::XCEngine::UI::UIPoint& point);
|
|
|
|
void AppendUIEditorTabStripBackground(
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
const UIEditorTabStripLayout& layout,
|
|
const UIEditorTabStripState& state,
|
|
const UIEditorTabStripPalette& palette = {},
|
|
const UIEditorTabStripMetrics& metrics = {});
|
|
|
|
void AppendUIEditorTabStripForeground(
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
const UIEditorTabStripLayout& layout,
|
|
const std::vector<UIEditorTabStripItem>& items,
|
|
const UIEditorTabStripState& state,
|
|
const UIEditorTabStripPalette& palette = {},
|
|
const UIEditorTabStripMetrics& metrics = {});
|
|
|
|
void AppendUIEditorTabStrip(
|
|
::XCEngine::UI::UIDrawList& drawList,
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
const std::vector<UIEditorTabStripItem>& items,
|
|
const UIEditorTabStripState& state,
|
|
const UIEditorTabStripPalette& palette = {},
|
|
const UIEditorTabStripMetrics& metrics = {});
|
|
|
|
} // namespace XCEngine::UI::Editor::Widgets
|