diff --git a/Nuake/src/UI/Inspector.h b/Nuake/src/UI/Inspector.h index 6159e9be..05443e39 100644 --- a/Nuake/src/UI/Inspector.h +++ b/Nuake/src/UI/Inspector.h @@ -83,7 +83,6 @@ namespace NuakeUI ImGui::SliderFloat("Margin Top", &mSelectedNode->ComputedStyle.MarginTop.value, 0.f, 1920.0f); ImGui::SliderFloat("Margin Bottom", &mSelectedNode->ComputedStyle.MarginBottom.value, 0.0f, 1080.0f); - ImGui::SliderFloat("Flex Basis", &mSelectedNode->ComputedStyle.FlexBasis, 0.f, 1920.0f); ImGui::SliderFloat("Flex Grow", &mSelectedNode->ComputedStyle.FlexGrow, 0.0f, 1080.0f); ImGui::SliderFloat("Flex Shrink", &mSelectedNode->ComputedStyle.FlexShrink, 0.f, 1920.0f); ImGui::SliderFloat("Font Size", &mSelectedNode->ComputedStyle.FontSize, 0.0f, 1080.0f); diff --git a/Nuake/src/UI/Nodes/Canvas.cpp b/Nuake/src/UI/Nodes/Canvas.cpp index 5380075e..aafd1bf1 100644 --- a/Nuake/src/UI/Nodes/Canvas.cpp +++ b/Nuake/src/UI/Nodes/Canvas.cpp @@ -18,6 +18,8 @@ namespace NuakeUI Canvas::Canvas() : mInputManager(nullptr), mDirty(false) { mYogaConfig = YGConfigNew(); + YGConfigSetUseWebDefaults(mYogaConfig, true); + YGConfigSetPointScaleFactor(mYogaConfig, 1.0f); } Canvas::~Canvas() @@ -70,8 +72,16 @@ namespace NuakeUI mRootNode->Calculate(); + YGNodeStyleSetMaxWidth(root, size.x); + // This enfores that the root max size is the viewport. + mRootNode->ComputedStyle.MaxWidth = { size.x, LengthType::Pixel }; + mRootNode->ComputedStyle.MaxHeight = { size.y, LengthType::Pixel }; + if (root) + { + YGNodeSetAlwaysFormsContainingBlock(root, true /*alwaysFormsContainingBlock*/); YGNodeCalculateLayout(root, size.x, size.y, YGDirectionLTR); + } } void Canvas::ComputeStyle(NodePtr node) diff --git a/Nuake/src/UI/Nodes/Node.cpp b/Nuake/src/UI/Nodes/Node.cpp index 09319da5..c823342a 100644 --- a/Nuake/src/UI/Nodes/Node.cpp +++ b/Nuake/src/UI/Nodes/Node.cpp @@ -423,9 +423,7 @@ namespace NuakeUI break; EnumProp(FlexDirection) EnumProp(FlexWrap) - case StyleProperties::FlexBasis: - ComputedStyle.FlexBasis = value.value.Number; - break; + LengthProp(FlexBasis) case StyleProperties::FlexGrow: ComputedStyle.FlexGrow = value.value.Number; break; @@ -519,7 +517,6 @@ namespace NuakeUI } } - SetLength(Width) SetLength(Height) @@ -558,6 +555,13 @@ namespace NuakeUI SetLengthBorderNoAuto(Padding, Right); SetLengthBorderNoAuto(Padding, Bottom); + if (ComputedStyle.FlexGrow > 0.f) + YGNodeStyleSetFlexGrow(mNode, ComputedStyle.FlexGrow); + if (ComputedStyle.FlexShrink > 0.f) + YGNodeStyleSetFlexShrink(mNode, ComputedStyle.FlexShrink); + + SetLength(FlexBasis); + if (ComputedStyle.Position == PositionType::Relative) YGNodeStyleSetPositionType(mNode, YGPositionTypeRelative); else if (ComputedStyle.Position == PositionType::Absolute) @@ -607,6 +611,8 @@ namespace NuakeUI YGNodeStyleSetFlexDirection(mNode, YGFlexDirectionColumn); if (ComputedStyle.FlexDirection == FlexDirectionType::ColumnReversed) YGNodeStyleSetFlexDirection(mNode, YGFlexDirectionColumnReverse); + + else if (ComputedStyle.AlignItems == AlignItemsType::Center) YGNodeStyleSetAlignItems(mNode, YGAlignCenter); diff --git a/Nuake/src/UI/Nodes/NodeStyle.h b/Nuake/src/UI/Nodes/NodeStyle.h index e0d87910..a97f415d 100644 --- a/Nuake/src/UI/Nodes/NodeStyle.h +++ b/Nuake/src/UI/Nodes/NodeStyle.h @@ -45,7 +45,7 @@ namespace NuakeUI float AspectRatio; FlexDirectionType FlexDirection; FlexWrapType FlexWrap; - float FlexBasis; + Length FlexBasis; float FlexGrow; float FlexShrink; JustifyContentType JustifyContent;