diff --git a/modules/core_styles/styles/windows.otui b/modules/core_styles/styles/windows.otui index 960be2de..d296d758 100644 --- a/modules/core_styles/styles/windows.otui +++ b/modules/core_styles/styles/windows.otui @@ -5,7 +5,7 @@ Window < UIWindow background-color: white head height: 20 head text align: center - free move: true + move policy: free border-image: source: /core_styles/images/window.png border: 4 @@ -22,8 +22,8 @@ MiniWindow < UIWindow margin.top: 6 margin.left: 6 margin.right: 6 - margin.bottom: 6 - free move: true + move policy: free updated + focusable: false border-image: source: /core_styles/images/mini_window.png border: 4 diff --git a/src/framework/ui/uiverticallayout.cpp b/src/framework/ui/uiverticallayout.cpp index cc7c1580..4fda1dc3 100644 --- a/src/framework/ui/uiverticallayout.cpp +++ b/src/framework/ui/uiverticallayout.cpp @@ -32,6 +32,13 @@ void UIVerticalLayout::update() { UIWidgetPtr parentWidget = getParentWidget(); UIWidgetList widgets = parentWidget->getChildren(); + + // sort by Y center + std::sort(widgets.begin(), widgets.end(), + [](const UIWidgetPtr& first, const UIWidgetPtr& second) -> bool { + return first->getRect().center().y < second->getRect().center().y; + }); + Point pos = parentWidget->getPosition(); for(const UIWidgetPtr& widget : widgets) { Size size = widget->getSize(); diff --git a/src/framework/ui/uiwindow.cpp b/src/framework/ui/uiwindow.cpp index 4b38b446..e6e7ff00 100644 --- a/src/framework/ui/uiwindow.cpp +++ b/src/framework/ui/uiwindow.cpp @@ -30,7 +30,7 @@ void UIWindow::setup() { UIWidget::setup(); m_moving = false; - m_freeMove = false; + m_movePolicy = DONT_MOVE; m_headHeight = 0; m_titleAlign = Fw::AlignCenter; } @@ -70,8 +70,14 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode) setTitle(node->value()); else if(node->tag() == "head text align") m_titleAlign = Fw::translateAlignment(node->value()); - else if(node->tag() == "free move") - m_freeMove = node->value(); + else if(node->tag() == "move policy") { + if(node->value() == "free") + m_movePolicy = FREE_MOVE; + else if(node->value() == "free updated") + m_movePolicy = FREE_UPDATED_MOVE; + else + m_movePolicy = DONT_MOVE; + } else if(node->tag() == "onEnter") { g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); luaSetField(node->tag()); @@ -115,7 +121,7 @@ void UIWindow::onFocusChange(bool focused, Fw::FocusReason reason) bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button) { - if(m_freeMove) { + if(m_movePolicy != DONT_MOVE) { UIWidgetPtr clickedChild = getChildByPos(mousePos); if(!clickedChild || clickedChild->isPhantom()) { m_moving = true; @@ -138,6 +144,8 @@ bool UIWindow::onMouseMove(const Point& mousePos, const Point& mouseMoved) { if(m_moving) { moveTo(mousePos - m_movingReference); + if(m_movePolicy == FREE_UPDATED_MOVE) + updateParentLayout(); return true; } return UIWidget::onMouseMove(mousePos, mouseMoved); diff --git a/src/framework/ui/uiwindow.h b/src/framework/ui/uiwindow.h index 48b5e010..b8946dae 100644 --- a/src/framework/ui/uiwindow.h +++ b/src/framework/ui/uiwindow.h @@ -27,6 +27,12 @@ class UIWindow : public UIWidget { + enum MovePolicy { + DONT_MOVE = 0, + FREE_MOVE, + FREE_UPDATED_MOVE + }; + public: virtual void setup(); virtual void render(); @@ -46,7 +52,7 @@ protected: private: std::string m_title; bool m_moving; - bool m_freeMove; + MovePolicy m_movePolicy; Point m_movingReference; // styling