basic flow layout

This commit is contained in:
Dynamitos
2025-01-12 11:26:52 +01:00
parent e487867f96
commit 2915db8898
18 changed files with 415 additions and 172 deletions
+8 -1
View File
@@ -7,8 +7,15 @@ namespace UI {
template<StyleClass... classes>
class Div : public Element {
public:
Div(Attributes attr, std::initializer_list<OElement> children) : Element(attr, children) { style.displayType = DisplayType::Block; }
Div(Attributes attr, Array<Element*> children) : Element(attr, std::move(children)) { }
virtual ~Div() {}
virtual void applyStyle(Style parentStyle) override {
style = parentStyle;
style.outerDisplay = OuterDisplayType::Block;
style.widthType = DimensionType::Percent;
style.width = 100;
(classes::apply(style), ...);
}
private:
};
} // namespace UI
+28 -2
View File
@@ -4,10 +4,36 @@
namespace Seele {
namespace UI {
class Text : public Element {
template <StyleClass... classes> class Text : public Element {
public:
Text(std::string text) : Element({}, {}), text(text) {}
virtual void calcStyle(Style parentStyle) override { style = parentStyle; }
virtual void applyStyle(Style parentStyle) {
style = parentStyle;
style.outerDisplay = OuterDisplayType::Inline;
(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]).advance / 64.0f;
}
dimensions.x += style.fontFamily->getGlyphData(text[text.size() - 1]).size.x;
dimensions.y = style.fontSize;
}
virtual Array<UIRender> render(Vector2 anchor, uint32 level) override {
return {
UIRender{
.text = text,
.font = style.fontFamily,
.fontSize = style.fontSize,
.position = position + anchor,
.dimensions = dimensions,
.z = style.z,
.level = level,
},
};
}
// height = fontsize * 1.12
private:
std::string text;