[apps/shared] Make StorageExpressionModelListController

SelectableTableViewDelegate instead of StorageFunctionListController
This commit is contained in:
Émilie Feral
2019-02-22 16:11:53 +01:00
parent 83153dd511
commit d6f5f1bbea
4 changed files with 13 additions and 12 deletions

View File

@@ -14,23 +14,23 @@ StorageExpressionModelListController::StorageExpressionModelListController(Respo
m_addNewModel.setMessage(text);
}
void StorageExpressionModelListController::tableSelectionDidChange(int previousSelectedRow) {
void StorageExpressionModelListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
int currentSelectedRow = selectedRow();
// Update m_cumulatedHeightForSelectedIndex if we scrolled one cell up/down
if (previousSelectedRow >= 0 && currentSelectedRow == previousSelectedRow + 1) {
if (previousSelectedCellY >= 0 && previousSelectedCellY == previousSelectedCellY + 1) {
/* We selected the cell under the previous cell. Shift the memoized cell
* heights. */
shiftMemoization(true);
resetMemoizationForIndex(k_memoizedCellsCount-1);
// Update m_cumulatedHeightForSelectedIndex
if (previousSelectedRow >= 0) {
m_cumulatedHeightForSelectedIndex+= memoizedRowHeight(previousSelectedRow);
if (previousSelectedCellY >= 0) {
m_cumulatedHeightForSelectedIndex+= memoizedRowHeight(previousSelectedCellY);
} else {
assert(currentSelectedRow == 0);
m_cumulatedHeightForSelectedIndex = 0;
}
} else if (currentSelectedRow >= 0 && currentSelectedRow == previousSelectedRow - 1) {
} else if (currentSelectedRow >= 0 && currentSelectedRow == previousSelectedCellY - 1) {
/* We selected the cell above the previous cell. Shift the memoized cell
* heights. */
shiftMemoization(false);

View File

@@ -7,17 +7,18 @@
namespace Shared {
class StorageExpressionModelListController : public ViewController, public SelectableTableViewDataSource {
class StorageExpressionModelListController : public ViewController, public SelectableTableViewDataSource, public SelectableTableViewDelegate {
public:
StorageExpressionModelListController(Responder * parentResponder, I18n::Message text);
protected:
static constexpr KDCoordinate k_expressionMargin = 5;
// Memoization of cell heights
void tableSelectionDidChange(int previousSelectedRow);
KDCoordinate memoizedRowHeight(int j);
KDCoordinate memoizedCumulatedHeightFromIndex(int j);
// SelectableTableViewDelegate
void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) override;
// TableViewDataSource
virtual int numberOfExpressionRows();
KDCoordinate memoizedRowHeight(int j);
KDCoordinate memoizedCumulatedHeightFromIndex(int j);
int memoizedIndexFromCumulatedHeight(KDCoordinate offsetY);
virtual KDCoordinate expressionRowHeight(int j);
virtual void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j);
// Responder

View File

@@ -260,7 +260,7 @@ void StorageFunctionListController::willExitResponderChain(Responder * nextFirst
void StorageFunctionListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
// Update memoization of cell heights
StorageExpressionModelListController::tableSelectionDidChange(previousSelectedCellY);
StorageExpressionModelListController::tableViewDidChangeSelection(t, previousSelectedCellX, previousSelectedCellY);
// Do not select the cell left of the "addEmptyFunction" cell
if (isAddEmptyRow(selectedRow()) && selectedColumn() == 0) {
t->selectCellAtLocation(1, numberOfRows()-1);

View File

@@ -11,7 +11,7 @@
namespace Shared {
class StorageFunctionListController : public StorageExpressionModelListController, public ButtonRowDelegate, public TableViewDataSource, public SelectableTableViewDelegate {
class StorageFunctionListController : public StorageExpressionModelListController, public ButtonRowDelegate, public TableViewDataSource {
public:
StorageFunctionListController(Responder * parentResponder, ButtonRowController * header, ButtonRowController * footer, I18n::Message text);