From 917d35d6cbea488f07596d0403d0bef8d6413f8a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 27 May 2015 17:35:08 +0300 Subject: Improve a bit basiccontainer. --- src/gui/widgets/basiccontainer.cpp | 35 ++++++++++++++++------------------- src/gui/widgets/basiccontainer.h | 3 ++- src/gui/widgets/scrollarea.cpp | 2 +- src/gui/widgets/scrollarea.h | 3 ++- src/gui/widgets/widget.h | 2 +- 5 files changed, 22 insertions(+), 23 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp index 96dfffef7..e8f29ff9b 100644 --- a/src/gui/widgets/basiccontainer.cpp +++ b/src/gui/widgets/basiccontainer.cpp @@ -382,38 +382,35 @@ void BasicContainer::logicChildren() BLOCK_END("BasicContainer::logicChildren") } -void BasicContainer::showWidgetPart(Widget *const widget, Rect area) +void BasicContainer::showWidgetPart(Widget *const widget, const Rect &area) { const Rect widgetArea = getChildrenArea(); const int x = widget->mDimension.x; const int y = widget->mDimension.y; - area.x += x; - area.y += y; - - if (area.x + area.width > widgetArea.width) - widget->setX(x - area.x - area.width + widgetArea.width); - - if (area.y + area.height > widgetArea.height) - widget->setY(y - area.y - area.height + widgetArea.height); - - if (area.x < 0) - widget->setX(x - area.x); - - if (area.y < 0) - widget->setY(y - area.y); + const int ax = area.x + x; + const int ay = area.y + y; + + if (ax < 0) + widget->setX(-area.x); + else if (ax + area.width > widgetArea.width) + widget->setX(widgetArea.width - area.x - area.width); + + if (ay < 0) + widget->setY(-area.y); + else if (ay + area.height > widgetArea.height) + widget->setY(widgetArea.height - area.y - area.height); } void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler) { Widget::setInternalFocusHandler(focusHandler); + FocusHandler *handler = mInternalFocusHandler ? + mInternalFocusHandler : getFocusHandler(); FOR_EACH (WidgetListConstIterator, iter, mWidgets) { - if (!mInternalFocusHandler) - (*iter)->setFocusHandler(getFocusHandler()); - else - (*iter)->setFocusHandler(mInternalFocusHandler); + (*iter)->setFocusHandler(handler); } } diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h index ecc79cba2..ec4a39115 100644 --- a/src/gui/widgets/basiccontainer.h +++ b/src/gui/widgets/basiccontainer.h @@ -105,7 +105,8 @@ class BasicContainer notfinal : public Widget, * itself to be visible. * @param rectangle The rectangle to be visible. */ - void showWidgetPart(Widget *const widget, Rect area) override; + void showWidgetPart(Widget *const widget, + const Rect &area) override; // Inherited from Widget diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 1eb5417e8..23b681907 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -1275,7 +1275,7 @@ void ScrollArea::setScrollbarWidth(const int width) mScrollbarWidth = width; } -void ScrollArea::showWidgetPart(Widget *const widget, Rect area) +void ScrollArea::showWidgetPart(Widget *const widget, const Rect &area) { const Widget *const content = getContent(); if (widget != content) diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index d166f235c..deb24ff79 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -412,7 +412,8 @@ class ScrollArea final : public BasicContainer, int getDownButtonScrollAmount() const { return mDownButtonScrollAmount; } - void showWidgetPart(Widget *const widget, Rect area) override final; + void showWidgetPart(Widget *const widget, + const Rect &area) override final; Rect getChildrenArea() override final; diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h index 7c3134302..2c8c121e0 100644 --- a/src/gui/widgets/widget.h +++ b/src/gui/widgets/widget.h @@ -968,7 +968,7 @@ class Widget notfinal : public Widget2 * @since 0.1.0 */ virtual void showWidgetPart(Widget *const widget A_UNUSED, - Rect area A_UNUSED) + const Rect &area A_UNUSED) { } /** -- cgit v1.2.3-70-g09d2