More text changes
This commit is contained in:
@@ -14,6 +14,7 @@ struct UIRender {
|
||||
Vector backgroundColor;
|
||||
Vector2 position;
|
||||
Vector2 dimensions;
|
||||
uint32 baseline;
|
||||
uint32 z;
|
||||
uint32 level;
|
||||
};
|
||||
@@ -45,14 +46,14 @@ class Element {
|
||||
dimensions.x = parentSize.x * style.width / 100.0f;
|
||||
}
|
||||
|
||||
for (auto& child : children) {
|
||||
child->layout(maxDimensions - Vector2(style.marginLeft + style.marginRight, style.marginTop + style.marginBottom));
|
||||
}
|
||||
if (style.heightType == DimensionType::Pixel) {
|
||||
dimensions.y = style.height;
|
||||
} else if (style.heightType == DimensionType::Percent) {
|
||||
dimensions.y = parentSize.y * style.height / 100.0f;
|
||||
}
|
||||
for (auto& child : children) {
|
||||
child->layout(maxDimensions);
|
||||
}
|
||||
switch (style.innerDisplay) {
|
||||
case InnerDisplayType::Flow:
|
||||
flowLayout();
|
||||
@@ -71,15 +72,15 @@ class Element {
|
||||
if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) {
|
||||
// create a new line in case the element doesnt fit on the current one anymore,
|
||||
// but keep in current line in case we are still at the start, as a new line wouldnt help here
|
||||
if (cursor.x + child->dimensions.x > dimensions.x - child->style.left && cursor.x != 0) {
|
||||
if (cursor.x + child->dimensions.x > maxDimensions.x - child->style.left && cursor.x != 0) {
|
||||
cursor.x = 0;
|
||||
cursor.y += lineHeight;
|
||||
lineHeight = 0;
|
||||
}
|
||||
// todo: border
|
||||
child->position.x = cursor.x + child->style.marginLeft;
|
||||
child->position.y = cursor.y + child->style.marginTop;
|
||||
cursor.x = child->position.x + child->dimensions.x;
|
||||
cursor.y = child->position.y + child->dimensions.y;
|
||||
// apply offsets after updating the cursor for relative elements
|
||||
if (child->style.position == PositionType::Relative) {
|
||||
child->position.x += child->style.left;
|
||||
@@ -108,7 +109,7 @@ class Element {
|
||||
dimensions.x = cursor.x + style.paddingRight;
|
||||
}
|
||||
if (style.heightType == DimensionType::Auto) {
|
||||
dimensions.y = cursor.y + style.paddingBottom;
|
||||
dimensions.y = lineHeight + cursor.y + style.paddingBottom;
|
||||
}
|
||||
}
|
||||
virtual Array<UIRender> render(Vector2 anchor, uint32 level) {
|
||||
|
||||
@@ -12,8 +12,6 @@ class Div : public Element {
|
||||
virtual void applyStyle(Style parentStyle) override {
|
||||
style = parentStyle;
|
||||
style.outerDisplay = OuterDisplayType::Block;
|
||||
style.widthType = DimensionType::Percent;
|
||||
style.width = 100;
|
||||
(classes::apply(style), ...);
|
||||
}
|
||||
private:
|
||||
|
||||
@@ -15,9 +15,9 @@ template <StyleClass... classes> class Text : public Element {
|
||||
virtual void layout(UVector2 parentSize) override {
|
||||
size_t cursor = 0;
|
||||
for (uint32 i = 0; i < text.size() - 1; ++i) {
|
||||
dimensions.x += style.fontFamily->getGlyphData(text[i]).advance / 64.0f;
|
||||
dimensions.x += style.fontFamily->getGlyphData(text[i], style.fontSize).advance / 64.0f;
|
||||
}
|
||||
dimensions.x += style.fontFamily->getGlyphData(text[text.size() - 1]).size.x;
|
||||
dimensions.x += style.fontFamily->getGlyphData(text[text.size() - 1], style.fontSize).size.x;
|
||||
dimensions.y = style.fontSize;
|
||||
}
|
||||
virtual Array<UIRender> render(Vector2 anchor, uint32 level) override {
|
||||
@@ -28,6 +28,7 @@ template <StyleClass... classes> class Text : public Element {
|
||||
.fontSize = style.fontSize,
|
||||
.position = position + anchor,
|
||||
.dimensions = dimensions,
|
||||
.baseline = style.fontSize * 3 / 4, // TODO: improve
|
||||
.z = style.z,
|
||||
.level = level,
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "Style.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
|
||||
namespace Seele {
|
||||
template <typename C>
|
||||
@@ -36,10 +36,73 @@ template <StringLiteral lit> struct FontClass {
|
||||
};
|
||||
|
||||
using Font_Arial = FontClass<"arial">;
|
||||
using Font_Calibri = FontClass<"Calibri">;
|
||||
|
||||
template <uint32 fontSize, uint32 lineHeight> struct FontSizeClass {
|
||||
static void apply(UI::Style& s) {
|
||||
s.fontSize = fontSize;
|
||||
s.lineHeight = 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; }
|
||||
};
|
||||
|
||||
using BG_Red = BackgroundColorClass<Vector(1, 0, 0)>;
|
||||
|
||||
template <uint32 ml, uint32 mr, uint32 mt, uint32 mb> struct MarginClass {
|
||||
static void apply(UI::Style& s) {
|
||||
if (ml != -1)
|
||||
s.marginLeft = ml;
|
||||
if (mr != -1)
|
||||
s.marginRight = mr;
|
||||
if (mt != -1)
|
||||
s.marginTop = mt;
|
||||
if (mb != -1)
|
||||
s.marginBottom = mb;
|
||||
}
|
||||
};
|
||||
#define DECLARE_MARGIN_CLASSES(x) \
|
||||
using M_##x = MarginClass<x, x, x, x>; \
|
||||
using M_X##x = MarginClass<x, x, -1, -1>; \
|
||||
using M_Y##x = MarginClass<-1, -1, x, x>; \
|
||||
using M_L##x = MarginClass<x, -1, -1, -1>; \
|
||||
using M_R##x = MarginClass<-1, x, -1, -1>; \
|
||||
using M_T##x = MarginClass<-1, -1, x, -1>; \
|
||||
using M_B##x = MarginClass<-1, -1, -1, x>;
|
||||
|
||||
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)
|
||||
|
||||
|
||||
} // namespace Seele
|
||||
@@ -39,10 +39,10 @@ struct Style {
|
||||
Vector backgroundColor = Vector(1, 1, 1);
|
||||
OuterDisplayType outerDisplay = OuterDisplayType::Inline;
|
||||
InnerDisplayType innerDisplay = InnerDisplayType::Flow;
|
||||
PositionType position = PositionType::Relative;
|
||||
PositionType position = PositionType::Static;
|
||||
PFontAsset fontFamily;
|
||||
uint32 lineHeight = 48;
|
||||
uint32 fontSize = 48;
|
||||
uint32 lineHeight = 12;
|
||||
uint32 fontSize = 12;
|
||||
uint32 fontWeight = 0;
|
||||
uint32 paddingTop = 0;
|
||||
uint32 paddingBottom = 0;
|
||||
|
||||
Reference in New Issue
Block a user