diff --git a/components/lua_ui/flex.cpp b/components/lua_ui/flex.cpp index eb37a05fbf..13acfb3990 100644 --- a/components/lua_ui/flex.cpp +++ b/components/lua_ui/flex.cpp @@ -32,6 +32,11 @@ namespace LuaUi } return alignedPosition; } + + float getGrow(WidgetExtension* w) + { + return std::max(0.0f, w->externalValue("grow", 0.0f)); + } } void LuaFlex::updateChildren() @@ -42,9 +47,9 @@ namespace LuaUi { w->clearForced(); MyGUI::IntSize size = w->calculateSize(); - setPrimary(childrenSize, getPrimary(childrenSize) + getPrimary(size)); - setSecondary(childrenSize, std::max(getSecondary(childrenSize), getSecondary(size))); - totalGrow += std::max(0.0f, w->externalValue("grow", 0.0f)); + primary(childrenSize) += primary(size); + secondary(childrenSize) = std::max(secondary(childrenSize), secondary(size)); + totalGrow += getGrow(w); } mChildrenSize = childrenSize; @@ -53,22 +58,20 @@ namespace LuaUi float growFactor = 0; if (totalGrow > 0) { - growSize = getPrimary(flexSize) - getPrimary(childrenSize); + growSize = primary(flexSize) - primary(childrenSize); growFactor = growSize / totalGrow; - } - setPrimary(flexSize, getPrimary(flexSize) - growSize); + } MyGUI::IntPoint childPosition; - setPrimary(childPosition, alignSize(getPrimary(flexSize), getPrimary(childrenSize), mAlign)); - setSecondary(childPosition, alignSize(getSecondary(flexSize), getSecondary(childrenSize), mArrange)); + primary(childPosition) = alignSize(primary(flexSize) - growSize, primary(childrenSize), mAlign); + secondary(childPosition) = alignSize(secondary(flexSize), secondary(childrenSize), mArrange); for (auto* w : children()) { w->forcePosition(childPosition); MyGUI::IntSize size = w->widget()->getSize(); - float grow = std::max(0.0f, w->externalValue("grow", 0.0f)); - setPrimary(size, getPrimary(size) + static_cast(growFactor * grow)); + primary(size) += static_cast(growFactor * getGrow(w)); w->forceSize(size); - setPrimary(childPosition, getPrimary(childPosition) + getPrimary(size)); + primary(childPosition) += primary(size); } WidgetExtension::updateProperties(); } @@ -77,8 +80,8 @@ namespace LuaUi { MyGUI::IntSize size = WidgetExtension::calculateSize(); if (mAutoSized) { - setPrimary(size, getPrimary(mChildrenSize)); - setSecondary(size, std::max(getSecondary(size), getSecondary(mChildrenSize))); + primary(size) = primary(mChildrenSize); + secondary(size) = std::max(secondary(size), secondary(mChildrenSize)); } return size; } diff --git a/components/lua_ui/flex.hpp b/components/lua_ui/flex.hpp index 0ac8963f73..9ac85213f6 100644 --- a/components/lua_ui/flex.hpp +++ b/components/lua_ui/flex.hpp @@ -27,63 +27,27 @@ namespace LuaUi Alignment mArrange; template - inline T getPrimary(const MyGUI::types::TPoint& point) + T& primary(MyGUI::types::TPoint& point) { return mHorizontal ? point.left : point.top; } template - inline T getSecondary(const MyGUI::types::TPoint& point) + T& secondary(MyGUI::types::TPoint& point) { return mHorizontal ? point.top : point.left; } template - inline void setPrimary(MyGUI::types::TPoint& point, T value) + T& primary(MyGUI::types::TSize& size) { - if (mHorizontal) - point.left = value; - else - point.top = value; + return mHorizontal ? size.width : size.height; } template - inline void setSecondary(MyGUI::types::TPoint& point, T value) + T& secondary(MyGUI::types::TSize& size) { - if (mHorizontal) - point.top = value; - else - point.left = value; - } - - template - inline T getPrimary(const MyGUI::types::TSize& point) - { - return mHorizontal ? point.width : point.height; - } - - template - inline T getSecondary(const MyGUI::types::TSize& point) - { - return mHorizontal ? point.height : point.width; - } - - template - inline void setPrimary(MyGUI::types::TSize& point, T value) - { - if (mHorizontal) - point.width = value; - else - point.height = value; - } - - template - inline void setSecondary(MyGUI::types::TSize& point, T value) - { - if (mHorizontal) - point.height = value; - else - point.width = value; + return mHorizontal ? size.height : size.width; } }; }