From 05a235803fa4eaae22acebe4cfdff3e1924763b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 25 Apr 2019 15:19:54 +0200 Subject: [PATCH] [calculation] HistoryViewCell: fix scroll reloading and right or left outputs selection (the order of events here matters) --- apps/calculation/history_controller.cpp | 7 ++--- apps/calculation/history_view_cell.cpp | 26 ++++++++++++------- apps/calculation/history_view_cell.h | 1 + ...ble_exact_approximate_expressions_view.cpp | 19 ++++++-------- ...lable_exact_approximate_expressions_view.h | 5 +++- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index c3a5e1caf..90696bd6d 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -109,12 +109,13 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int if (previousSelectedCellY == selectedRow()) { return; } + HistoryViewCell * cell = static_cast(t->selectedCell()); if (previousSelectedCellY == -1) { - setSelectedSubviewType(SubviewType::Output); + setSelectedSubviewType(SubviewType::Output, cell); } else if (selectedRow() < previousSelectedCellY) { - setSelectedSubviewType(SubviewType::Output); + setSelectedSubviewType(SubviewType::Output, cell); } else if (selectedRow() > previousSelectedCellY) { - setSelectedSubviewType(SubviewType::Input); + setSelectedSubviewType(SubviewType::Input, cell); } HistoryViewCell * selectedCell = (HistoryViewCell *)(t->selectedCell()); if (selectedCell == nullptr) { diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index 1f8d915a9..1988fcd6b 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -19,6 +19,7 @@ void HistoryViewCellDataSource::setSelectedSubviewType(SubviewType subviewType, m_selectedSubviewType = subviewType; if (cell) { cell->setHighlighted(cell->isHighlighted()); + cell->cellDidSelectSubview(subviewType); } historyViewCellDidChangeSelection(); } @@ -72,18 +73,23 @@ void HistoryViewCell::reloadCell() { m_scrollableOutputView.evenOddCell()->reloadCell(); layoutSubviews(); - // Reload input scroll + // Reload subviews' scrolls 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); +void HistoryViewCell::cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type) { + if (type == HistoryViewCellDataSource::SubviewType::Output) { + /* 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); + } } } diff --git a/apps/calculation/history_view_cell.h b/apps/calculation/history_view_cell.h index e9d9639ff..79c7264c8 100644 --- a/apps/calculation/history_view_cell.h +++ b/apps/calculation/history_view_cell.h @@ -31,6 +31,7 @@ class HistoryViewCell : public ::EvenOddCell, public Responder { public: HistoryViewCell(Responder * parentResponder = nullptr); void reloadCell() override; + void cellDidSelectSubview(HistoryViewCellDataSource::SubviewType type); void setEven(bool even) override; void setHighlighted(bool highlight) override; void setDataSource(HistoryViewCellDataSource * dataSource) { m_dataSource = dataSource; } diff --git a/apps/shared/scrollable_exact_approximate_expressions_view.cpp b/apps/shared/scrollable_exact_approximate_expressions_view.cpp index 98bbc4d91..ebbf41791 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_view.cpp +++ b/apps/shared/scrollable_exact_approximate_expressions_view.cpp @@ -125,16 +125,13 @@ void ScrollableExactApproximateExpressionsView::setEqualMessage(I18n::Message eq m_contentCell.approximateSign()->setMessage(equalSignMessage); } -void ScrollableExactApproximateExpressionsView::setSelectedSubviewPosition(SubviewPosition subviewPosition, bool scrollToSelection) { - m_contentCell.setSelectedSubviewPosition(subviewPosition); - if (scrollToSelection) { - if (subviewPosition == SubviewPosition::Left) { - // Scroll to the left extremity - reloadScroll(); - } else { - // Scroll to the right extremity - scrollToContentPoint(KDPoint(m_contentCell.bounds().width(), 0), true); - } +void ScrollableExactApproximateExpressionsView::reloadScroll() { + if (selectedSubviewPosition() == SubviewPosition::Left) { + // Scroll to the left extremity + ScrollableView::reloadScroll(); + } else { + // Scroll to the right extremity + scrollToContentPoint(KDPoint(m_contentCell.bounds().width(), 0), true); } } @@ -157,7 +154,7 @@ bool ScrollableExactApproximateExpressionsView::handleEvent(Ion::Events::Event e if ((event == Ion::Events::Right && selectedSubviewPosition() == SubviewPosition::Left && rightExpressionIsVisible) || (event == Ion::Events::Left && selectedSubviewPosition() == SubviewPosition::Right && leftExpressionIsVisible)) { SubviewPosition otherSubviewPosition = selectedSubviewPosition() == SubviewPosition::Left ? SubviewPosition::Right : SubviewPosition::Left; - setSelectedSubviewPosition(otherSubviewPosition, false); + setSelectedSubviewPosition(otherSubviewPosition); return true; } return ScrollableView::handleEvent(event); diff --git a/apps/shared/scrollable_exact_approximate_expressions_view.h b/apps/shared/scrollable_exact_approximate_expressions_view.h index 10b581861..40ec3c59a 100644 --- a/apps/shared/scrollable_exact_approximate_expressions_view.h +++ b/apps/shared/scrollable_exact_approximate_expressions_view.h @@ -20,7 +20,10 @@ public: SubviewPosition selectedSubviewPosition() { return m_contentCell.selectedSubviewPosition(); } - void setSelectedSubviewPosition(SubviewPosition subviewPosition, bool reloadScroll = true); + void setSelectedSubviewPosition(SubviewPosition subviewPosition) { + m_contentCell.setSelectedSubviewPosition(subviewPosition); + } + void reloadScroll(); void didBecomeFirstResponder() override; bool handleEvent(Ion::Events::Event event) override; Poincare::Layout layout() const {