various UI and rt changes
This commit is contained in:
+7
-11
@@ -7,14 +7,10 @@
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
struct UIRender {
|
||||
std::string text;
|
||||
PFontAsset font;
|
||||
uint32 fontSize;
|
||||
Vector textColor;
|
||||
Gfx::PTexture2D backgroundTexture;
|
||||
Vector backgroundColor;
|
||||
Vector2 position;
|
||||
Vector2 dimensions;
|
||||
uint32 baseline;
|
||||
uint32 z;
|
||||
uint32 level;
|
||||
};
|
||||
@@ -45,15 +41,15 @@ class Element {
|
||||
} else if (style.widthType == DimensionType::Percent) {
|
||||
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 - Vector2(style.marginLeft + style.marginRight, style.marginTop + style.marginBottom));
|
||||
}
|
||||
switch (style.innerDisplay) {
|
||||
case InnerDisplayType::Flow:
|
||||
flowLayout();
|
||||
@@ -73,7 +69,7 @@ class Element {
|
||||
// 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 > maxDimensions.x - child->style.left && cursor.x != 0) {
|
||||
cursor.x = 0;
|
||||
cursor.x = style.paddingLeft;
|
||||
cursor.y += lineHeight;
|
||||
lineHeight = 0;
|
||||
}
|
||||
@@ -94,7 +90,7 @@ class Element {
|
||||
if (child->style.position == PositionType::Static || child->style.position == PositionType::Relative) {
|
||||
// create a new line in case we are not already at one
|
||||
if (cursor.x != 0) {
|
||||
cursor.x = 0;
|
||||
cursor.x = style.paddingLeft;
|
||||
cursor.y += lineHeight;
|
||||
}
|
||||
child->position.x = cursor.x + child->style.marginLeft;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "UI/Element.h"
|
||||
#include "UI/Style/Class.h"
|
||||
#include <ranges>
|
||||
|
||||
namespace Seele {
|
||||
namespace UI {
|
||||
@@ -13,31 +14,24 @@ template <StyleClass... classes> class Text : public Element {
|
||||
(classes::apply(style), ...);
|
||||
}
|
||||
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], style.fontSize).advance / 64.0f;
|
||||
}
|
||||
dimensions.x += style.fontFamily->getGlyphData(text[text.size() - 1], style.fontSize).size.x;
|
||||
dimensions.y = style.fontSize;
|
||||
UVector2 cursor = UVector2(0);
|
||||
dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders);
|
||||
}
|
||||
virtual Array<UIRender> render(Vector2 anchor, uint32 level) override {
|
||||
return {
|
||||
UIRender{
|
||||
.text = text,
|
||||
.font = style.fontFamily,
|
||||
.fontSize = style.fontSize,
|
||||
.position = position + anchor,
|
||||
.dimensions = dimensions,
|
||||
.baseline = style.fontSize * 3 / 4, // TODO: improve
|
||||
.z = style.z,
|
||||
.level = level,
|
||||
},
|
||||
};
|
||||
return Array<UIRender>(std::from_range, glyphRenders | std::views::transform([=](const FontAsset::RenderGlyph& glyph) {
|
||||
return UIRender{
|
||||
.backgroundTexture = glyph.texture,
|
||||
.position = Vector2(glyph.position) + anchor,
|
||||
.dimensions = Vector2(glyph.dimensions),
|
||||
.level = level,
|
||||
};
|
||||
}));
|
||||
}
|
||||
// height = fontsize * 1.12
|
||||
|
||||
private:
|
||||
std::string text;
|
||||
Array<FontAsset::RenderGlyph> glyphRenders;
|
||||
};
|
||||
} // namespace UI
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user