[calculation] Display exact and approximate outputs in the

calculation history when the output is selected for calculations
involving decimal numbers (1.2)
This commit is contained in:
Émilie Feral
2019-04-22 14:14:15 +02:00
parent 6fd5cb360b
commit 80078137d5
4 changed files with 16 additions and 9 deletions

View File

@@ -106,6 +106,9 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
}
void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
if (previousSelectedCellY == selectedRow()) {
return;
}
if (previousSelectedCellY == -1) {
setSelectedSubviewType(SubviewType::Output);
} else if (selectedRow() < previousSelectedCellY) {
@@ -139,7 +142,7 @@ int HistoryController::reusableCellCount(int type) {
void HistoryController::willDisplayCellForIndex(HighlightCell * cell, int index) {
HistoryViewCell * myCell = (HistoryViewCell *)cell;
myCell->setCalculation(m_calculationStore->calculationAtIndex(index));
myCell->setCalculation(m_calculationStore->calculationAtIndex(index), index == selectedRow() && selectedSubviewType() == SubviewType::Output);
myCell->setEven(index%2 == 0);
myCell->reloadCell();
}
@@ -150,7 +153,7 @@ KDCoordinate HistoryController::rowHeight(int j) {
}
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
App * calculationApp = (App *)app();
return calculation->height(calculationApp->localContext()) + 4 * Metric::CommonSmallMargin;
return calculation->height(calculationApp->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin;
}
int HistoryController::typeAtLocation(int i, int j) {

View File

@@ -28,6 +28,7 @@ public:
void scrollToCell(int i, int j);
private:
CalculationSelectableTableView * selectableTableView();
void historyViewCellDidChangeSelection() override { m_selectableTableView.reloadData(); }
constexpr static int k_maxNumberOfDisplayedRows = 5;
CalculationSelectableTableView m_selectableTableView;
HistoryViewCell m_calculationHistory[k_maxNumberOfDisplayedRows];

View File

@@ -20,6 +20,7 @@ void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType,
if (cell) {
cell->setHighlighted(cell->isHighlighted());
}
historyViewCellDidChangeSelection();
}
/* HistoryViewCell */
@@ -111,10 +112,7 @@ void HistoryViewCell::layoutSubviews() {
));
}
void HistoryViewCell::setCalculation(Calculation * calculation) {
if (*calculation == m_calculation) {
return;
}
void HistoryViewCell::setCalculation(Calculation * calculation, bool isSelected) {
m_calculation = *calculation;
m_inputView.setLayout(calculation->createInputLayout());
App * calculationApp = (App *)app();
@@ -124,11 +122,11 @@ void HistoryViewCell::setCalculation(Calculation * calculation) {
Poincare::Layout leftOutputLayout = Poincare::Layout();
Poincare::Layout rightOutputLayout;
Calculation::DisplayOutput display = calculation->displayOutput(calculationApp->localContext());
if (display == Calculation::DisplayOutput::ExactOnly) {
if (display == Calculation::DisplayOutput::ExactOnly || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && !isSelected && calculation->toggleDisplayExact())) {
rightOutputLayout = calculation->createExactOutputLayout();
} else {
rightOutputLayout = calculation->createApproximateOutputLayout(calculationApp->localContext());
if (display == Calculation::DisplayOutput::ExactAndApproximate) {
if (display == Calculation::DisplayOutput::ExactAndApproximate || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && isSelected)) {
leftOutputLayout = calculation->createExactOutputLayout();
}
}

View File

@@ -20,6 +20,10 @@ public:
void setSelectedSubviewType(SubviewType subviewType, HistoryViewCell * cell = nullptr);
SubviewType selectedSubviewType() { return m_selectedSubviewType; }
private:
/* This method should belong to a delegate instead of a data source but as
* both the data source and the delegate will be the same controller, we
* avoid keeping 2 pointers in HistoryViewCell. */
virtual void historyViewCellDidChangeSelection() = 0;
SubviewType m_selectedSubviewType;
};
@@ -36,7 +40,8 @@ public:
}
Poincare::Layout layout() const override;
KDColor backgroundColor() const override;
void setCalculation(Calculation * calculation);
Calculation * calculation() { return &m_calculation; }
void setCalculation(Calculation * calculation, bool isSelected = false);
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;