ADD: FlexDirection

This commit is contained in:
sebastian 2026-02-12 12:15:01 +01:00
parent d9a1596ea2
commit dbbb2cf07d
2 changed files with 28 additions and 7 deletions

View File

@ -48,6 +48,8 @@ struct LayoutStyle {
.top = {0.0f, SizeUnit::Percent}, .top = {0.0f, SizeUnit::Percent},
}; };
FlexDirection flexDirection = FlexDirection::Column;
float flexGrow = 0.0f; float flexGrow = 0.0f;
}; };

View File

@ -18,21 +18,40 @@ void UiPositioner::compute(const Dimensions &parent) {
// 2. Sibling-Offset nur anwenden, wenn parent existiert // 2. Sibling-Offset nur anwenden, wenn parent existiert
if (uiComponent.parent) { if (uiComponent.parent) {
float offsetY = 0.0f; float siblingOffset = 0.0f;
for (auto& sibling : uiComponent.parent->children) { for (auto& sibling : uiComponent.parent->children) {
if (&sibling->uiPositioner == this) break; // nur bis zu mir if (&sibling->uiPositioner == this) break; // nur bis zu mir
offsetY += sibling->uiPositioner.screenSpace.height; if (uiComponent.parent->uiPositioner.style.flexDirection == FlexDirection::Column) {
offsetY += sibling->uiPositioner.resolve(sibling->uiPositioner.style.margin.top, parent.height, screenHeight); siblingOffset += sibling->uiPositioner.screenSpace.height;
siblingOffset += sibling->uiPositioner.resolve(sibling->uiPositioner.style.margin.top, parent.height, screenHeight);
} else {
siblingOffset += sibling->uiPositioner.screenSpace.width;
siblingOffset += sibling->uiPositioner.resolve(sibling->uiPositioner.style.margin.left, parent.width, screenWidth);
} }
screenSpace.y += offsetY; }
if (uiComponent.parent->uiPositioner.style.flexDirection == FlexDirection::Column) {
screenSpace.y += siblingOffset;
} else {
screenSpace.x += siblingOffset;
}
} }
// 3. Kinder rekursiv positionieren // 3. Kinder rekursiv positionieren
float currentChildOffset = 0.0f; float currentMainOffset = 0.0f;
for (auto& child : uiComponent.children) { for (auto& child : uiComponent.children) {
child->uiPositioner.compute(screenSpace); child->uiPositioner.compute(screenSpace);
currentChildOffset += child->uiPositioner.screenSpace.height;
currentChildOffset += child->uiPositioner.resolve(child->uiPositioner.style.margin.top, screenSpace.height, screenHeight); if (style.flexDirection == FlexDirection::Column) {
child->uiPositioner.screenSpace.y += currentMainOffset;
currentMainOffset += child->uiPositioner.screenSpace.height;
currentMainOffset += child->uiPositioner.resolve(child->uiPositioner.style.margin.top, parent.height, screenHeight);
} else {
child->uiPositioner.screenSpace.x += currentMainOffset;
currentMainOffset += child->uiPositioner.screenSpace.width;
currentMainOffset += child->uiPositioner.resolve(child->uiPositioner.style.margin.left, parent.width, screenWidth);
}
} }
} }