From e4088c3bbfd71f1a9f4ae7344bd5c43202b2ed3e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 29 Nov 2015 21:27:20 +0100 Subject: Fix find of child widgets starting 'before' (0,0). --- plugingui/widget.cc | 17 +++++++---------- plugingui/widget.h | 14 ++++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'plugingui') diff --git a/plugingui/widget.cc b/plugingui/widget.cc index 9b766df..4b92e65 100644 --- a/plugingui/widget.cc +++ b/plugingui/widget.cc @@ -103,6 +103,8 @@ void Widget::resize(int width, int height) _width = width; _height = height; pixbuf.realloc(width, height); + + sizeChangeNotifier(width, height); } void Widget::move(size_t x, size_t y) @@ -111,12 +113,12 @@ void Widget::move(size_t x, size_t y) _y = y; } -size_t Widget::x() +int Widget::x() { return _x; } -size_t Widget::y() +int Widget::y() { return _y; } @@ -153,26 +155,21 @@ size_t Widget::windowY() return window_y; } -Widget* Widget::find(size_t x, size_t y) +Widget* Widget::find(int x, int y) { for(auto i = children.rbegin(); i != children.rend(); ++i) { Widget* widget = *i; if(widget->visible()) { - if((widget->x() <= x) && ((widget->x() + widget->width()) >= x) && - (widget->y() <= y) && ((widget->y() + widget->height()) >= y)) + if((x >= widget->x()) && (x < (widget->x() + (int)widget->width())) && + (y >= widget->y()) && (y < (widget->y() + (int)widget->height()))) { return widget->find(x - widget->x(), y - widget->y()); } } } - if((x > width()) || (y > height())) - { - return nullptr; - } - return this; } diff --git a/plugingui/widget.h b/plugingui/widget.h index 9827641..6bfffb5 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -37,7 +37,7 @@ namespace GUI { class Window; -class Widget : public Listener, LayoutItem { +class Widget : public Listener, public LayoutItem { friend class Painter; public: Widget(Widget* parent); @@ -49,8 +49,8 @@ public: // From LayoutItem virtual void resize(int width, int height) override; virtual void move(size_t x, size_t y) override; - virtual size_t x() override; - virtual size_t y() override; + virtual int x() override; + virtual int y() override; virtual size_t width() override; virtual size_t height() override; @@ -71,7 +71,7 @@ public: virtual void mouseLeaveEvent() {} virtual void mouseEnterEvent() {} - Widget* find(size_t x, size_t y); + Widget* find(int x, int y); virtual Window* window(); @@ -82,6 +82,8 @@ public: bool visible(); void setVisible(bool visible); + Notifier sizeChangeNotifier; // (int, width, int height) + protected: void repaintChildren(RepaintEvent* repaintEvent); @@ -92,8 +94,8 @@ protected: Widget* parent = nullptr; Window* _window = nullptr; - size_t _x{0}; - size_t _y{0}; + int _x{0}; + int _y{0}; size_t _width{0}; size_t _height{0}; -- cgit v1.2.3