fix and changes

* win32 compilation fix
* add buttons to miniwindow
* dispatcher events fixes
* ui fixes
This commit is contained in:
Eduardo Bart
2012-03-27 15:14:35 -03:00
parent 060c1cf8e7
commit 8ea154016b
24 changed files with 129 additions and 81 deletions

View File

@@ -81,11 +81,11 @@ void UIAnchorLayout::removeWidget(const UIWidgetPtr& widget)
removeAnchors(widget);
}
void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup)
bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup)
{
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
Rect newRect = widget->getRect();
bool verticalMoved = false;
@@ -214,12 +214,17 @@ void UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
}
}
widget->setRect(newRect);
bool changed = false;
if(widget->setRect(newRect))
changed = true;
anchorGroup.setUpdated(true);
return changed;
}
void UIAnchorLayout::internalUpdate()
bool UIAnchorLayout::internalUpdate()
{
bool changed = false;
// reset all anchors groups update state
for(auto& it : m_anchorsGroups) {
UIAnchorGroup& anchorGroup = it.second;
@@ -230,7 +235,11 @@ void UIAnchorLayout::internalUpdate()
for(auto& it : m_anchorsGroups) {
const UIWidgetPtr& widget = it.first;
UIAnchorGroup& anchorGroup = it.second;
if(!anchorGroup.isUpdated())
updateWidget(widget, anchorGroup);
if(!anchorGroup.isUpdated()) {
if(updateWidget(widget, anchorGroup))
changed = true;
}
}
return changed;
}

View File

@@ -75,10 +75,10 @@ public:
UIAnchorLayoutPtr asUIAnchorLayout() { return std::static_pointer_cast<UIAnchorLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
private:
void updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup);
bool updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anchorGroup);
std::map<UIWidgetPtr, UIAnchorGroup> m_anchorsGroups;
};

View File

@@ -62,8 +62,9 @@ void UIGridLayout::addWidget(const UIWidgetPtr& widget)
update();
}
void UIGridLayout::internalUpdate()
bool UIGridLayout::internalUpdate()
{
bool changed = false;
UIWidgetPtr parentWidget = getParentWidget();
UIWidgetList widgets = parentWidget->getChildren();
@@ -80,12 +81,15 @@ void UIGridLayout::internalUpdate()
Point virtualPos = Point(column * (m_cellSize.width() + m_cellSpacing), line * (m_cellSize.height() + m_cellSpacing));
Point pos = topLeft + virtualPos;
widget->setRect(Rect(pos, m_cellSize));
if(widget->setRect(Rect(pos, m_cellSize)))
changed = true;
index++;
if(index >= m_numColumns * m_numLines)
break;
}
return changed;
}

View File

@@ -44,7 +44,7 @@ public:
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
protected:
void internalUpdate();
bool internalUpdate();
private:
Size m_cellSize;

View File

@@ -35,16 +35,17 @@ void UIHorizontalLayout::applyStyle(const OTMLNodePtr& styleNode)
}
}
void UIHorizontalLayout::internalUpdate()
bool UIHorizontalLayout::internalUpdate()
{
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
UIWidgetList widgets = parentWidget->getChildren();
if(m_alignRight)
std::reverse(widgets.begin(), widgets.end());
bool changed = false;
Rect clippingRect = parentWidget->getClippingRect();
Point pos = (m_alignRight) ? clippingRect.topRight() : clippingRect.topLeft();
int prefferedWidth = 0;
@@ -70,7 +71,8 @@ void UIHorizontalLayout::internalUpdate()
pos.y = clippingRect.top() + (clippingRect.height() - size.height())/2;
}
widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size));
if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
changed = true;
gap = (m_alignRight) ? -widget->getMarginLeft() : (widget->getWidth() + widget->getMarginRight());
gap += m_spacing;
@@ -87,4 +89,6 @@ void UIHorizontalLayout::internalUpdate()
parentWidget->setWidth(prefferedWidth);
});
}
return true;
}

View File

@@ -37,7 +37,7 @@ public:
UIHorizontalLayoutPtr asUIHorizontalLayout() { return std::static_pointer_cast<UIHorizontalLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
Boolean<false> m_alignRight;
};

View File

@@ -38,7 +38,7 @@ void UILayout::update()
m_updating = true;
internalUpdate();
if(UIWidgetPtr parentWidget = getParentWidget())
parentWidget->onLayoutUpdate();
parentWidget->onLayoutUpdate();
m_updating = false;
}

View File

@@ -55,7 +55,7 @@ public:
virtual UIGridLayoutPtr asUIGridLayout() { return nullptr; }
protected:
virtual void internalUpdate() = 0;
virtual bool internalUpdate() = 0;
Boolean<false> m_updateDisabled;
Boolean<false> m_updating;

View File

@@ -34,11 +34,13 @@ void UIVerticalLayout::applyStyle(const OTMLNodePtr& styleNode)
}
}
void UIVerticalLayout::internalUpdate()
bool UIVerticalLayout::internalUpdate()
{
bool changed = false;
UIWidgetPtr parentWidget = getParentWidget();
if(!parentWidget)
return;
return false;
UIWidgetList widgets = parentWidget->getChildren();
@@ -70,7 +72,8 @@ void UIVerticalLayout::internalUpdate()
pos.x = clippingRect.left() + (clippingRect.width() - size.width())/2;
}
widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size));
if(widget->setRect(Rect(pos - parentWidget->getVirtualOffset(), size)))
changed = true;
gap = (m_alignBottom) ? -widget->getMarginTop() : (widget->getHeight() + widget->getMarginBottom());
gap += m_spacing;
@@ -87,4 +90,6 @@ void UIVerticalLayout::internalUpdate()
parentWidget->setHeight(prefferedHeight);
});
}
return changed;
}

View File

@@ -37,7 +37,7 @@ public:
UIVerticalLayoutPtr asUIVerticalLayout() { return std::static_pointer_cast<UIVerticalLayout>(shared_from_this()); }
protected:
void internalUpdate();
bool internalUpdate();
Boolean<false> m_alignBottom;
};

View File

@@ -726,16 +726,16 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
m_layout = layout;
}
void UIWidget::setRect(const Rect& rect)
bool UIWidget::setRect(const Rect& rect)
{
if(rect.width() > 8192 || rect.height() > 8192) {
logError("attempt to set huge rect size (", rect,") for ", m_id);
return;
return false;
}
// only update if the rect really changed
Rect oldRect = m_rect;
if(rect == oldRect)
return;
return false;
m_rect = rect;
@@ -752,6 +752,8 @@ void UIWidget::setRect(const Rect& rect)
});
m_updateEventScheduled = true;
}
return true;
}
void UIWidget::setStyle(const std::string& styleName)
@@ -978,6 +980,9 @@ UIWidgetPtr UIWidget::getChildById(const std::string& childId)
UIWidgetPtr UIWidget::getChildByPos(const Point& childPos)
{
if(!containsChildPoint(childPos))
return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos))
@@ -1010,6 +1015,9 @@ UIWidgetPtr UIWidget::recursiveGetChildById(const std::string& id)
UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
{
if(!containsChildPoint(childPos))
return nullptr;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
@@ -1026,6 +1034,9 @@ UIWidgetPtr UIWidget::recursiveGetChildByPos(const Point& childPos)
UIWidgetList UIWidget::recursiveGetChildrenByPos(const Point& childPos)
{
UIWidgetList children;
if(!containsChildPoint(childPos))
return children;
for(auto it = m_children.rbegin(); it != m_children.rend(); ++it) {
const UIWidgetPtr& child = (*it);
if(child->isExplicitlyVisible() && child->containsPoint(childPos)) {
@@ -1342,8 +1353,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
m_lastClickPosition = mousePos;
}
if(hasLuaField("onMousePress"))
if(hasLuaField("onMousePress")) {
return callLuaField<bool>("onMousePress", mousePos, button);
}
return true;
}

View File

@@ -113,7 +113,7 @@ public:
void setId(const std::string& id);
void setParent(const UIWidgetPtr& parent);
void setLayout(const UILayoutPtr& layout);
void setRect(const Rect& rect);
bool setRect(const Rect& rect);
void setStyle(const std::string& styleName);
void setStyleFromNode(const OTMLNodePtr& styleNode);
void setEnabled(bool enabled);
@@ -240,6 +240,7 @@ public:
bool isDestroyed() { return m_destroyed; }
bool hasChildren() { return m_children.size() > 0; }
bool containsChildPoint(const Point& point) { return getClippingRect().contains(point); }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
std::string getId() { return m_id; }