diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index 0c2d3f4b8..aa9c9e8b9 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -15,6 +15,7 @@ protected: KDCoordinate maxContentWidthDisplayableWithoutScrolling(); KDCoordinate maxContentHeightDisplayableWithoutScrolling(); void layoutSubviews() override; + void updateScrollIndicator(); #if ESCHER_VIEW_LOGGING virtual const char * className() const override; virtual void logAttributes(std::ostream &os) const override; diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index 7ab250f74..ea86084c3 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -56,18 +56,22 @@ void ScrollView::layoutSubviews() { KDPoint absoluteOffset = m_offset.opposite().translatedBy(KDPoint(m_leftMargin, m_topMargin)); KDRect contentFrame = KDRect(absoluteOffset, m_contentView->bounds().size()); m_contentView->setFrame(contentFrame); + + // We recompute the size of the scroll indicator + updateScrollIndicator(); +} + +void ScrollView::updateScrollIndicator() { + float contentHeight = m_contentView->bounds().height()+m_topMargin+m_bottomMargin; + float start = m_offset.y(); + float end = m_offset.y() + m_frame.height(); + + m_verticalScrollIndicator.setStart(start/contentHeight); + m_verticalScrollIndicator.setEnd(end/contentHeight); } void ScrollView::setContentOffset(KDPoint offset) { m_offset = offset; - - float contentHeight = m_contentView->bounds().height()+m_topMargin+m_bottomMargin; - float start = offset.y(); - float end = offset.y() + m_frame.height(); - - m_verticalScrollIndicator.setStart(start/contentHeight); - m_verticalScrollIndicator.setEnd(end/contentHeight); - layoutSubviews(); }