From 5b78d65b6d8710bf4637d7e4ea3f0f5bc1b25ac9 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Wed, 23 Jan 2019 18:06:01 +0100 Subject: [PATCH] [escher/scroll_view] Simplify subviews management --- escher/include/escher/scroll_view.h | 7 +++++-- escher/src/scroll_view.cpp | 18 ------------------ escher/src/scroll_view_indicator.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index dcd2096e8..2a5b2c1aa 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -28,8 +28,11 @@ public: class Decorator { public: Decorator(); - int numberOfIndicators(); - View * indicatorAtIndex(int index); + int numberOfIndicators() { return 2; } + View * indicatorAtIndex(int index) { + assert(0 < index && index <= numberOfIndicators()); + return &m_verticalBar + (index-1); + } void layoutIndicators(KDSize content, KDPoint offset, KDSize frame); ScrollViewVerticalBar * verticalBar() { return &m_verticalBar; } ScrollViewHorizontalBar * horizontalBar() { return &m_horizontalBar; } diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index 5a70f135d..2e6d40319 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -152,24 +152,6 @@ ScrollView::Decorator::Decorator() : { } -int ScrollView::Decorator::numberOfIndicators() { - return m_verticalBar.visible() + m_horizontalBar.visible(); -} - -View * ScrollView::Decorator::indicatorAtIndex(int index) { - switch (index) { - case 1: - if (m_horizontalBar.visible()) { - return &m_horizontalBar; - } else { - return &m_verticalBar; - } - case 2: - return &m_verticalBar; - } - return nullptr; -} - void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) { m_horizontalBar.update( content.width(), diff --git a/escher/src/scroll_view_indicator.cpp b/escher/src/scroll_view_indicator.cpp index c8c46acb7..4374e5e6f 100644 --- a/escher/src/scroll_view_indicator.cpp +++ b/escher/src/scroll_view_indicator.cpp @@ -32,6 +32,9 @@ void ScrollViewBar::update(KDCoordinate totalContentLength, KDCoordinate content } void ScrollViewHorizontalBar::drawRect(KDContext * ctx, KDRect rect) const { + if (!visible()) { + return; + } ctx->fillRect( KDRect( m_margin, (m_frame.height() - k_indicatorThickness)/2, @@ -49,6 +52,9 @@ void ScrollViewHorizontalBar::drawRect(KDContext * ctx, KDRect rect) const { } void ScrollViewVerticalBar::drawRect(KDContext * ctx, KDRect rect) const { + if (!visible()) { + return; + } ctx->fillRect( KDRect( (m_frame.width() - k_indicatorThickness)/2, m_margin,