mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher][apps/calculation] Improve ScrollView::scrollToContentRect to
scroll "smartly" when scrolling to a too-big-to-be-displayed rect This fixes calculation history navigation on big cells (that are bigger than the displayed table)
This commit is contained in:
committed by
LeaNumworks
parent
24d9f37205
commit
94daf465c4
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user