mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/calculation] Fixed history scroll
Fixed a bug involving mishandled negative offsets in CalculationSelectableTableView::scrollToSubviewOfTypeOfCellAtLocation and cleaned up the function. Change-Id: I4394ca9dc9748e8b761e7f722e41014d71d3373f
This commit is contained in:
committed by
Léa Saviot
parent
cb62747e48
commit
e78c5c02d3
@@ -44,19 +44,50 @@ void CalculationSelectableTableView::scrollToSubviewOfTypeOfCellAtLocation(Histo
|
||||
HistoryViewCell * cell = static_cast<HistoryViewCell *>(selectedCell());
|
||||
assert(cell);
|
||||
KDCoordinate contentOffsetX = contentOffset().x();
|
||||
KDCoordinate contentOffsetY = dataSource()->cumulatedHeightFromIndex(j+1) - maxContentHeightDisplayableWithoutScrolling();
|
||||
if (subviewType == HistoryViewCellDataSource::SubviewType::Input) {
|
||||
if (j == 0) {
|
||||
contentOffsetY = 0;
|
||||
} else {
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
|
||||
}
|
||||
} else if (cell->displaysSingleLine() && dataSource()->rowHeight(j) > maxContentHeightDisplayableWithoutScrolling()) {
|
||||
/* If we cannot display the full calculation, we display the output as
|
||||
* close as possible to the top of the screen without drawing empty space
|
||||
* between the history and the input field. */
|
||||
contentOffsetY = dataSource()->cumulatedHeightFromIndex(j) + std::min(dataSource()->rowHeight(j) - maxContentHeightDisplayableWithoutScrolling(), cell->inputView()->layout().baseline() - cell->outputView()->baseline());
|
||||
|
||||
KDCoordinate contentOffsetY = dataSource()->cumulatedHeightFromIndex(j);
|
||||
if (cell->displaysSingleLine() && dataSource()->rowHeight(j) > maxContentHeightDisplayableWithoutScrolling()) {
|
||||
/* If we cannot display the full calculation, we display the selected
|
||||
* layout as close as possible to the top of the screen without drawing
|
||||
* empty space between the history and the input field.
|
||||
*
|
||||
* Below are some values we can assign to contentOffsetY, and the kinds of
|
||||
* display they entail :
|
||||
* (the selected cell is at index j)
|
||||
*
|
||||
* 1 - cumulatedHeightFromIndex(j)
|
||||
* Aligns the top of the cell with the top of the zone in which the
|
||||
* history can be drawn.
|
||||
*
|
||||
* 2 - (cumulatedHeightFromIndex(j+1)
|
||||
* - maxContentHeightDisplayableWithoutScrolling())
|
||||
* Aligns the bottom of the cell with the top of the input field.
|
||||
*
|
||||
* 3 - cumulatedHeightFromIndex(j) + baseline1 - baseline2
|
||||
* Aligns the top of the selected layout with the top of the screen (only
|
||||
* used when the selected layout is the smallest).
|
||||
*
|
||||
* The following drawing shows where the calculation would be aligned with
|
||||
* each value of contentOffsetY, for the calculation (1/3)/(4/2) = 1/6.
|
||||
*
|
||||
* (1) (2) (3)
|
||||
* +--------------+ +--------------+ +--------------+
|
||||
* | 1 | | --- - | | 3 1 |
|
||||
* | - | | 4 6 | | --- - |
|
||||
* | 3 1 | | - | | 4 6 |
|
||||
* | --- - | | 2 | | - |
|
||||
* +--------------+ +--------------+ +--------------+
|
||||
* | (1/3)/(4/2) | | (1/3)/(4/2) | | (1/3)/(4/2) |
|
||||
* +--------------+ +--------------+ +--------------+
|
||||
*
|
||||
* */
|
||||
contentOffsetY += std::min(
|
||||
dataSource()->rowHeight(j) - maxContentHeightDisplayableWithoutScrolling(),
|
||||
std::max(0, (cell->inputView()->layout().baseline() - cell->outputView()->baseline()) * (subviewType == HistoryViewCellDataSource::SubviewType::Input ? -1 : 1)));
|
||||
} else if (subviewType != HistoryViewCellDataSource::SubviewType::Input) {
|
||||
contentOffsetY += dataSource()->rowHeight(j) - maxContentHeightDisplayableWithoutScrolling();
|
||||
}
|
||||
|
||||
setContentOffset(KDPoint(contentOffsetX, contentOffsetY));
|
||||
/* For the same reason as (*), we have to rehighlight the new history view
|
||||
* cell and reselect the first responder.
|
||||
|
||||
Reference in New Issue
Block a user