[apps/calculation] HistoryController: in historyViewCellDidChangeSelection,

limit the whole table reloading to cases where the cell height did
actually change to avoid useless blinking
This commit is contained in:
Émilie Feral
2020-01-23 11:10:40 +01:00
committed by Léa Saviot
parent 71de56f87a
commit a82ff2b703
4 changed files with 23 additions and 9 deletions

View File

@@ -211,10 +211,18 @@ void HistoryController::scrollToCell(int i, int j) {
m_selectableTableView.scrollToCell(i, j);
}
void HistoryController::historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) {
/* Update the whole table as the height of the selected cell row might have
* changed. */
m_selectableTableView.reloadData();
bool HistoryController::calculationAtIndexToggles(int index) {
Context * context = App::app()->localContext();
return index >= 0 && index < m_calculationStore->numberOfCalculations() && calculationAtIndex(index)->displayOutput(context) == Calculation::DisplayOutput::ExactAndApproximateToggle;
}
void HistoryController::historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) {
/* If the selection change triggers the toggling of the outputs, we update
* the whole table as the height of the selected cell row might have changed. */
if ((type == SubviewType::Output || previousType == SubviewType::Output) && (calculationAtIndexToggles(selectedRow()) || calculationAtIndexToggles(previousSelectedCellY))) {
m_selectableTableView.reloadData();
}
// Fill the selected cell and the previous selected cell because cells repartition might have changed
*cell = static_cast<HistoryViewCell *>(m_selectableTableView.selectedCell());
*previousCell = static_cast<HistoryViewCell *>(m_selectableTableView.cellAtLocation(previousSelectedCellX, previousSelectedCellY));

View File

@@ -35,7 +35,8 @@ private:
int storeIndex(int i) { return numberOfRows() - i - 1; }
Shared::ExpiringPointer<Calculation> calculationAtIndex(int i);
CalculationSelectableTableView * selectableTableView();
void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) override;
bool calculationAtIndexToggles(int index);
void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) override;
constexpr static int k_maxNumberOfDisplayedRows = 5;
CalculationSelectableTableView m_selectableTableView;
HistoryViewCell m_calculationHistory[k_maxNumberOfDisplayedRows];

View File

@@ -17,11 +17,16 @@ HistoryViewCellDataSource::HistoryViewCellDataSource() :
m_selectedSubviewType(SubviewType::Output) {}
void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType, bool sameCell, int previousSelectedCellX, int previousSelectedCellY) {
SubviewType previousSubviewType = sameCell ? m_selectedSubviewType : SubviewType::None;
m_selectedSubviewType = subviewType;
HistoryViewCell * selectedCell = nullptr;
HistoryViewCell * previouslySelectedCell = nullptr;
historyViewCellDidChangeSelection(&selectedCell, &previouslySelectedCell, previousSelectedCellX, previousSelectedCellY);
SubviewType previousSubviewType = m_selectedSubviewType;
m_selectedSubviewType = subviewType;
/* We need to notify the whole table that the selection changed if it
* involves the selection/deselection of an output. Indeed, only them can
* trigger change in the displayed expressions. */
historyViewCellDidChangeSelection(&selectedCell, &previouslySelectedCell, previousSelectedCellX, previousSelectedCellY, subviewType, previousSubviewType);
previousSubviewType = sameCell ? previousSubviewType : SubviewType::None;
if (selectedCell) {
selectedCell->reloadSubviewHighlight();
selectedCell->cellDidSelectSubview(subviewType, previousSubviewType);

View File

@@ -25,7 +25,7 @@ private:
* both the data source and the delegate will be the same controller, we
* avoid keeping 2 pointers in HistoryViewCell. */
// It returns the selected cell at the end of the method
virtual void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY) = 0;
virtual void historyViewCellDidChangeSelection(HistoryViewCell ** cell, HistoryViewCell ** previousCell, int previousSelectedCellX, int previousSelectedCellY, SubviewType type, SubviewType previousType) = 0;
SubviewType m_selectedSubviewType;
};