mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 21:09: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;
|
return alignedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getGrow(WidgetExtension* w)
|
||||||
|
{
|
||||||
|
return std::max(0.0f, w->externalValue("grow", 0.0f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaFlex::updateChildren()
|
void LuaFlex::updateChildren()
|
||||||
|
@ -42,9 +47,9 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
w->clearForced();
|
w->clearForced();
|
||||||
MyGUI::IntSize size = w->calculateSize();
|
MyGUI::IntSize size = w->calculateSize();
|
||||||
setPrimary(childrenSize, getPrimary(childrenSize) + getPrimary(size));
|
primary(childrenSize) += primary(size);
|
||||||
setSecondary(childrenSize, std::max(getSecondary(childrenSize), getSecondary(size)));
|
secondary(childrenSize) = std::max(secondary(childrenSize), secondary(size));
|
||||||
totalGrow += std::max(0.0f, w->externalValue("grow", 0.0f));
|
totalGrow += getGrow(w);
|
||||||
}
|
}
|
||||||
mChildrenSize = childrenSize;
|
mChildrenSize = childrenSize;
|
||||||
|
|
||||||
|
@ -53,22 +58,20 @@ namespace LuaUi
|
||||||
float growFactor = 0;
|
float growFactor = 0;
|
||||||
if (totalGrow > 0)
|
if (totalGrow > 0)
|
||||||
{
|
{
|
||||||
growSize = getPrimary(flexSize) - getPrimary(childrenSize);
|
growSize = primary(flexSize) - primary(childrenSize);
|
||||||
growFactor = growSize / totalGrow;
|
growFactor = growSize / totalGrow;
|
||||||
}
|
}
|
||||||
setPrimary(flexSize, getPrimary(flexSize) - growSize);
|
|
||||||
|
|
||||||
MyGUI::IntPoint childPosition;
|
MyGUI::IntPoint childPosition;
|
||||||
setPrimary(childPosition, alignSize(getPrimary(flexSize), getPrimary(childrenSize), mAlign));
|
primary(childPosition) = alignSize(primary(flexSize) - growSize, primary(childrenSize), mAlign);
|
||||||
setSecondary(childPosition, alignSize(getSecondary(flexSize), getSecondary(childrenSize), mArrange));
|
secondary(childPosition) = alignSize(secondary(flexSize), secondary(childrenSize), mArrange);
|
||||||
for (auto* w : children())
|
for (auto* w : children())
|
||||||
{
|
{
|
||||||
w->forcePosition(childPosition);
|
w->forcePosition(childPosition);
|
||||||
MyGUI::IntSize size = w->widget()->getSize();
|
MyGUI::IntSize size = w->widget()->getSize();
|
||||||
float grow = std::max(0.0f, w->externalValue("grow", 0.0f));
|
primary(size) += static_cast<int>(growFactor * getGrow(w));
|
||||||
setPrimary(size, getPrimary(size) + static_cast<int>(growFactor * grow));
|
|
||||||
w->forceSize(size);
|
w->forceSize(size);
|
||||||
setPrimary(childPosition, getPrimary(childPosition) + getPrimary(size));
|
primary(childPosition) += primary(size);
|
||||||
}
|
}
|
||||||
WidgetExtension::updateProperties();
|
WidgetExtension::updateProperties();
|
||||||
}
|
}
|
||||||
|
@ -77,8 +80,8 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
MyGUI::IntSize size = WidgetExtension::calculateSize();
|
MyGUI::IntSize size = WidgetExtension::calculateSize();
|
||||||
if (mAutoSized) {
|
if (mAutoSized) {
|
||||||
setPrimary(size, getPrimary(mChildrenSize));
|
primary(size) = primary(mChildrenSize);
|
||||||
setSecondary(size, std::max(getSecondary(size), getSecondary(mChildrenSize)));
|
secondary(size) = std::max(secondary(size), secondary(mChildrenSize));
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,63 +27,27 @@ namespace LuaUi
|
||||||
Alignment mArrange;
|
Alignment mArrange;
|
||||||
|
|
||||||
template<typename T>
|
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;
|
return mHorizontal ? point.left : point.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
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;
|
return mHorizontal ? point.top : point.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void setPrimary(MyGUI::types::TPoint<T>& point, T value)
|
T& primary(MyGUI::types::TSize<T>& size)
|
||||||
{
|
{
|
||||||
if (mHorizontal)
|
return mHorizontal ? size.width : size.height;
|
||||||
point.left = value;
|
|
||||||
else
|
|
||||||
point.top = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void setSecondary(MyGUI::types::TPoint<T>& point, T value)
|
T& secondary(MyGUI::types::TSize<T>& size)
|
||||||
{
|
{
|
||||||
if (mHorizontal)
|
return mHorizontal ? size.height : size.width;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue