diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index 254ef7359..362bbf692 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -3,11 +3,13 @@ #include #include +#include class ScrollView : public View { public: ScrollView(View * contentView, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, - KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0, bool showIndicators = true); + KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0, bool showIndicators = true, + bool colorBackground = true, KDColor backgroundColor = Palette::BackgroundColor); void setContentOffset(KDPoint offset); KDPoint contentOffset(); @@ -39,6 +41,8 @@ private: KDCoordinate m_bottomMargin; KDCoordinate m_leftMargin; bool m_showIndicators; + bool m_colorBackground; + KDColor m_backgroundColor; }; #endif diff --git a/escher/include/escher/selectable_table_view.h b/escher/include/escher/selectable_table_view.h index e41f47946..e596651f6 100644 --- a/escher/include/escher/selectable_table_view.h +++ b/escher/include/escher/selectable_table_view.h @@ -5,6 +5,7 @@ #include #include #include +#include #include /* SelectableTableView is a Table View that handles selection. To implement it, @@ -17,7 +18,8 @@ class SelectableTableView : public TableView, public Responder { public: SelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, - KDCoordinate leftMargin = 0, SelectableTableViewDelegate * delegate = nullptr); + KDCoordinate leftMargin = 0, SelectableTableViewDelegate * delegate = nullptr, + bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::BackgroundColor); int selectedRow(); int selectedColumn(); virtual bool handleEvent(Ion::Events::Event event) override; diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 5f11c1cf6..c36aff748 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -1,6 +1,7 @@ #ifndef ESCHER_TABLE_VIEW_H #define ESCHER_TABLE_VIEW_H +#include #include #include #include @@ -8,7 +9,8 @@ class TableView : public ScrollView { public: TableView(TableViewDataSource * dataSource, KDCoordinate topMargin = 0, - KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); + KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0, + bool showIndicators = true, bool colorBackground = true, KDColor backgroundColor = Palette::BackgroundColor); virtual void scrollToCell(int i, int j); TableViewCell * cellAtLocation(int i, int j); diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index ceeceec38..2f21f4712 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -1,5 +1,4 @@ #include -#include extern "C" { #include @@ -8,7 +7,8 @@ extern "C" { constexpr KDCoordinate ScrollView::k_indicatorThickness; ScrollView::ScrollView(View * contentView, KDCoordinate topMargin, KDCoordinate rightMargin, - KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators) : + KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators, bool colorBackground, + KDColor backgroundColor) : View(), m_topMargin(topMargin), m_offset(KDPointZero), @@ -18,9 +18,12 @@ ScrollView::ScrollView(View * contentView, KDCoordinate topMargin, KDCoordinate m_rightMargin(rightMargin), m_bottomMargin(bottomMargin), m_leftMargin(leftMargin), - m_showIndicators(showIndicators) + m_showIndicators(showIndicators), + m_colorBackground(colorBackground), + m_backgroundColor(backgroundColor) { } + bool ScrollView::hasVerticalIndicator() const { if (m_showIndicators) { return m_verticalScrollIndicator.end() < 1 || m_verticalScrollIndicator.start() > 0; @@ -52,9 +55,12 @@ View * ScrollView::subviewAtIndex(int index) { } void ScrollView::drawRect(KDContext * ctx, KDRect rect) const { + if (!m_colorBackground) { + return; + } KDCoordinate width = bounds().width(); KDCoordinate height = bounds().height(); - ctx->fillRect(KDRect(0, 0, width, height), Palette::BackgroundColor); + ctx->fillRect(KDRect(0, 0, width, height), m_backgroundColor); // Future optimization: avoid drawing behind the content view/ //ctx->fillRect(KDRect(m_leftMargin, m_contentView->bounds().height()+m_topMargin, width-m_leftMargin-m_rightMargin, height- m_contentView->bounds().height())-m_topMargin, Palette::BackgroundColor); } diff --git a/escher/src/selectable_table_view.cpp b/escher/src/selectable_table_view.cpp index 85b736a12..5b0355d5c 100644 --- a/escher/src/selectable_table_view.cpp +++ b/escher/src/selectable_table_view.cpp @@ -1,9 +1,10 @@ #include SelectableTableView::SelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource, - KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin, - SelectableTableViewDelegate * delegate) : - TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin), + KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin, + SelectableTableViewDelegate * delegate, bool showIndicators, bool colorBackground, + KDColor backgroundColor) : + TableView(dataSource, topMargin, rightMargin, bottomMargin, leftMargin, showIndicators, colorBackground, backgroundColor), Responder(parentResponder), m_delegate(delegate), m_selectedCellX(0), diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index f8d69711e..714e13f71 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -8,8 +8,10 @@ extern "C" { #define MIN(x,y) ((x)<(y) ? (x) : (y)) TableView::TableView(TableViewDataSource * dataSource, KDCoordinate topMargin, KDCoordinate rightMargin, - KDCoordinate bottomMargin, KDCoordinate leftMargin) : - ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin), + KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators, bool colorBackground, + KDColor backgroundColor) : + ScrollView(&m_contentView, topMargin, rightMargin, bottomMargin, leftMargin, showIndicators, colorBackground, + backgroundColor), m_contentView(TableView::ContentView(this, dataSource)) { }