[calculation] HistoryViewCell: fix scroll reloading and right or left

outputs selection (the order of events here matters)
This commit is contained in:
Émilie Feral
2019-04-25 15:19:54 +02:00
parent 39c53b5e8b
commit 05a235803f
5 changed files with 33 additions and 25 deletions

View File

@@ -109,12 +109,13 @@ void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int
if (previousSelectedCellY == selectedRow()) {
return;
}
HistoryViewCell * cell = static_cast<HistoryViewCell *>(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) {

View File

@@ -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);
}
}
}

View File

@@ -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; }

View File

@@ -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);

View File

@@ -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 {