[escher/scroll_view] New Arrow/BarDecorator inherit from Decorator

This commit is contained in:
Ruben Dashyan
2019-01-24 16:40:51 +01:00
committed by EmilieNumworks
parent 1beb8ca98f
commit eb17334050
5 changed files with 25 additions and 18 deletions

View File

@@ -12,8 +12,8 @@ Controller::ContentView::ContentView(Controller * controller, SelectableTableVie
m_selectableTableView.setVerticalCellOverlap(0);
m_selectableTableView.setMargins(0, k_sideMargin, k_bottomMargin, k_sideMargin);
m_selectableTableView.setColorsBackground(false);
m_selectableTableView.decorator()->setBarsFrameBreadth(k_scrollBarsFrameBreadth);
m_selectableTableView.decorator()->verticalBar()->setMargin(k_indicatorMargin);
static_cast<ScrollView::BarDecorator *>(m_selectableTableView.decorator())->setBarsFrameBreadth(k_scrollBarsFrameBreadth);
static_cast<ScrollView::BarDecorator *>(m_selectableTableView.decorator())->verticalBar()->setMargin(k_indicatorMargin);
}
SelectableTableView * Controller::ContentView::selectableTableView() {

View File

@@ -32,7 +32,7 @@ StorageValuesController::StorageValuesController(Responder * parentResponder, In
m_selectableTableView.setBottomMargin(k_bottomMargin);
m_selectableTableView.setLeftMargin(k_leftMargin);
m_selectableTableView.setBackgroundColor(Palette::WallScreenDark);
m_selectableTableView.decorator()->setBarsFrameBreadth(13);
static_cast<ScrollView::BarDecorator *>(m_selectableTableView.decorator())->setBarsFrameBreadth(13);
m_abscissaTitleCell.setMessageFont(k_font);
for (int i = 0; i < k_maxNumberOfAbscissaCells; i++) {
m_abscissaCells[i].setParentResponder(&m_selectableTableView);

View File

@@ -32,7 +32,7 @@ ValuesController::ValuesController(Responder * parentResponder, InputEventHandle
m_selectableTableView.setBottomMargin(k_bottomMargin);
m_selectableTableView.setLeftMargin(k_leftMargin);
m_selectableTableView.setBackgroundColor(Palette::WallScreenDark);
m_selectableTableView.decorator()->setBarsFrameBreadth(13);
static_cast<ScrollView::BarDecorator *>(m_selectableTableView.decorator())->setBarsFrameBreadth(13);
m_abscissaTitleCell.setMessageFont(KDFont::SmallFont);
for (int i = 0; i < k_maxNumberOfAbscissaCells; i++) {
m_abscissaCells[i].setParentResponder(&m_selectableTableView);

View File

@@ -27,13 +27,20 @@ public:
class Decorator {
public:
Decorator();
int numberOfIndicators() { return 2; }
View * indicatorAtIndex(int index) {
virtual int numberOfIndicators() { return 0; }
virtual View * indicatorAtIndex(int index) { assert(false); return nullptr; }
virtual void layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {}
};
class BarDecorator : public Decorator {
public:
BarDecorator();
int numberOfIndicators() override { return 2; }
View * indicatorAtIndex(int index) override {
assert(0 < index && index <= numberOfIndicators());
return &m_verticalBar + (index-1);
}
void layoutIndicators(KDSize content, KDPoint offset, KDSize frame);
void layoutIndicators(KDSize content, KDPoint offset, KDSize frame) override;
ScrollViewVerticalBar * verticalBar() { return &m_verticalBar; }
ScrollViewHorizontalBar * horizontalBar() { return &m_horizontalBar; }
void setBarsFrameBreadth(KDCoordinate t) { m_barsFrameBreadth = t; }
@@ -43,15 +50,15 @@ public:
KDCoordinate m_barsFrameBreadth;
};
class DecoratorV2 {
class ArrowDecorator : public Decorator {
public:
DecoratorV2();
int numberOfIndicators() { return 4; }
View * indicatorAtIndex(int index) {
ArrowDecorator();
int numberOfIndicators() override { return 4; }
View * indicatorAtIndex(int index) override {
assert(0 < index && index <= numberOfIndicators());
return &m_topArrow + (index-1);
}
void layoutIndicators(KDSize content, KDPoint offset, KDSize frame);
void layoutIndicators(KDSize content, KDPoint offset, KDSize frame) override;
private:
ScrollViewArrow m_topArrow;
ScrollViewArrow m_rightArrow;
@@ -93,7 +100,7 @@ private:
KDCoordinate m_bottomMargin;
KDCoordinate m_leftMargin;
Decorator m_decorator;
BarDecorator m_decorator;
bool m_showsIndicators;
bool m_colorsBackground;
KDColor m_backgroundColor;

View File

@@ -145,14 +145,14 @@ KDCoordinate ScrollView::maxContentHeightDisplayableWithoutScrolling() {
return m_frame.height() - m_topMargin - m_bottomMargin;
}
ScrollView::Decorator::Decorator() :
ScrollView::BarDecorator::BarDecorator() :
m_verticalBar(),
m_horizontalBar(),
m_barsFrameBreadth(20)
{
}
void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {
void ScrollView::BarDecorator::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {
KDCoordinate hBarFrameBreadth = m_barsFrameBreadth * m_horizontalBar.update(
content.width(),
offset.x(),
@@ -175,7 +175,7 @@ void ScrollView::Decorator::layoutIndicators(KDSize content, KDPoint offset, KDS
));
}
ScrollView::DecoratorV2::DecoratorV2() :
ScrollView::ArrowDecorator::ArrowDecorator() :
m_topArrow(ScrollViewArrow::Side::Top),
m_rightArrow(ScrollViewArrow::Side::Right),
m_bottomArrow(ScrollViewArrow::Side::Bottom),
@@ -183,7 +183,7 @@ ScrollView::DecoratorV2::DecoratorV2() :
{
}
void ScrollView::DecoratorV2::layoutIndicators(KDSize content, KDPoint offset, KDSize frame) {
void ScrollView::ArrowDecorator::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());