ADD: FlexDirection
This commit is contained in:
parent
d9a1596ea2
commit
dbbb2cf07d
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user