[escher] TableViewDataSource: implement default cumulatedWidthFromIndex,

cumulatedWidthFromIndex, indexFromCumulatedWidth,
indexFromCumulatedHeight
This commit is contained in:
Émilie Feral
2018-06-06 17:15:46 +02:00
parent 2d580faf51
commit f6bdf56c15
12 changed files with 38 additions and 91 deletions

View File

@@ -132,23 +132,6 @@ KDCoordinate CalculationController::rowHeight(int j) {
return ResponderImageCell::k_oneCellHeight;
}
KDCoordinate CalculationController::cumulatedWidthFromIndex(int j) {
int result = 0;
for (int k = 0; k < j; k++) {
result += columnWidth(k);
}
return result;
}
int CalculationController::indexFromCumulatedWidth(KDCoordinate offsetX) {
int result = 0;
int i = 0;
while (result < offsetX && i < numberOfColumns()) {
result += columnWidth(i++);
}
return (result < offsetX || offsetX == 0) ? i : i - 1;
}
KDCoordinate CalculationController::cumulatedHeightFromIndex(int j) {
return rowHeight(0) * j;
}

View File

@@ -29,9 +29,7 @@ public:
int numberOfColumns() override;
KDCoordinate columnWidth(int i) override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;

View File

@@ -30,23 +30,6 @@ KDCoordinate ExpressionModelListController::expressionRowHeight(int j) {
return modelSize + Metric::StoreRowHeight - KDText::charSize().height();
}
KDCoordinate ExpressionModelListController::cumulatedExpressionHeightFromIndex(int j) {
int result = 0;
for (int k = 0; k < j; k++) {
result += expressionRowHeight(k);
}
return result;
}
int ExpressionModelListController::indexFromCumulatedExpressionHeight(KDCoordinate offsetY) {
int result = 0;
int j = 0;
while (result < offsetY && j < numberOfExpressionRows()) {
result += expressionRowHeight(j++);
}
return (result < offsetY || offsetY == 0) ? j : j - 1;
}
void ExpressionModelListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) {
EvenOddExpressionCell * myCell = (EvenOddExpressionCell *)cell;
ExpressionModel * m = modelStore()->modelAtIndex(j);

View File

@@ -14,8 +14,6 @@ protected:
/* Table Data Source */
virtual int numberOfExpressionRows();
virtual KDCoordinate expressionRowHeight(int j);
KDCoordinate cumulatedExpressionHeightFromIndex(int j);
int indexFromCumulatedExpressionHeight(KDCoordinate offsetY);
virtual void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j);
/* Responder */
bool handleEventOnExpression(Ion::Events::Event event);

View File

@@ -23,13 +23,7 @@ public:
return expressionRowHeight(j);
}
KDCoordinate columnWidth(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override {
return cumulatedExpressionHeightFromIndex(j);
}
KDCoordinate cumulatedWidthFromIndex(int i) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override {
return indexFromCumulatedExpressionHeight(offsetY);
}
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int typeAtLocation(int i, int j) override;
HighlightCell * reusableCell(int index, int type) override;

View File

@@ -22,12 +22,6 @@ public:
int numberOfRows() override {
return numberOfExpressionRows();
}
KDCoordinate cumulatedHeightFromIndex(int j) override {
return cumulatedExpressionHeightFromIndex(j);
}
int indexFromCumulatedHeight(KDCoordinate offsetY) override {
return indexFromCumulatedExpressionHeight(offsetY);
}
KDCoordinate rowHeight(int j) override {
return expressionRowHeight(j);
}

View File

@@ -209,23 +209,6 @@ KDCoordinate SolutionsController::rowHeight(int j) {
return layoutHeight+ScrollableExactApproximateExpressionsCell::k_margin*2;
}
KDCoordinate SolutionsController::cumulatedHeightFromIndex(int j) {
int result = 0;
for (int k = 0; k < j; k++) {
result += rowHeight(k);
}
return result;
}
int SolutionsController::indexFromCumulatedHeight(KDCoordinate offsetY) {
int result = 0;
int j = 0;
while (result < offsetY && j < numberOfRows()) {
result += rowHeight(j++);
}
return (result < offsetY || offsetY == 0) ? j : j - 1;
}
KDCoordinate SolutionsController::cumulatedWidthFromIndex(int i) {
switch (i) {
case 0:

View File

@@ -27,9 +27,7 @@ public:
KDCoordinate columnWidth(int i) override;
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;

View File

@@ -95,27 +95,11 @@ KDCoordinate CalculationController::rowHeight(int j) {
return k_cellHeight;
}
KDCoordinate CalculationController::cumulatedWidthFromIndex(int i) {
int result = 0;
for (int k = 0; k < i; k++) {
result += columnWidth(k);
}
return result;
}
KDCoordinate CalculationController::cumulatedHeightFromIndex(int j) {
return j*rowHeight(0);
}
int CalculationController::indexFromCumulatedWidth(KDCoordinate offsetX) {
int result = 0;
int i = 0;
while (result < offsetX && i < numberOfRows()) {
result += rowHeight(i++);
}
return (result < offsetX || offsetX == 0) ? i : i - 1;
}
int CalculationController::indexFromCumulatedHeight(KDCoordinate offsetY) {
return (offsetY-1) / rowHeight(0);
}

View File

@@ -26,8 +26,6 @@ public:
KDCoordinate rowHeight(int j) override;
KDCoordinate cumulatedHeightFromIndex(int j) override;
int indexFromCumulatedHeight(KDCoordinate offsetY) override;
KDCoordinate cumulatedWidthFromIndex(int i) override;
int indexFromCumulatedWidth(KDCoordinate offsetX) override;
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
int typeAtLocation(int i, int j) override;

View File

@@ -13,14 +13,14 @@ public:
virtual KDCoordinate rowHeight(int j) = 0;
/* return the number of pixels to include in offset to display the column i at
the top */
virtual KDCoordinate cumulatedWidthFromIndex(int i) = 0;
virtual KDCoordinate cumulatedHeightFromIndex(int j) = 0;
virtual KDCoordinate cumulatedWidthFromIndex(int i);
virtual KDCoordinate cumulatedHeightFromIndex(int j);
/* return the number of columns (starting with first ones) that can be fully
* displayed in offsetX pixels.
* Caution: if the offset is exactly the size of n columns, the function
* returns n-1. */
virtual int indexFromCumulatedWidth(KDCoordinate offsetX) = 0;
virtual int indexFromCumulatedHeight(KDCoordinate offsetY) = 0;
virtual int indexFromCumulatedWidth(KDCoordinate offsetX);
virtual int indexFromCumulatedHeight(KDCoordinate offsetY);
virtual HighlightCell * reusableCell(int index, int type) = 0;
virtual int reusableCellCount(int type) = 0;
virtual int typeAtLocation(int i, int j) = 0;

View File

@@ -2,3 +2,37 @@
void TableViewDataSource::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
}
KDCoordinate TableViewDataSource::cumulatedWidthFromIndex(int i) {
int result = 0;
for (int k = 0; k < i; k++) {
result += columnWidth(k);
}
return result;
}
KDCoordinate TableViewDataSource::cumulatedHeightFromIndex(int j) {
int result = 0;
for (int k = 0; k < j; k++) {
result += rowHeight(k);
}
return result;
}
int TableViewDataSource::indexFromCumulatedWidth(KDCoordinate offsetX) {
int result = 0;
int i = 0;
while (result < offsetX && i < numberOfColumns()) {
result += columnWidth(i++);
}
return (result < offsetX || offsetX == 0) ? i : i - 1;
}
int TableViewDataSource::indexFromCumulatedHeight(KDCoordinate offsetY) {
int result = 0;
int j = 0;
while (result < offsetY && j < numberOfRows()) {
result += rowHeight(j++);
}
return (result < offsetY || offsetY == 0) ? j : j - 1;
}