diff options
author | Patrick Desaulniers <desaulniers.patrick@carrefour.cegepvicto.ca> | 2018-09-29 08:42:44 -0400 |
---|---|---|
committer | Filipe Coelho <falktx@falktx.com> | 2018-09-29 21:36:34 +0200 |
commit | bf7594cbad62d2f035d6a1f7a1da5edd281786d1 (patch) | |
tree | d3c6e8a5d6b5193bc2adaf3effa75221f8911c66 | |
parent | 6d35b690e5399ceaf52b42443b0b3a94587122ac (diff) |
Add onPositionChanged callback for widgets
-rw-r--r-- | dgl/Widget.hpp | 21 | ||||
-rw-r--r-- | dgl/src/Widget.cpp | 22 |
2 files changed, 33 insertions, 10 deletions
diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp index 74bf1837..06abce11 100644 --- a/dgl/Widget.hpp +++ b/dgl/Widget.hpp @@ -176,6 +176,22 @@ public: }; /** + Widget position changed event. + @a pos The new absolute position of the widget. + @a oldPos The previous absolute position of the widget. + @see onPositionChanged + */ + struct PositionChangedEvent { + Point<int> pos; + Point<int> oldPos; + + /** Constuctor */ + PositionChangedEvent() noexcept + : pos(0, 0), + oldPos(0, 0) {} + }; + + /** Constructor. */ explicit Widget(Window& parent); @@ -362,6 +378,11 @@ protected: */ virtual void onResize(const ResizeEvent&); + /** + A function called when the widget's absolute position is changed. + */ + virtual void onPositionChanged(const PositionChangedEvent&); + private: struct PrivateData; PrivateData* const pData; diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp index b94d5dd9..d200fb40 100644 --- a/dgl/src/Widget.cpp +++ b/dgl/src/Widget.cpp @@ -151,20 +151,12 @@ const Point<int>& Widget::getAbsolutePos() const noexcept void Widget::setAbsoluteX(int x) noexcept { - if (pData->absolutePos.getX() == x) - return; - - pData->absolutePos.setX(x); - pData->parent.repaint(); + setAbsolutePos(Point<int>(x, getAbsoluteY())); } void Widget::setAbsoluteY(int y) noexcept { - if (pData->absolutePos.getY() == y) - return; - - pData->absolutePos.setY(y); - pData->parent.repaint(); + setAbsolutePos(Point<int>(getAbsoluteX(), y)); } void Widget::setAbsolutePos(int x, int y) noexcept @@ -177,7 +169,13 @@ void Widget::setAbsolutePos(const Point<int>& pos) noexcept if (pData->absolutePos == pos) return; + PositionChangedEvent ev; + ev.oldPos = pData->absolutePos; + ev.pos = pos; + pData->absolutePos = pos; + onPositionChanged(ev); + pData->parent.repaint(); } @@ -245,6 +243,10 @@ void Widget::onResize(const ResizeEvent&) { } +void Widget::onPositionChanged(const PositionChangedEvent&) +{ +} + // ----------------------------------------------------------------------- END_NAMESPACE_DGL |