|
|
@@ -129,6 +129,7 @@ UIElement::UIElement(Context* context) :
|
|
|
layoutMode_(LM_FREE),
|
|
|
layoutSpacing_(0),
|
|
|
layoutBorder_(IntRect::ZERO),
|
|
|
+ layoutFlexScale_(Vector2::ONE),
|
|
|
resizeNestingLevel_(0),
|
|
|
layoutNestingLevel_(0),
|
|
|
layoutMinSize_(0),
|
|
|
@@ -198,6 +199,7 @@ void UIElement::RegisterObject(Context* context)
|
|
|
ENUM_ACCESSOR_ATTRIBUTE(UIElement, "Layout Mode", GetLayoutMode, SetLayoutMode, LayoutMode, layoutModes, LM_FREE, AM_FILE);
|
|
|
ACCESSOR_ATTRIBUTE(UIElement, VAR_INT, "Layout Spacing", GetLayoutSpacing, SetLayoutSpacing, int, 0, AM_FILE);
|
|
|
REF_ACCESSOR_ATTRIBUTE(UIElement, VAR_INTRECT, "Layout Border", GetLayoutBorder, SetLayoutBorder, IntRect, IntRect::ZERO, AM_FILE);
|
|
|
+ REF_ACCESSOR_ATTRIBUTE(UIElement, VAR_VECTOR2, "Layout Flex Scale", GetLayoutFlexScale, SetLayoutFlexScale, Vector2, Vector2::ONE, AM_FILE);
|
|
|
ACCESSOR_ATTRIBUTE(UIElement, VAR_INT, "Indent", GetIndent, SetIndent, int, 0, AM_FILE);
|
|
|
ACCESSOR_ATTRIBUTE(UIElement, VAR_INT, "Indent Spacing", GetIndentSpacing, SetIndentSpacing, int, 16, AM_FILE);
|
|
|
ATTRIBUTE(UIElement, VAR_VARIANTMAP, "Variables", vars_, Variant::emptyVariantMap, AM_FILE);
|
|
|
@@ -249,6 +251,9 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Prevent updates while loading attributes
|
|
|
+ DisableLayoutUpdate();
|
|
|
+
|
|
|
// Then load rest of the attributes from the source
|
|
|
if (!Animatable::LoadXML(source, setInstanceDefault))
|
|
|
return false;
|
|
|
@@ -297,6 +302,9 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
|
|
|
|
|
|
ApplyAttributes();
|
|
|
|
|
|
+ EnableLayoutUpdate();
|
|
|
+ UpdateLayout();
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -1004,6 +1012,11 @@ void UIElement::SetLayoutBorder(const IntRect& border)
|
|
|
UpdateLayout();
|
|
|
}
|
|
|
|
|
|
+void UIElement::SetLayoutFlexScale(const Vector2& scale)
|
|
|
+{
|
|
|
+ layoutFlexScale_ = Vector2(Max(scale.x_, 0.0f), Max(scale.y_, 0.0f));
|
|
|
+}
|
|
|
+
|
|
|
void UIElement::SetIndent(int indent)
|
|
|
{
|
|
|
indent_ = indent;
|
|
|
@@ -1034,6 +1047,7 @@ void UIElement::UpdateLayout()
|
|
|
PODVector<int> sizes;
|
|
|
PODVector<int> minSizes;
|
|
|
PODVector<int> maxSizes;
|
|
|
+ PODVector<float> flexScales;
|
|
|
|
|
|
int baseIndentWidth = GetIndentWidth();
|
|
|
|
|
|
@@ -1050,10 +1064,11 @@ void UIElement::UpdateLayout()
|
|
|
sizes.Push(children_[i]->GetWidth() + indent);
|
|
|
minSizes.Push(children_[i]->GetMinWidth() + indent);
|
|
|
maxSizes.Push(children_[i]->GetMaxWidth() + indent);
|
|
|
+ flexScales.Push(children_[i]->GetLayoutFlexScale().x_);
|
|
|
minChildHeight = Max(minChildHeight, children_[i]->GetMinHeight());
|
|
|
}
|
|
|
|
|
|
- CalculateLayout(positions, sizes, minSizes, maxSizes, GetWidth(), layoutBorder_.left_, layoutBorder_.right_, layoutSpacing_);
|
|
|
+ CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetWidth(), layoutBorder_.left_, layoutBorder_.right_, layoutSpacing_);
|
|
|
|
|
|
int width = Max(GetWidth(), CalculateLayoutParentSize(sizes, layoutBorder_.left_, layoutBorder_.right_, layoutSpacing_));
|
|
|
int height = Max(GetHeight(), minChildHeight + layoutBorder_.top_ + layoutBorder_.bottom_);
|
|
|
@@ -1091,10 +1106,11 @@ void UIElement::UpdateLayout()
|
|
|
sizes.Push(children_[i]->GetHeight());
|
|
|
minSizes.Push(children_[i]->GetMinHeight());
|
|
|
maxSizes.Push(children_[i]->GetMaxHeight());
|
|
|
+ flexScales.Push(children_[i]->GetLayoutFlexScale().y_);
|
|
|
minChildWidth = Max(minChildWidth, children_[i]->GetMinWidth() + children_[i]->GetIndentWidth());
|
|
|
}
|
|
|
|
|
|
- CalculateLayout(positions, sizes, minSizes, maxSizes, GetHeight(), layoutBorder_.top_, layoutBorder_.bottom_, layoutSpacing_);
|
|
|
+ CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetHeight(), layoutBorder_.top_, layoutBorder_.bottom_, layoutSpacing_);
|
|
|
|
|
|
int height = Max(GetHeight(), CalculateLayoutParentSize(sizes, layoutBorder_.top_, layoutBorder_.bottom_, layoutSpacing_));
|
|
|
int width = Max(GetWidth(), minChildWidth + layoutBorder_.left_ + layoutBorder_.right_);
|
|
|
@@ -1843,7 +1859,7 @@ int UIElement::CalculateLayoutParentSize(const PODVector<int>& sizes, int begin,
|
|
|
}
|
|
|
|
|
|
void UIElement::CalculateLayout(PODVector<int>& positions, PODVector<int>& sizes, const PODVector<int>& minSizes,
|
|
|
- const PODVector<int>& maxSizes, int targetSize, int begin, int end, int spacing)
|
|
|
+ const PODVector<int>& maxSizes, const PODVector<float>& flexScales, int targetSize, int begin, int end, int spacing)
|
|
|
{
|
|
|
int numChildren = sizes.Size();
|
|
|
if (!numChildren)
|
|
|
@@ -1859,7 +1875,7 @@ void UIElement::CalculateLayout(PODVector<int>& positions, PODVector<int>& sizes
|
|
|
// Initial pass
|
|
|
for (int i = 0; i < numChildren; ++i)
|
|
|
{
|
|
|
- int targetSize = targetChildSize;
|
|
|
+ int targetSize = (int)(targetChildSize * flexScales[i]);
|
|
|
if (remainder)
|
|
|
{
|
|
|
acc += add;
|
|
|
@@ -1905,7 +1921,7 @@ void UIElement::CalculateLayout(PODVector<int>& positions, PODVector<int>& sizes
|
|
|
for (int i = 0; i < numResizable; ++i)
|
|
|
{
|
|
|
unsigned index = resizable[i];
|
|
|
- int targetSize = sizes[index] + errorPerChild;
|
|
|
+ int targetSize = sizes[index] + errorPerChild * flexScales[i];
|
|
|
if (remainder)
|
|
|
{
|
|
|
acc += add;
|