ADD: Justify Content in Between
This commit is contained in:
parent
beca6e4d3b
commit
e52785ae14
@ -38,18 +38,35 @@ void UiPositioner::compute(const Dimensions &parent) {
|
|||||||
|
|
||||||
// 3b JustifyContent-offset berechnen
|
// 3b JustifyContent-offset berechnen
|
||||||
float remainingSpace = ((style.flexDirection == FlexDirection::Column) ? screenSpace.height : screenSpace.width) - totalChildrenMainSize;
|
float remainingSpace = ((style.flexDirection == FlexDirection::Column) ? screenSpace.height : screenSpace.width) - totalChildrenMainSize;
|
||||||
|
float gap =0.0f;
|
||||||
|
|
||||||
|
if (uiComponent.parent == nullptr) {
|
||||||
|
printf("Test");
|
||||||
|
}
|
||||||
|
|
||||||
float justifyOffset = 0.0f;
|
float justifyOffset = 0.0f;
|
||||||
switch (style.justifyContent) {
|
switch (style.justifyContent) {
|
||||||
case JustifyContent::Start: justifyOffset = 0.0f; break;
|
case JustifyContent::Start: justifyOffset = 0.0f; break;
|
||||||
case JustifyContent::Center: justifyOffset = remainingSpace / 2.0f; break;
|
case JustifyContent::Center: justifyOffset = remainingSpace / 2.0f; break;
|
||||||
case JustifyContent::End: justifyOffset = remainingSpace; break;
|
case JustifyContent::End: justifyOffset = remainingSpace; break;
|
||||||
|
case JustifyContent::SpaceBetween:
|
||||||
|
justifyOffset = 0.0;
|
||||||
|
if (uiComponent.children.size() > 1) {
|
||||||
|
gap = remainingSpace / (static_cast<float>(uiComponent.children.size()) - 1.0f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: break; // Space between later
|
default: break; // Space between later
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 3. Kinder rekursiv positionieren
|
// 3. Kinder rekursiv positionieren
|
||||||
float currentMainOffset = justifyOffset;
|
float currentMainOffset = justifyOffset;
|
||||||
|
bool first = true;
|
||||||
for (auto& child : uiComponent.children) {
|
for (auto& child : uiComponent.children) {
|
||||||
|
if (!first && style.justifyContent == JustifyContent::SpaceBetween) {
|
||||||
|
currentMainOffset += gap;
|
||||||
|
}
|
||||||
|
|
||||||
if (style.flexDirection == FlexDirection::Column) {
|
if (style.flexDirection == FlexDirection::Column) {
|
||||||
child->uiPositioner.screenSpace.y += currentMainOffset;
|
child->uiPositioner.screenSpace.y += currentMainOffset;
|
||||||
currentMainOffset += child->uiPositioner.screenSpace.height;
|
currentMainOffset += child->uiPositioner.screenSpace.height;
|
||||||
@ -59,6 +76,8 @@ void UiPositioner::compute(const Dimensions &parent) {
|
|||||||
currentMainOffset += child->uiPositioner.screenSpace.width;
|
currentMainOffset += child->uiPositioner.screenSpace.width;
|
||||||
currentMainOffset += child->uiPositioner.resolve(child->uiPositioner.style.margin.left, parent.width, screenWidth);
|
currentMainOffset += child->uiPositioner.resolve(child->uiPositioner.style.margin.left, parent.width, screenWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AlignItems
|
// AlignItems
|
||||||
|
|||||||
@ -23,7 +23,7 @@ void UILayer::onAttach() {
|
|||||||
|
|
||||||
rootContainer = std::make_unique<UiContainer>();
|
rootContainer = std::make_unique<UiContainer>();
|
||||||
LayoutStyle& rootLayout = rootContainer->getLayoutStyle();
|
LayoutStyle& rootLayout = rootContainer->getLayoutStyle();
|
||||||
rootLayout.justifyContent = JustifyContent::End;
|
rootLayout.justifyContent = JustifyContent::SpaceBetween;
|
||||||
|
|
||||||
auto imageStyle = LayoutStyle();
|
auto imageStyle = LayoutStyle();
|
||||||
imageStyle.width = SizeValue(0.25f, SizeUnit::Percent);
|
imageStyle.width = SizeValue(0.25f, SizeUnit::Percent);
|
||||||
@ -49,6 +49,8 @@ void UILayer::onAttach() {
|
|||||||
font = std::make_unique<Font>(myFont);
|
font = std::make_unique<Font>(myFont);
|
||||||
//auto text = std::make_unique<UiText>(*font, "Hello World!", glm::vec2(0.5f, 0.5f), glm::vec3(1,1,1));
|
//auto text = std::make_unique<UiText>(*font, "Hello World!", glm::vec2(0.5f, 0.5f), glm::vec3(1,1,1));
|
||||||
|
|
||||||
|
auto text = std::make_unique<UiText>(*font, "Hello World", imageStyle);
|
||||||
|
|
||||||
//rootContainer->addChild(std::move(text));
|
//rootContainer->addChild(std::move(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user