Initial flexbox implementation

This commit is contained in:
Dynamitos committed 2026-10-25 07:34:05 +01:00
1 parent 1bc73b6d2f
commit bcb9a7b148
15 files changed
+1504 -142

No files matched your search

+22 -1
View File
@@ -13,7 +13,28 @@ class Div : public Element {
virtual ~Div() {}
virtual void applyStyle(Style parentStyle, const Theme& theme) override {
style = parentStyle;
style.outerDisplay = OuterDisplayType::Block;
// CSS non-inherited properties: reset to defaults before applying template
// classes. width/height, min/max, margin/padding, gap, position offsets, and
// per-item flex properties (grow/shrink/order/basis/alignSelf) are all
// non-inherited in CSS — a child's Div classes opt in explicitly.
// Inherited (keep from parent): display, direction, wrap, justify, items,
// content, z, colors, font, lineHeight, fontSize, fontWeight.
style.widthType = DimensionType::Auto; style.width = 0;
style.minWidthType = DimensionType::Auto; style.minWidth = 0;
style.maxWidthType = DimensionType::Auto; style.maxWidth = 0;
style.heightType = DimensionType::Auto; style.height = 0;
style.minHeightType = DimensionType::Auto; style.minHeight = 0;
style.maxHeightType = DimensionType::Auto; style.maxHeight = 0;
style.paddingTop = 0; style.paddingBottom = 0;
style.paddingLeft = 0; style.paddingRight = 0;
style.marginTop = 0; style.marginBottom = 0;
style.marginLeft = 0; style.marginRight = 0;
style.gap = 0;
style.top = 0; style.bottom = 0; style.left = 0; style.right = 0;
style.position = Position::Static;
style.grow = 0.f; style.shrink = 1.f;
style.order = 0; style.alignSelfOverride = -1.f;
style.basisType = DimensionType::Auto; style.basis = 0.f;
(classes::apply(style, theme), ...);
}
private:
-1
View File
@@ -15,7 +15,6 @@ class Panel : public Div<classes...> {
virtual void applyStyle(Style parentStyle, const Theme& theme) override {
// start from the panel chrome, then let the user's classes win
style = parentStyle;
style.outerDisplay = OuterDisplayType::Block;
style.backgroundColor = theme.color(ColorToken::Gray900);
style.textColor = theme.color(ColorToken::White);
uint32 pad = theme.spacing(8);
+6 -1
View File
@@ -61,11 +61,16 @@ class Text : public Element {
if (style.heightType == UI::DimensionType::Auto) {
style.height = h;
}
// the measured size is also the element's natural size: layout measures
// through Element::intrinsicW/H (set here) instead of trusting a stale
// style.width/height that a later setText() invalidation may have left behind.
intrinsicW = w;
intrinsicH = h;
}
virtual Array<UIRender> render(Vector2 anchor, uint32 level) override {
Array<UIRender> result;
if (style.hidden || style.outerDisplay == OuterDisplayType::Hidden) {
if (style.display == Display::Hidden) {
return result;
}
Vector2 pos = position + anchor;