Initial UI implementation by AI
This commit is contained in:
1 parent
f2a3f59ab1
commit
908b52441f
29 files changed
+884
-186
No files matched your search
+126
-78
@@ -1,108 +1,156 @@
|
||||
#pragma once
|
||||
#include "UI/Style/Style.h"
|
||||
#include "UI/Style/Theme.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/FontAsset.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "Style.h"
|
||||
#include <string_view>
|
||||
|
||||
namespace Seele {
|
||||
template <typename C>
|
||||
concept StyleClass = requires(C c, UI::Style& s) { c.apply(s); };
|
||||
namespace UI {
|
||||
// a style class is anything with a static apply(Style&, const Theme&)
|
||||
template <typename C> concept StyleClass = requires(Style& s, const Theme& t) { C::apply(s, t); };
|
||||
|
||||
template <uint32 w, UI::DimensionType widthType> struct WidthClass {
|
||||
static void apply(UI::Style& s) {
|
||||
// --- size ---
|
||||
template <uint32 w, DimensionType widthType> struct WidthClass {
|
||||
static void apply(Style& s, const Theme&) {
|
||||
s.width = w;
|
||||
s.widthType = widthType;
|
||||
}
|
||||
};
|
||||
using W_Full = WidthClass<100, UI::DimensionType::Percent>;
|
||||
using W_1 = WidthClass<2, UI::DimensionType::Pixel>;
|
||||
using W_Full = WidthClass<100, DimensionType::Percent>;
|
||||
template <uint32 h> struct HeightClass {
|
||||
static void apply(Style& s, const Theme&) {
|
||||
s.height = h;
|
||||
s.heightType = DimensionType::Pixel;
|
||||
}
|
||||
};
|
||||
using H_Full = HeightClass<100>;
|
||||
|
||||
template <UI::OuterDisplayType outer, UI::InnerDisplayType inner> struct DisplayClass {
|
||||
static void apply(UI::Style& s) {
|
||||
// --- display ---
|
||||
template <OuterDisplayType outer, InnerDisplayType inner> struct DisplayClass {
|
||||
static void apply(Style& s, const Theme&) {
|
||||
s.outerDisplay = outer;
|
||||
s.innerDisplay = inner;
|
||||
}
|
||||
};
|
||||
using Hidden = DisplayClass<UI::OuterDisplayType::Hidden, UI::InnerDisplayType::Flow>;
|
||||
using Block = DisplayClass<UI::OuterDisplayType::Block, UI::InnerDisplayType::Flow>;
|
||||
using Inline = DisplayClass<UI::OuterDisplayType::Inline, UI::InnerDisplayType::Flow>;
|
||||
using Hidden = DisplayClass<OuterDisplayType::Hidden, InnerDisplayType::Flow>;
|
||||
using Block = DisplayClass<OuterDisplayType::Block, InnerDisplayType::Flow>;
|
||||
using Inline = DisplayClass<OuterDisplayType::Inline, InnerDisplayType::Flow>;
|
||||
|
||||
template <size_t N> struct StringLiteral {
|
||||
constexpr StringLiteral(const char (&str)[N]) { std::copy_n(str, N, value); }
|
||||
|
||||
char value[N];
|
||||
};
|
||||
template <StringLiteral lit> struct FontClass {
|
||||
static void apply(UI::Style& s) { s.fontFamily = AssetRegistry::findFont("", lit.value); }
|
||||
};
|
||||
|
||||
using Font_Arial = FontClass<"arial">;
|
||||
using Font_Calibri = FontClass<"Calibri">;
|
||||
// --- fonts (looked up at style() time; fonts must be loaded before the first
|
||||
// System::style() call, see the invariant in System.h) ---
|
||||
// a string literal can't be a C++ template argument, so font *names* are carried
|
||||
// as runtime data on Style::fontName by a font class tag (e.g. UI::Font_Arial in
|
||||
// Fonts.h); Text::applyStyle resolves the name to a PFontAsset (Theme::defaultFont
|
||||
// as fallback). the font scale below is what remains a pure static class.
|
||||
|
||||
// tailwind text scale: (fontSize, lineHeight) in px, scaled by Theme at style() time
|
||||
template <uint32 fontSize, uint32 lineHeight> struct FontSizeClass {
|
||||
static void apply(UI::Style& s) {
|
||||
s.fontSize = fontSize;
|
||||
s.lineHeight = lineHeight;
|
||||
static void apply(Style& s, const Theme& t) {
|
||||
s.fontSize = t.font(fontSize);
|
||||
s.lineHeight = t.font(lineHeight);
|
||||
}
|
||||
};
|
||||
|
||||
using Text_XS = FontSizeClass<12, 16>;
|
||||
using Text_SM = FontSizeClass<14, 20>;
|
||||
using Text_Base = FontSizeClass<16, 24>;
|
||||
using Text_LG = FontSizeClass<18, 28>;
|
||||
using Text_XL = FontSizeClass<20, 28>;
|
||||
using Text_2XL = FontSizeClass<24, 32>;
|
||||
using Text_3XL = FontSizeClass<30, 36>;
|
||||
using Text_4XL = FontSizeClass<36, 40>;
|
||||
using Text_5XL = FontSizeClass<48, 48>;
|
||||
using Text_6XL = FontSizeClass<60, 60>;
|
||||
using Text_7XL = FontSizeClass<72, 72>;
|
||||
using Text_8XL = FontSizeClass<96, 96>;
|
||||
using Text_9XL = FontSizeClass<128, 128>;
|
||||
|
||||
template <Vector backgroundColor> struct BackgroundColorClass {
|
||||
static void apply(UI::Style& s) { s.backgroundColor = backgroundColor; }
|
||||
template <ColorToken token> struct BackgroundColorClass {
|
||||
static void apply(Style& s, const Theme& t) { s.backgroundColor = t.color(token); }
|
||||
};
|
||||
template <ColorToken token> struct TextColorClass {
|
||||
static void apply(Style& s, const Theme& t) { s.textColor = t.color(token); }
|
||||
};
|
||||
using BG_White = BackgroundColorClass<ColorToken::White>;
|
||||
using BG_Gray950 = BackgroundColorClass<ColorToken::Gray950>;
|
||||
using BG_Gray900 = BackgroundColorClass<ColorToken::Gray900>;
|
||||
using BG_Gray800 = BackgroundColorClass<ColorToken::Gray800>;
|
||||
using BG_Gray700 = BackgroundColorClass<ColorToken::Gray700>;
|
||||
using BG_Gray600 = BackgroundColorClass<ColorToken::Gray600>;
|
||||
using BG_Red = BackgroundColorClass<ColorToken::Red>;
|
||||
using BG_Green = BackgroundColorClass<ColorToken::Green>;
|
||||
using BG_Blue = BackgroundColorClass<ColorToken::Blue>;
|
||||
using BG_Amber = BackgroundColorClass<ColorToken::Amber>;
|
||||
using C_White = TextColorClass<ColorToken::White>;
|
||||
using C_Gray400 = TextColorClass<ColorToken::Gray400>;
|
||||
using C_Gray500 = TextColorClass<ColorToken::Gray500>;
|
||||
using C_Red = TextColorClass<ColorToken::Red>;
|
||||
using C_Green = TextColorClass<ColorToken::Green>;
|
||||
using C_Blue = TextColorClass<ColorToken::Blue>;
|
||||
|
||||
using BG_Red = BackgroundColorClass<Vector(1, 0, 0)>;
|
||||
|
||||
// --- spacing (themed: scaled by Theme::spacingScale for DPI/accessibility) ---
|
||||
// a side left as ~0U (4294967295) is left untouched
|
||||
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
|
||||
static void apply(UI::Style& s) {
|
||||
if constexpr (ml != -1)
|
||||
s.marginLeft = ml;
|
||||
if constexpr (mr != -1)
|
||||
s.marginRight = mr;
|
||||
if constexpr (mt != -1)
|
||||
s.marginTop = mt;
|
||||
if constexpr (mb != -1)
|
||||
s.marginBottom = mb;
|
||||
static void apply(Style& s, const Theme& t) {
|
||||
if constexpr (ml != ~0U)
|
||||
s.marginLeft = t.spacing(ml);
|
||||
if constexpr (mr != ~0U)
|
||||
s.marginRight = t.spacing(mr);
|
||||
if constexpr (mt != ~0U)
|
||||
s.marginTop = t.spacing(mt);
|
||||
if constexpr (mb != ~0U)
|
||||
s.marginBottom = t.spacing(mb);
|
||||
}
|
||||
};
|
||||
#define DECLARE_MARGIN_CLASSES(x) \
|
||||
using M_##x = MarginClass<x, x, x, x>; \
|
||||
using M_X##x = MarginClass<x, x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_Y##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, x>; \
|
||||
using M_L##x = MarginClass<x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_R##x = MarginClass<std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max()>; \
|
||||
using M_T##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x, std::numeric_limits<uint32>::max()>; \
|
||||
using M_B##x = MarginClass<std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), std::numeric_limits<uint32>::max(), x>;
|
||||
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct PaddingClass {
|
||||
static void apply(Style& s, const Theme& t) {
|
||||
if constexpr (ml != ~0U)
|
||||
s.paddingLeft = t.spacing(ml);
|
||||
if constexpr (mr != ~0U)
|
||||
s.paddingRight = t.spacing(mr);
|
||||
if constexpr (mt != ~0U)
|
||||
s.paddingTop = t.spacing(mt);
|
||||
if constexpr (mb != ~0U)
|
||||
s.paddingBottom = t.spacing(mb);
|
||||
}
|
||||
};
|
||||
template <uint32 g> struct GapClass {
|
||||
static void apply(Style& s, const Theme& t) { s.gap = t.spacing(g); }
|
||||
};
|
||||
|
||||
DECLARE_MARGIN_CLASSES(0)
|
||||
DECLARE_MARGIN_CLASSES(1)
|
||||
DECLARE_MARGIN_CLASSES(2)
|
||||
DECLARE_MARGIN_CLASSES(3)
|
||||
DECLARE_MARGIN_CLASSES(4)
|
||||
DECLARE_MARGIN_CLASSES(5)
|
||||
DECLARE_MARGIN_CLASSES(6)
|
||||
DECLARE_MARGIN_CLASSES(7)
|
||||
DECLARE_MARGIN_CLASSES(8)
|
||||
DECLARE_MARGIN_CLASSES(9)
|
||||
DECLARE_MARGIN_CLASSES(10)
|
||||
DECLARE_MARGIN_CLASSES(11)
|
||||
DECLARE_MARGIN_CLASSES(12)
|
||||
DECLARE_MARGIN_CLASSES(14)
|
||||
DECLARE_MARGIN_CLASSES(16)
|
||||
DECLARE_MARGIN_CLASSES(20)
|
||||
DECLARE_MARGIN_CLASSES(24)
|
||||
// curated tailwind spacing scale (px @ scale 1.0).
|
||||
// intermediate steps: declare a local MarginClass<N,...>/PaddingClass<N,...> alias
|
||||
// in your own namespace — StyleClass is a concept, not a closed set.
|
||||
#define SPACE(n) \
|
||||
using M_##n = MarginClass<n, n, n, n>; \
|
||||
using P_##n = PaddingClass<n, n, n, n>; \
|
||||
using M_X##n = MarginClass<n, n, ~0U, ~0U>; \
|
||||
using M_Y##n = MarginClass<~0U, ~0U, n, n>; \
|
||||
using P_X##n = PaddingClass<n, n, ~0U, ~0U>; \
|
||||
using P_Y##n = PaddingClass<~0U, ~0U, n, n>; \
|
||||
using G_##n = GapClass<n>;
|
||||
|
||||
SPACE(0)
|
||||
SPACE(1)
|
||||
SPACE(2)
|
||||
SPACE(4)
|
||||
SPACE(6)
|
||||
SPACE(8)
|
||||
SPACE(10)
|
||||
SPACE(12)
|
||||
SPACE(16)
|
||||
SPACE(20)
|
||||
SPACE(24)
|
||||
SPACE(32)
|
||||
SPACE(40)
|
||||
SPACE(48)
|
||||
SPACE(64)
|
||||
SPACE(80)
|
||||
|
||||
// tailwind text scale: (fontSize, lineHeight) @ scale 1.0.
|
||||
// names must be valid identifiers (no leading digit), and the macro body ends in ';'
|
||||
// or the next token gets glued to the using-declaration.
|
||||
#define TEXT_STEP(name, size, line) using Text_##name = FontSizeClass<size, line>;
|
||||
TEXT_STEP(XS, 12, 16)
|
||||
TEXT_STEP(SM, 14, 20)
|
||||
TEXT_STEP(BASE, 16, 24)
|
||||
TEXT_STEP(LG, 18, 28)
|
||||
TEXT_STEP(XL, 20, 28)
|
||||
TEXT_STEP(XXL, 24, 32)
|
||||
TEXT_STEP(3XL, 30, 36)
|
||||
TEXT_STEP(4XL, 36, 40)
|
||||
TEXT_STEP(5XL, 48, 48)
|
||||
TEXT_STEP(6XL, 60, 60)
|
||||
TEXT_STEP(7XL, 72, 72)
|
||||
TEXT_STEP(8XL, 96, 96)
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
Reference in new issue
Block a user