mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher/scroll_view] Implement Decorator::indicatorAtIndex explicitly
Instead of using pointer arithmetic
This commit is contained in:
committed by
EmilieNumworks
parent
3487547f16
commit
15de9f93ef
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user