mirror of
https://github.com/edubart/otclient.git
synced 2025-11-07 13:56:22 +01:00
init menu
This commit is contained in:
@@ -28,7 +28,8 @@ UIVerticalLayout::UIVerticalLayout(UIWidgetPtr parentWidget)
|
||||
: UILayout(parentWidget)
|
||||
{
|
||||
m_alignBottom = false;
|
||||
m_padding = 0;
|
||||
m_fitParent = false;
|
||||
m_spacing = 0;
|
||||
}
|
||||
|
||||
void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
|
||||
@@ -37,9 +38,11 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
|
||||
|
||||
for(const OTMLNodePtr& node : styleNode->children()) {
|
||||
if(node->tag() == "align-bottom")
|
||||
m_alignBottom = node->value<bool>();
|
||||
else if(node->tag() == "padding")
|
||||
m_padding = node->value<int>();
|
||||
setAlignBottom(node->value<bool>());
|
||||
else if(node->tag() == "spacing")
|
||||
setSpacing(node->value<int>());
|
||||
else if(node->tag() == "fit-parent")
|
||||
setFitParent(node->value<bool>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,24 +55,41 @@ void UIVerticalLayout::update()
|
||||
std::reverse(widgets.begin(), widgets.end());
|
||||
|
||||
Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition();
|
||||
int prefferedHeight = 0;
|
||||
int gap;
|
||||
|
||||
for(const UIWidgetPtr& widget : widgets) {
|
||||
if(!widget->isExplicitlyVisible())
|
||||
continue;
|
||||
|
||||
Size size = widget->getSize();
|
||||
pos.y += (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
|
||||
|
||||
gap = (m_alignBottom) ? -(widget->getMarginBottom()+widget->getHeight()) : widget->getMarginTop();
|
||||
pos.y += gap;
|
||||
prefferedHeight += gap;
|
||||
|
||||
if(widget->isSizeFixed()) {
|
||||
// center it
|
||||
pos.x = parentWidget->getX() + (parentWidget->getWidth() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
||||
pos.x = std::max(pos.x, parentWidget->getX());
|
||||
} else {
|
||||
// expand width
|
||||
size.setWidth(parentWidget->getWidth() - (widget->getMarginLeft() + widget->getMarginRight()));
|
||||
pos.x = std::max(pos.x, parentWidget->getX() + (parentWidget->getWidth() - size.width())/2);
|
||||
pos.x = parentWidget->getX() + (parentWidget->getWidth() - size.width())/2;
|
||||
}
|
||||
|
||||
widget->setRect(Rect(pos, size));
|
||||
pos.y += (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
|
||||
pos.y += m_padding;
|
||||
|
||||
gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
|
||||
gap += m_spacing;
|
||||
pos.y += gap;
|
||||
prefferedHeight += gap;
|
||||
}
|
||||
|
||||
prefferedHeight -= m_spacing;
|
||||
|
||||
if(m_fitParent && prefferedHeight != parentWidget->getHeight())
|
||||
parentWidget->setHeight(prefferedHeight);
|
||||
}
|
||||
|
||||
void UIVerticalLayout::addWidget(const UIWidgetPtr& widget)
|
||||
@@ -81,3 +101,22 @@ void UIVerticalLayout::removeWidget(const UIWidgetPtr& widget)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void UIVerticalLayout::setAlignBottom(bool aliginBottom)
|
||||
{
|
||||
m_alignBottom = aliginBottom;
|
||||
update();
|
||||
}
|
||||
|
||||
void UIVerticalLayout::setSpacing(int spacing)
|
||||
{
|
||||
m_spacing = spacing;
|
||||
update();
|
||||
}
|
||||
|
||||
void UIVerticalLayout::setFitParent(bool fitParent)
|
||||
{
|
||||
m_fitParent = fitParent;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user