[escher] In table view, use scrollToContentRect instead of recomputing

everything

Change-Id: Idb3ec8218386b03bc34d08fcd888d1a671ea98f9
This commit is contained in:
Émilie Feral
2017-08-09 11:47:05 +02:00
parent 8e5691bcc7
commit 319955424b
3 changed files with 7 additions and 38 deletions

View File

@@ -145,6 +145,9 @@ void HistoryController::willDisplayCellForIndex(HighlightCell * cell, int index)
}
KDCoordinate HistoryController::rowHeight(int j) {
if (j >= m_calculationStore->numberOfCalculations()) {
return 0;
}
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
KDCoordinate inputHeight = calculation->inputLayout()->size().height();
App * calculationApp = (App *)app();

View File

@@ -59,10 +59,6 @@ protected:
int numberOfDisplayableColumns() const;
int rowsScrollingOffset() const;
int columnsScrollingOffset() const;
bool rowAtIndexIsBeforeFullyVisibleRange(int index) const;
bool columnAtIndexIsBeforeFullyVisibleRange(int index) const;
bool rowAtIndexIsAfterFullyVisibleRange(int index) const;
bool columnAtIndexIsAfterFullyVisibleRange(int index) const;
int typeOfSubviewAtIndex(int index) const;
/* This method transform a index (of subview for instance) into an index
* refering to the set of cells of type "type". */

View File

@@ -99,22 +99,12 @@ KDCoordinate TableView::ContentView::width() const {
}
void TableView::ContentView::scrollToCell(int x, int y) const {
KDRect cellRect = KDRect(m_dataSource->cumulatedWidthFromIndex(x), m_dataSource->cumulatedHeightFromIndex(y), m_dataSource->columnWidth(x), m_dataSource->rowHeight(y));
m_tableView->scrollToContentRect(cellRect, true);
/* Handle cases when the size of the view has decreased. */
KDCoordinate contentOffsetX = m_tableView->contentOffset().x();
KDCoordinate contentOffsetY = m_tableView->contentOffset().y();
if (columnAtIndexIsBeforeFullyVisibleRange(x)) {
// Let's scroll the tableView to put that cell on the left (while keeping the left margin)
contentOffsetX = m_dataSource->cumulatedWidthFromIndex(x);
} else if (columnAtIndexIsAfterFullyVisibleRange(x)) {
// Let's scroll the tableView to put that cell on the right (while keeping the right margin)
contentOffsetX = m_dataSource->cumulatedWidthFromIndex(x+1)+2*m_horizontalCellOverlapping - m_tableView->maxContentWidthDisplayableWithoutScrolling();
}
if (rowAtIndexIsBeforeFullyVisibleRange(y)) {
// Let's scroll the tableView to put that cell on the top (while keeping the top margin)
contentOffsetY = m_dataSource->cumulatedHeightFromIndex(y);
} else if (rowAtIndexIsAfterFullyVisibleRange(y)) {
// Let's scroll the tableView to put that cell on the bottom (while keeping the bottom margin)
contentOffsetY = m_dataSource->cumulatedHeightFromIndex(y+1)+2*m_verticalCellOverlapping - m_tableView->maxContentHeightDisplayableWithoutScrolling();
}
if (m_tableView->maxContentHeightDisplayableWithoutScrolling() > height()-contentOffsetY) {
contentOffsetY = height() > m_tableView->maxContentHeightDisplayableWithoutScrolling() ? height()-m_tableView->maxContentHeightDisplayableWithoutScrolling() : 0;
}
@@ -257,23 +247,3 @@ int TableView::ContentView::columnsScrollingOffset() const {
invisibleWidth = invisibleWidth < 0 ? 0 : invisibleWidth;
return m_dataSource->indexFromCumulatedWidth(invisibleWidth);
}
bool TableView::ContentView::rowAtIndexIsBeforeFullyVisibleRange(int index) const {
return index <= rowsScrollingOffset();
}
bool TableView::ContentView::columnAtIndexIsBeforeFullyVisibleRange(int index) const {
return index <= columnsScrollingOffset();
}
bool TableView::ContentView::rowAtIndexIsAfterFullyVisibleRange(int index) const {
int minHeightToDisplayRowAtIndex = m_dataSource->cumulatedHeightFromIndex(index+1);
int heightToTheBottomOfTheScreen = m_tableView->contentOffset().y()+m_tableView->maxContentHeightDisplayableWithoutScrolling()+m_tableView->topMargin();
return minHeightToDisplayRowAtIndex >= heightToTheBottomOfTheScreen;
}
bool TableView::ContentView::columnAtIndexIsAfterFullyVisibleRange(int index) const {
int minWidthToDisplayColumnAtIndex = m_dataSource->cumulatedWidthFromIndex(index+1);
int widthToTheRightOfTheScreen = m_tableView->contentOffset().x()+m_tableView->maxContentWidthDisplayableWithoutScrolling()+m_tableView->leftMargin();
return minWidthToDisplayColumnAtIndex >= widthToTheRightOfTheScreen;
}