From 319955424b031a9efc75e64d54f1a7dd85af9999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 9 Aug 2017 11:47:05 +0200 Subject: [PATCH] [escher] In table view, use scrollToContentRect instead of recomputing everything Change-Id: Idb3ec8218386b03bc34d08fcd888d1a671ea98f9 --- apps/calculation/history_controller.cpp | 3 ++ escher/include/escher/table_view.h | 4 --- escher/src/table_view.cpp | 38 +++---------------------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index 9ed465678..5bf9a5a95 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -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(); diff --git a/escher/include/escher/table_view.h b/escher/include/escher/table_view.h index 012a2a0f1..00fd3221b 100644 --- a/escher/include/escher/table_view.h +++ b/escher/include/escher/table_view.h @@ -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". */ diff --git a/escher/src/table_view.cpp b/escher/src/table_view.cpp index f5b4776fd..3bd08c83e 100644 --- a/escher/src/table_view.cpp +++ b/escher/src/table_view.cpp @@ -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; -}