Better default + made root node constraint other nodes

This commit is contained in:
antopilo
2024-09-13 21:46:21 -04:00
parent efc4b8bae7
commit fad8b4033b
4 changed files with 21 additions and 6 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);

View File

@@ -45,7 +45,7 @@ namespace NuakeUI
float AspectRatio;
FlexDirectionType FlexDirection;
FlexWrapType FlexWrap;
float FlexBasis;
Length FlexBasis;
float FlexGrow;
float FlexShrink;
JustifyContentType JustifyContent;