diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index d47408f71..611a87311 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -43,6 +43,22 @@ public: KDCoordinate m_barsFrameBreadth; }; + class DecoratorV2 { + public: + DecoratorV2(); + int numberOfIndicators() { return 4; } + View * indicatorAtIndex(int index) { + assert(0 < index && index <= numberOfIndicators()); + return &m_topArrow + (index-1); + } + void layoutIndicators(KDSize content, KDPoint offset, KDSize frame); + private: + ScrollViewArrow m_topArrow; + ScrollViewArrow m_rightArrow; + ScrollViewArrow m_bottomArrow; + ScrollViewArrow m_leftArrow; + }; + Decorator * decorator() { return &m_decorator; } void setShowsIndicators(bool s) { m_showsIndicators = s; } bool showsIndicators() const { return m_showsIndicators; } diff --git a/escher/include/escher/scroll_view_indicator.h b/escher/include/escher/scroll_view_indicator.h index 31641cab1..6744d6974 100644 --- a/escher/include/escher/scroll_view_indicator.h +++ b/escher/include/escher/scroll_view_indicator.h @@ -43,4 +43,21 @@ private: KDCoordinate totalLength() const { return m_frame.height() - 2*m_margin; } }; +class ScrollViewArrow : public ScrollViewIndicator { +public: + enum Side : char { //FIXME + Top = 't', + Right = '>', + Bottom = 'b', + Left = '<' + }; + ScrollViewArrow(Side side); + bool update(bool visible); + void drawRect(KDContext * ctx, KDRect rect) const override; +private: + bool m_visible; + const char m_arrow; + KDColor m_backgroundColor; +}; + #endif diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index caa271a3d..806138462 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -175,6 +175,38 @@ void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDS )); } +ScrollView::DecoratorV2::DecoratorV2() : + m_topArrow(ScrollViewArrow::Side::Top), + m_rightArrow(ScrollViewArrow::Side::Right), + m_bottomArrow(ScrollViewArrow::Side::Bottom), + m_leftArrow(ScrollViewArrow::Side::Left) +{ +} + +void ScrollView::DecoratorV2::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) { + KDSize arrowSize = KDFont::LargeFont->glyphSize(); + KDCoordinate topArrowFrameBreadth = arrowSize.height() * m_topArrow.update(0 < offset.y()); + KDCoordinate rightArrowFrameBreadth = arrowSize.width() * m_rightArrow.update(offset.x() + frame.width() < content.width()); + KDCoordinate bottomArrowFrameBreadth = arrowSize.height() * m_bottomArrow.update(offset.y() + frame.height() < content.height()); + KDCoordinate leftArrowFrameBreadth = arrowSize.width() * m_leftArrow.update(0 < offset.x()); + m_topArrow.setFrame(KDRect( + 0, 0, + frame.width(), topArrowFrameBreadth + )); + m_rightArrow.setFrame(KDRect( + frame.width() - rightArrowFrameBreadth, 0, + rightArrowFrameBreadth, frame.height() + )); + m_bottomArrow.setFrame(KDRect( + 0, frame.height() - bottomArrowFrameBreadth, + frame.width(), bottomArrowFrameBreadth + )); + m_leftArrow.setFrame(KDRect( + 0, 0, + leftArrowFrameBreadth, frame.height() + )); +} + #if ESCHER_VIEW_LOGGING const char * ScrollView::className() const { return "ScrollView"; diff --git a/escher/src/scroll_view_indicator.cpp b/escher/src/scroll_view_indicator.cpp index 56b7e2f1c..6786566ca 100644 --- a/escher/src/scroll_view_indicator.cpp +++ b/escher/src/scroll_view_indicator.cpp @@ -72,6 +72,30 @@ void ScrollViewVerticalBar::drawRect(KDContext * ctx, KDRect rect) const { ); } +ScrollViewArrow::ScrollViewArrow(Side side) : + m_visible(false), + m_arrow(side) +{ +} + +bool ScrollViewArrow::update(bool visible) { + if (m_visible != visible) { + markRectAsDirty(bounds()); + } + m_visible = visible; + return visible; +} + +void ScrollViewArrow::drawRect(KDContext * ctx, KDRect rect) const { + ctx->fillRect(bounds(), m_backgroundColor); + KDSize arrowSize = KDFont::LargeFont->glyphSize(); + const KDPoint arrowAlign = KDPoint( + (m_arrow == Top || m_arrow == Bottom) * (m_frame.width() - arrowSize.width()) / 2, + (m_arrow == Left || m_arrow == Right) * (m_frame.height() - arrowSize.height()) / 2 + ); + ctx->drawString(&m_arrow, arrowAlign, KDFont::LargeFont, m_color, m_backgroundColor, m_visible); +} + #if ESCHER_VIEW_LOGGING const char * ScrollViewIndicator::className() const { return "ScrollViewIndicator";