Files
Seele/src/Engine/UI/Element/Text.h
T

37 lines
1.4 KiB
C++
Raw Normal View History

2025-01-08 19:15:12 +01:00
#pragma once
#include "UI/Element.h"
#include "UI/Style/Class.h"
2025-01-29 16:15:48 +01:00
#include <ranges>
2025-01-08 19:15:12 +01:00
namespace Seele {
namespace UI {
2025-01-12 11:26:52 +01:00
template <StyleClass... classes> class Text : public Element {
2025-01-08 19:15:12 +01:00
public:
Text(std::string text) : Element({}, {}), text(text) {}
2025-01-12 11:26:52 +01:00
virtual void applyStyle(Style parentStyle) {
style = parentStyle;
style.outerDisplay = OuterDisplayType::Inline;
(classes::apply(style), ...);
}
virtual void layout(UVector2 parentSize) override {
2025-01-29 16:15:48 +01:00
UVector2 cursor = UVector2(0);
dimensions = style.fontFamily->shapeText(text, style.fontSize, glyphRenders);
2025-01-12 11:26:52 +01:00
}
virtual Array<UIRender> render(Vector2 anchor, uint32 level) override {
2025-01-29 16:15:48 +01:00
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,
};
}));
2025-01-12 11:26:52 +01:00
}
// height = fontsize * 1.12
2025-01-08 19:15:12 +01:00
private:
std::string text;
2025-01-29 16:15:48 +01:00
Array<FontAsset::RenderGlyph> glyphRenders;
2025-01-08 19:15:12 +01:00
};
} // namespace UI
} // namespace Seele