implement move policy for window moving
This commit is contained in:
parent
14ce1c8183
commit
9636392d58
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<bool>();
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue