diff --git a/apps/calculation/selectable_table_view.cpp b/apps/calculation/selectable_table_view.cpp index 717d727fe..e2d81e53c 100644 --- a/apps/calculation/selectable_table_view.cpp +++ b/apps/calculation/selectable_table_view.cpp @@ -24,18 +24,6 @@ void CalculationSelectableTableView::scrollToCell(int i, int j) { KDCoordinate contentOffsetY = dataSource()->cumulatedHeightFromIndex(dataSource()->numberOfRows()) - maxContentHeightDisplayableWithoutScrolling(); setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); } - if (dataSource()->numberOfRows() > j && dataSource()->numberOfColumns() > i && dataSource()->rowHeight(j) > bounds().height()) { - KDCoordinate contentOffsetX = contentOffset().x(); - KDCoordinate contentOffsetY = contentOffset().y(); - if (contentOffsetY > dataSource()->cumulatedHeightFromIndex(j) && contentOffsetY > dataSource()->cumulatedHeightFromIndex(j+1)) { - // Let's scroll the tableView to align the top of the cell to the top - contentOffsetY = dataSource()->cumulatedHeightFromIndex(j); - } else { - // Let's scroll the tableView to align the bottom of the cell to the bottom - contentOffsetY = dataSource()->cumulatedHeightFromIndex(j+1) - maxContentHeightDisplayableWithoutScrolling(); - } - setContentOffset(KDPoint(contentOffsetX, contentOffsetY)); - } } void CalculationSelectableTableView::scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCellDataSource::SubviewType subviewType, int i, int j) { diff --git a/escher/src/scroll_view.cpp b/escher/src/scroll_view.cpp index 834aae7c0..d85e0dbcc 100644 --- a/escher/src/scroll_view.cpp +++ b/escher/src/scroll_view.cpp @@ -81,8 +81,33 @@ void ScrollView::scrollToContentPoint(KDPoint p, bool allowOverscroll) { } void ScrollView::scrollToContentRect(KDRect rect, bool allowOverscroll) { - scrollToContentPoint(rect.topLeft(), allowOverscroll); - scrollToContentPoint(rect.bottomRight(), allowOverscroll); + KDPoint tl = rect.topLeft(); + KDPoint br = rect.bottomRight(); + KDRect visibleRect = visibleContentRect(); + /* We first check that we can display the whole rect. If we can't, we focus + * the croll to the closest part of the rect. */ + if (visibleRect.height() < rect.height()) { + // The visible rect is too small to display 'rect' + if (rect.top() >= visibleRect.top()) { + // We scroll to display the top part of rect + br = KDPoint(br.x(), rect.top() + visibleRect.height()); + } else { + // We scroll to display the bottom part of rect + tl = KDPoint(tl.x(), rect.bottom() - visibleRect.height()); + } + } + if (visibleRect.width() < rect.width()) { + // The visible rect is too small to display 'rect' + if (rect.left() >= visibleRect.left()) { + // We scroll to display the left part of rect + br = KDPoint(rect.left() + visibleRect.width(), br.y()); + } else { + // We scroll to display the right part of rect + tl = KDPoint(rect.right() - visibleRect.width(), tl.y()); + } + } + scrollToContentPoint(tl, allowOverscroll); + scrollToContentPoint(br, allowOverscroll); } KDRect ScrollView::visibleContentRect() {