mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 15:39:41 +00:00
Less primary/secondary coordinate boilerplate in Flex
This commit is contained in:
parent
3580f8ab43
commit
02bbd226b8
2 changed files with 22 additions and 55 deletions
|
@ -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<int>(growFactor * grow));
|
||||
primary(size) += static_cast<int>(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;
|
||||
}
|
||||
|
|
|
@ -27,63 +27,27 @@ namespace LuaUi
|
|||
Alignment mArrange;
|
||||
|
||||
template<typename T>
|
||||
inline T getPrimary(const MyGUI::types::TPoint<T>& point)
|
||||
T& primary(MyGUI::types::TPoint<T>& point)
|
||||
{
|
||||
return mHorizontal ? point.left : point.top;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T getSecondary(const MyGUI::types::TPoint<T>& point)
|
||||
T& secondary(MyGUI::types::TPoint<T>& point)
|
||||
{
|
||||
return mHorizontal ? point.top : point.left;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void setPrimary(MyGUI::types::TPoint<T>& point, T value)
|
||||
T& primary(MyGUI::types::TSize<T>& size)
|
||||
{
|
||||
if (mHorizontal)
|
||||
point.left = value;
|
||||
else
|
||||
point.top = value;
|
||||
return mHorizontal ? size.width : size.height;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void setSecondary(MyGUI::types::TPoint<T>& point, T value)
|
||||
T& secondary(MyGUI::types::TSize<T>& size)
|
||||
{
|
||||
if (mHorizontal)
|
||||
point.top = value;
|
||||
else
|
||||
point.left = value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T getPrimary(const MyGUI::types::TSize<T>& point)
|
||||
{
|
||||
return mHorizontal ? point.width : point.height;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T getSecondary(const MyGUI::types::TSize<T>& point)
|
||||
{
|
||||
return mHorizontal ? point.height : point.width;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void setPrimary(MyGUI::types::TSize<T>& point, T value)
|
||||
{
|
||||
if (mHorizontal)
|
||||
point.width = value;
|
||||
else
|
||||
point.height = value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void setSecondary(MyGUI::types::TSize<T>& point, T value)
|
||||
{
|
||||
if (mHorizontal)
|
||||
point.height = value;
|
||||
else
|
||||
point.width = value;
|
||||
return mHorizontal ? size.height : size.width;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue