From d83c101a33a4bce53dfc5157b1924dec8db72ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 28 Oct 2016 17:25:53 +0200 Subject: [PATCH] [apps/calculation] Create a specific table view for calculation which aligns to the bottom Change-Id: I4fe9763b1d9ae2ae3e898046221b780c51515830 --- apps/calculation/Makefile | 1 + apps/calculation/selectable_table_view.cpp | 26 ++++++++++++++++++++++ apps/calculation/selectable_table_view.h | 17 ++++++++++++++ escher/include/escher/scroll_view.h | 2 +- escher/include/escher/table_view.h | 8 +++---- escher/src/scroll_view.cpp | 2 +- 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 apps/calculation/selectable_table_view.cpp create mode 100644 apps/calculation/selectable_table_view.h diff --git a/apps/calculation/Makefile b/apps/calculation/Makefile index c6d00dea5..91c0e452e 100644 --- a/apps/calculation/Makefile +++ b/apps/calculation/Makefile @@ -2,6 +2,7 @@ app_objs += $(addprefix apps/calculation/,\ app.o\ calculation.o\ calculation_store.o\ + selectable_table_view.o\ history_view_cell.o\ history_controller.o\ edit_expression_controller.o\ diff --git a/apps/calculation/selectable_table_view.cpp b/apps/calculation/selectable_table_view.cpp new file mode 100644 index 000000000..e4bd1293e --- /dev/null +++ b/apps/calculation/selectable_table_view.cpp @@ -0,0 +1,26 @@ +#include "selectable_table_view.h" + +namespace Calculation { + +CalculationSelectableTableView::CalculationSelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource, + SelectableTableViewDelegate * delegate) : + ::SelectableTableView(parentResponder, dataSource, 0, 0, 0, 0, delegate) +{ +} + +void CalculationSelectableTableView::scrollToCell(int i, int j) { + ::SelectableTableView::scrollToCell(i, j); + if (m_contentView.bounds().height() < bounds().height()) { + m_topMargin = bounds().height() - m_contentView.bounds().height(); + } else { + m_topMargin = 0; + } + ScrollView::layoutSubviews(); + if (m_contentView.bounds().height() - contentOffset().y() < bounds().height()) { + KDCoordinate contentOffsetX = contentOffset().x(); + KDCoordinate contentOffsetY = dataSource()->cumulatedHeightFromIndex(dataSource()->numberOfRows()) - maxContentHeightDisplayableWithoutScrolling(); + setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); + } +} + +} \ No newline at end of file diff --git a/apps/calculation/selectable_table_view.h b/apps/calculation/selectable_table_view.h new file mode 100644 index 000000000..8f036f246 --- /dev/null +++ b/apps/calculation/selectable_table_view.h @@ -0,0 +1,17 @@ +#ifndef CALCULATION_SELECTABLE_TABLE_VIEW_H +#define CALCULATION_SELECTABLE_TABLE_VIEW_H + +#include + +namespace Calculation { + +class CalculationSelectableTableView : public ::SelectableTableView { +public: + CalculationSelectableTableView(Responder * parentResponder, TableViewDataSource * dataSource, + SelectableTableViewDelegate * delegate = nullptr); + void scrollToCell(int i, int j) override; +}; + +} + +#endif diff --git a/escher/include/escher/scroll_view.h b/escher/include/escher/scroll_view.h index a9bee0527..254ef7359 100644 --- a/escher/include/escher/scroll_view.h +++ b/escher/include/escher/scroll_view.h @@ -19,6 +19,7 @@ protected: KDCoordinate maxContentHeightDisplayableWithoutScrolling(); void layoutSubviews() override; void updateScrollIndicator(); + KDCoordinate m_topMargin; #if ESCHER_VIEW_LOGGING virtual const char * className() const override; virtual void logAttributes(std::ostream &os) const override; @@ -34,7 +35,6 @@ private: ScrollViewIndicator m_horizontalScrollIndicator; bool hasVerticalIndicator() const; bool hasHorizontalIndicator() const; - KDCoordinate m_topMargin; KDCoordinate m_rightMargin; KDCoordinate m_bottomMargin; KDCoordinate m_leftMargin; diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index bfd50fb46..5f11c1cf6 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -10,7 +10,7 @@ public: TableView(TableViewDataSource * dataSource, KDCoordinate topMargin = 0, KDCoordinate rightMargin = 0, KDCoordinate bottomMargin = 0, KDCoordinate leftMargin = 0); - void scrollToCell(int i, int j); + virtual void scrollToCell(int i, int j); TableViewCell * cellAtLocation(int i, int j); void reloadData(); KDSize size() const; @@ -19,7 +19,6 @@ protected: const char * className() const override; #endif TableViewDataSource * dataSource(); -private: class ContentView : public View { public: ContentView(TableView * tableView, TableViewDataSource * dataSource); @@ -65,10 +64,9 @@ private: TableView * m_tableView; TableViewDataSource * m_dataSource; }; - - void layoutSubviews() override; - ContentView m_contentView; +private: + void layoutSubviews() override; }; #endif diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index 5f346806c..ceeceec38 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -10,11 +10,11 @@ constexpr KDCoordinate ScrollView::k_indicatorThickness; ScrollView::ScrollView(View * contentView, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin, bool showIndicators) : View(), + m_topMargin(topMargin), m_offset(KDPointZero), m_contentView(contentView), m_verticalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Vertical)), m_horizontalScrollIndicator(ScrollViewIndicator(ScrollViewIndicator::Direction::Horizontal)), - m_topMargin(topMargin), m_rightMargin(rightMargin), m_bottomMargin(bottomMargin), m_leftMargin(leftMargin),