[escher/scroll_view] Implement Decorator::indicatorAtIndex explicitly

Instead of using pointer arithmetic
This commit is contained in:
Ruben Dashyan
2019-02-14 16:57:44 +01:00
committed by EmilieNumworks
parent 3487547f16
commit 15de9f93ef
2 changed files with 28 additions and 10 deletions

View File

@@ -46,10 +46,7 @@ public:
public:
BarDecorator();
int numberOfIndicators() const override { return 2; }
View * indicatorAtIndex(int index) override {
assert(0 < index && index <= numberOfIndicators());
return &m_verticalBar + (index-1);
}
View * indicatorAtIndex(int index) override;
KDRect layoutIndicators(KDSize content, KDPoint offset, KDRect frame) override;
ScrollViewVerticalBar * verticalBar() { return &m_verticalBar; }
ScrollViewHorizontalBar * horizontalBar() { return &m_horizontalBar; }
@@ -64,10 +61,7 @@ public:
public:
ArrowDecorator();
int numberOfIndicators() const override { return 4; }
View * indicatorAtIndex(int index) override {
assert(0 < index && index <= numberOfIndicators());
return &m_topArrow + (index-1);
}
View * indicatorAtIndex(int index) override;
KDRect layoutIndicators(KDSize content, KDPoint offset, KDRect frame) override;
void setBackgroundColor(KDColor c) override;
private:

View File

@@ -130,6 +130,16 @@ ScrollView::BarDecorator::BarDecorator() :
{
}
View * ScrollView::BarDecorator::indicatorAtIndex(int index) {
switch(index) {
case 1:
return &m_verticalBar;
default:
assert(index == 2);
return &m_horizontalBar;
}
}
KDRect ScrollView::BarDecorator::layoutIndicators(KDSize content, KDPoint offset, KDRect frame) {
KDCoordinate hBarFrameBreadth = m_barsFrameBreadth * m_horizontalBar.update(
content.width(),
@@ -162,6 +172,20 @@ ScrollView::ArrowDecorator::ArrowDecorator() :
{
}
View * ScrollView::ArrowDecorator::indicatorAtIndex(int index) {
switch(index) {
case 1:
return &m_topArrow;
case 2:
return &m_rightArrow;
case 3:
return &m_bottomArrow;
default:
assert(index == 4);
return &m_leftArrow;
}
}
KDRect ScrollView::ArrowDecorator::layoutIndicators(KDSize content, KDPoint offset, KDRect frame) {
KDSize arrowSize = KDFont::LargeFont->glyphSize();
KDCoordinate topArrowFrameBreadth = arrowSize.height() * m_topArrow.update(0 < offset.y());
@@ -193,8 +217,8 @@ KDRect ScrollView::ArrowDecorator::layoutIndicators(KDSize content, KDPoint offs
}
void ScrollView::ArrowDecorator::setBackgroundColor(KDColor c) {
for (int i = 0; i < numberOfIndicators(); i++) {
(&m_topArrow + i)->setBackgroundColor(c);
for (int index = 1; index <= numberOfIndicators(); index++) {
static_cast<ScrollViewArrow *>(indicatorAtIndex(index))->setBackgroundColor(c);
}
}