Numworks Epsilon  1.4.1
Graphing Calculator Operating System
selectable_table_view.cpp
Go to the documentation of this file.
2 
3 namespace Calculation {
4 
6  SelectableTableViewDataSource * selectionDataSource, SelectableTableViewDelegate * delegate) :
7  ::SelectableTableView(parentResponder, dataSource, selectionDataSource, delegate)
8 {
10  setMargins(0);
11  setShowsIndicators(false);
12 }
13 
16  if (m_contentView.bounds().height() < bounds().height()) {
17  setTopMargin(bounds().height() - m_contentView.bounds().height());
18  } else {
19  setTopMargin(0);
20  }
22  if (m_contentView.bounds().height() - contentOffset().y() < bounds().height()) {
23  KDCoordinate contentOffsetX = contentOffset().x();
25  setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
26  }
27  if (dataSource()->numberOfRows() > j && dataSource()->numberOfColumns() > i && dataSource()->rowHeight(j) > bounds().height()) {
28  KDCoordinate contentOffsetX = contentOffset().x();
29  KDCoordinate contentOffsetY = contentOffset().y();
30  if (contentOffsetY > dataSource()->cumulatedHeightFromIndex(j) && contentOffsetY > dataSource()->cumulatedHeightFromIndex(j+1)) {
31  // Let's scroll the tableView to align the top of the cell to the top
32  contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
33  } else {
34  // Let's scroll the tableView to align the bottom of the cell to the bottom
36  }
37  setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
38  }
39 }
40 
42  if (dataSource()->rowHeight(j) <= bounds().height()) {
43  return;
44  }
45  /* As we scroll, the selected calculation does not use the same history view
46  * cell, thus, we want to deselect the previous used history view cell. */
47  if (selectedRow() >= 0) {
48  HighlightCell * previousCell = selectedCell();
49  previousCell->setHighlighted(false);
50  }
51  /* Main part of the scroll */
52  KDCoordinate contentOffsetX = contentOffset().x();
54  if (subviewType == HistoryViewCell::SubviewType::Input) {
55  if (j == 0) {
56  contentOffsetY = 0;
57  } else {
58  contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
59  }
60  }
61  /* For the same reason, we have to rehighlight the new history view cell and
62  * inform the delegate which history view cell is highlighted even if the
63  * selected calculation has not changed. */
64  setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
65  HighlightCell * cell = cellAtLocation(i, j);
66  cell->setHighlighted(true);
67  if (m_delegate) {
69  }
70 }
71 
72 
73 }
KDCoordinate maxContentHeightDisplayableWithoutScrolling()
void setShowsIndicators(bool s)
Definition: scroll_view.h:28
KDCoordinate y() const
Definition: point.h:11
void scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType subviewType, int i, int j)
HighlightCell * selectedCell()
int16_t KDCoordinate
Definition: coordinate.h:6
SelectableTableViewDelegate * m_delegate
virtual void tableViewDidChangeSelection(SelectableTableView *t, int previousSelectedCellX, int previousSelectedCellY)
void setVerticalCellOverlap(KDCoordinate o)
Definition: table_view.h:14
virtual void scrollToCell(int i, int j)
Definition: table_view.cpp:26
HighlightCell * cellAtLocation(int i, int j)
Definition: table_view.cpp:30
void layoutSubviews() override
Definition: point.h:6
TableViewDataSource * dataSource()
Definition: table_view.cpp:20
void setTopMargin(KDCoordinate m)
Definition: scroll_view.h:13
constexpr uint8_t numberOfColumns
Definition: keyboard.h:39
CalculationSelectableTableView(Responder *parentResponder, TableViewDataSource *dataSource, SelectableTableViewDataSource *selectionDataSource, SelectableTableViewDelegate *delegate=nullptr)
virtual KDCoordinate cumulatedHeightFromIndex(int j)=0
void setContentOffset(KDPoint offset, bool forceRelayout=false)
void setMargins(KDCoordinate top, KDCoordinate right, KDCoordinate bottom, KDCoordinate left)
Definition: scroll_view.h:22
KDPoint contentOffset() const
Definition: scroll_view.h:41
ContentView m_contentView
Definition: table_view.h:73
constexpr uint8_t numberOfRows
Definition: keyboard.h:35
KDCoordinate x() const
Definition: point.h:10
virtual void setHighlighted(bool highlight)
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157