implement move policy for window moving

This commit is contained in:
Eduardo Bart 2011-11-03 10:48:48 -02:00
parent 14ce1c8183
commit 9636392d58
4 changed files with 29 additions and 8 deletions

View File

@ -5,7 +5,7 @@ Window < UIWindow
background-color: white background-color: white
head height: 20 head height: 20
head text align: center head text align: center
free move: true move policy: free
border-image: border-image:
source: /core_styles/images/window.png source: /core_styles/images/window.png
border: 4 border: 4
@ -22,8 +22,8 @@ MiniWindow < UIWindow
margin.top: 6 margin.top: 6
margin.left: 6 margin.left: 6
margin.right: 6 margin.right: 6
margin.bottom: 6 move policy: free updated
free move: true focusable: false
border-image: border-image:
source: /core_styles/images/mini_window.png source: /core_styles/images/mini_window.png
border: 4 border: 4

View File

@ -32,6 +32,13 @@ void UIVerticalLayout::update()
{ {
UIWidgetPtr parentWidget = getParentWidget(); UIWidgetPtr parentWidget = getParentWidget();
UIWidgetList widgets = parentWidget->getChildren(); 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(); Point pos = parentWidget->getPosition();
for(const UIWidgetPtr& widget : widgets) { for(const UIWidgetPtr& widget : widgets) {
Size size = widget->getSize(); Size size = widget->getSize();

View File

@ -30,7 +30,7 @@ void UIWindow::setup()
{ {
UIWidget::setup(); UIWidget::setup();
m_moving = false; m_moving = false;
m_freeMove = false; m_movePolicy = DONT_MOVE;
m_headHeight = 0; m_headHeight = 0;
m_titleAlign = Fw::AlignCenter; m_titleAlign = Fw::AlignCenter;
} }
@ -70,8 +70,14 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
setTitle(node->value()); setTitle(node->value());
else if(node->tag() == "head text align") else if(node->tag() == "head text align")
m_titleAlign = Fw::translateAlignment(node->value()); m_titleAlign = Fw::translateAlignment(node->value());
else if(node->tag() == "free move") else if(node->tag() == "move policy") {
m_freeMove = node->value<bool>(); 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") { else if(node->tag() == "onEnter") {
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]"); g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
luaSetField(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) bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button)
{ {
if(m_freeMove) { if(m_movePolicy != DONT_MOVE) {
UIWidgetPtr clickedChild = getChildByPos(mousePos); UIWidgetPtr clickedChild = getChildByPos(mousePos);
if(!clickedChild || clickedChild->isPhantom()) { if(!clickedChild || clickedChild->isPhantom()) {
m_moving = true; m_moving = true;
@ -138,6 +144,8 @@ bool UIWindow::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{ {
if(m_moving) { if(m_moving) {
moveTo(mousePos - m_movingReference); moveTo(mousePos - m_movingReference);
if(m_movePolicy == FREE_UPDATED_MOVE)
updateParentLayout();
return true; return true;
} }
return UIWidget::onMouseMove(mousePos, mouseMoved); return UIWidget::onMouseMove(mousePos, mouseMoved);

View File

@ -27,6 +27,12 @@
class UIWindow : public UIWidget class UIWindow : public UIWidget
{ {
enum MovePolicy {
DONT_MOVE = 0,
FREE_MOVE,
FREE_UPDATED_MOVE
};
public: public:
virtual void setup(); virtual void setup();
virtual void render(); virtual void render();
@ -46,7 +52,7 @@ protected:
private: private:
std::string m_title; std::string m_title;
bool m_moving; bool m_moving;
bool m_freeMove; MovePolicy m_movePolicy;
Point m_movingReference; Point m_movingReference;
// styling // styling