[escher/scroll_view] Simplify layoutIndicators

Mark indicators' frame as dirty when necessary, indirectly by setFrame
to empty.
This commit is contained in:
Ruben Dashyan
2019-01-24 11:39:16 +01:00
committed by EmilieNumworks
parent 5b78d65b6d
commit 81f80ef602
3 changed files with 14 additions and 17 deletions

View File

@@ -20,10 +20,10 @@ protected:
class ScrollViewBar : public ScrollViewIndicator {
public:
ScrollViewBar();
void update(KDCoordinate totalContentLength, KDCoordinate contentOffset, KDCoordinate visibleContentLength);
bool visible() const { return 0 < m_offset || m_visibleLength < 1; }
bool update(KDCoordinate totalContentLength, KDCoordinate contentOffset, KDCoordinate visibleContentLength);
protected:
constexpr static KDCoordinate k_indicatorThickness = 4;
bool visible() const { return 0 < m_offset || m_visibleLength < 1; }
float m_offset;
float m_visibleLength;
KDColor m_trackColor;

View File

@@ -153,30 +153,26 @@ ScrollView::Decorator::Decorator() :
}
void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {
m_horizontalBar.update(
KDCoordinate hBarFrameBreadth = m_indicatorThickness * m_horizontalBar.update(
content.width(),
offset.x(),
frame.width()
);
m_verticalBar.update(
KDCoordinate vBarFrameBreadth = m_indicatorThickness * m_verticalBar.update(
content.height(),
offset.y(),
frame.height()
);
/* If the two indicators are visible, we leave an empty rectangle in the right
* bottom corner. Otherwise, the only indicator uses all the height/width. */
if (m_verticalBar.visible()) {
m_verticalBar.setFrame(KDRect(
frame.width() - m_indicatorThickness, 0,
m_indicatorThickness, frame.height() - m_horizontalBar.visible() * m_indicatorThickness
));
}
if (m_horizontalBar.visible()) {
m_horizontalBar.setFrame(KDRect(
0, frame.height() - m_indicatorThickness,
frame.width() - m_verticalBar.visible() * m_indicatorThickness, m_indicatorThickness
));
}
m_verticalBar.setFrame(KDRect(
frame.width() - vBarFrameBreadth, 0,
vBarFrameBreadth, frame.height() - hBarFrameBreadth
));
m_horizontalBar.setFrame(KDRect(
0, frame.height() - hBarFrameBreadth,
frame.width() - vBarFrameBreadth, hBarFrameBreadth
));
}
#if ESCHER_VIEW_LOGGING

View File

@@ -19,7 +19,7 @@ ScrollViewBar::ScrollViewBar() :
{
}
void ScrollViewBar::update(KDCoordinate totalContentLength, KDCoordinate contentOffset, KDCoordinate visibleContentLength) {
bool ScrollViewBar::update(KDCoordinate totalContentLength, KDCoordinate contentOffset, KDCoordinate visibleContentLength) {
float offset = contentOffset;
float visibleLength = visibleContentLength;
offset = offset / totalContentLength;
@@ -29,6 +29,7 @@ void ScrollViewBar::update(KDCoordinate totalContentLength, KDCoordinate content
m_visibleLength = visibleLength;
markRectAsDirty(bounds());
}
return visible();
}
void ScrollViewHorizontalBar::drawRect(KDContext * ctx, KDRect rect) const {