[calculation] HistoryViewCell: reloadCell selects the right or left

output according to the calculation hold (this enables to discard
unnecessary reloadScroll)
This commit is contained in:
Émilie Feral
2019-04-24 09:45:29 +02:00
parent 8629b4c9e9
commit e29c2b8b39
2 changed files with 12 additions and 14 deletions

View File

@@ -56,7 +56,6 @@ void HistoryViewCell::setHighlighted(bool highlight) {
m_scrollableOutputView.evenOddCell()->setHighlighted(true);
}
}
reloadScroll();
}
Poincare::Layout HistoryViewCell::layout() const {
@@ -71,12 +70,20 @@ Poincare::Layout HistoryViewCell::layout() const {
void HistoryViewCell::reloadCell() {
m_scrollableOutputView.evenOddCell()->reloadCell();
layoutSubviews();
reloadScroll();
}
void HistoryViewCell::reloadScroll() {
// Reload input scroll
m_inputView.reloadScroll();
m_scrollableOutputView.reloadScroll();
/* Select the right output according to the calculation display output. This
* will reload the scroll to display the selected output. */
App * calculationApp = (App *)app();
Calculation::DisplayOutput display = m_calculation.displayOutput(calculationApp->localContext());
if (display == Calculation::DisplayOutput::ExactAndApproximate) {
m_scrollableOutputView.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Left);
} else {
assert(display == Calculation::DisplayOutput::ApproximateOnly || display == Calculation::DisplayOutput::ExactAndApproximateToggle || display == Calculation::DisplayOutput::ExactOnly);
m_scrollableOutputView.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Right);
}
}
KDColor HistoryViewCell::backgroundColor() const {
@@ -133,14 +140,6 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool isSelected)
m_scrollableOutputView.setLayouts(rightOutputLayout, leftOutputLayout);
I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(calculationApp->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual;
m_scrollableOutputView.setEqualMessage(equalMessage);
// Select the right output according to the calculation display output
if (display == Calculation::DisplayOutput::ApproximateOnly || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && isSelected)) {
m_scrollableOutputView.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Right);
} else {
assert(display == Calculation::DisplayOutput::ExactOnly || display == Calculation::DisplayOutput::ExactAndApproximate || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && !isSelected));
m_scrollableOutputView.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Left);
}
}
void HistoryViewCell::didBecomeFirstResponder() {

View File

@@ -31,7 +31,6 @@ class HistoryViewCell : public ::EvenOddCell, public Responder {
public:
HistoryViewCell(Responder * parentResponder = nullptr);
void reloadCell() override;
void reloadScroll();
void setEven(bool even) override;
void setHighlighted(bool highlight) override;
void setDataSource(HistoryViewCellDataSource * dataSource) { m_dataSource = dataSource; }