[apps/calculation][apps/shared]

AbstractScrollableExactApproximateExpressionsView children classes
reload scroll after reloading the subview selection when entering the
responder chain and when cell becomes first responder. We don't reload
scroll when setting content of cells as this is done every time we
relayout - when scrolling in the table for instance.
This commit is contained in:
Émilie Feral
2020-01-21 10:29:46 +01:00
committed by Léa Saviot
parent ef5681ec0b
commit 87e4836196
9 changed files with 28 additions and 12 deletions

View File

@@ -18,9 +18,9 @@ IllustratedListController::IllustratedListController(Responder * parentResponder
}
void IllustratedListController::didEnterResponderChain(Responder * previousFirstResponder) {
// Select the left subview on all cells
// Select the left subview on all cells and reinitialize scroll
for (int i = 0; i < k_maxNumberOfAdditionalCalculations; i++) {
m_additionalCalculationCells[i].setSelectedSubviewPosition(ScrollableInputExactApproximateExpressionsView::SubviewPosition::Left);
m_additionalCalculationCells[i].reinitSelection();
}
selectCellAtLocation(0, 1);
}

View File

@@ -59,14 +59,18 @@ void ScrollableInputExactApproximateExpressionsView::setCalculation(Calculation
/* The displayed input and outputs have changed. We need to re-layout the cell
* and re-initialize the scroll. */
layoutSubviews();
reloadScroll();
}
void ScrollableInputExactApproximateExpressionsCell::didBecomeFirstResponder() {
m_view.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Left);
reinitSelection();
Container::activeApp()->setFirstResponder(&m_view);
}
void ScrollableInputExactApproximateExpressionsCell::reinitSelection() {
m_view.setSelectedSubviewPosition(Shared::ScrollableExactApproximateExpressionsView::SubviewPosition::Left);
m_view.reloadScroll();
}
void ScrollableInputExactApproximateExpressionsCell::setCalculation(Calculation * calculation) {
m_view.setCalculation(calculation);
layoutSubviews();

View File

@@ -49,15 +49,13 @@ public:
// Table cell
View * labelView() const override { return (View *)&m_view; }
void setHighlighted(bool highlight) override {
m_view.evenOddCell()->setHighlighted(highlight);
m_view.reloadScroll();
}
void setHighlighted(bool highlight) override { m_view.evenOddCell()->setHighlighted(highlight); }
void setCalculation(Calculation * calculation);
void setDisplayCenter(bool display);
ScrollableInputExactApproximateExpressionsView::SubviewPosition selectedSubviewPosition() { return m_view.selectedSubviewPosition(); }
void setSelectedSubviewPosition(ScrollableInputExactApproximateExpressionsView::SubviewPosition subviewPosition) { m_view.setSelectedSubviewPosition(subviewPosition); }
void reinitSelection();
private:
// Remove label margin added by TableCell because they're already handled by ScrollableInputExactApproximateExpressionsView
KDCoordinate labelMargin() const override { return 0; }

View File

@@ -12,12 +12,10 @@ ScrollableExactApproximateExpressionsCell::ScrollableExactApproximateExpressions
void ScrollableExactApproximateExpressionsCell::setLayouts(Poincare::Layout exactLayout, Poincare::Layout approximateLayout) {
m_view.setLayouts(Layout(), exactLayout, approximateLayout);
m_view.setSelectedSubviewPosition(ScrollableExactApproximateExpressionsView::SubviewPosition::Center);
}
void ScrollableExactApproximateExpressionsCell::setHighlighted(bool highlight) {
m_view.evenOddCell()->setHighlighted(highlight);
reloadScroll();
}
void ScrollableExactApproximateExpressionsCell::setEven(bool even) {
@@ -31,10 +29,16 @@ void ScrollableExactApproximateExpressionsCell::reloadScroll() {
}
void ScrollableExactApproximateExpressionsCell::didBecomeFirstResponder() {
m_view.setSelectedSubviewPosition(ScrollableExactApproximateExpressionsView::SubviewPosition::Center);
reinitSelection();
Container::activeApp()->setFirstResponder(&m_view);
}
void ScrollableExactApproximateExpressionsCell::reinitSelection() {
ScrollableExactApproximateExpressionsView::SubviewPosition selectedSubview = m_view.displayCenter() ? ScrollableExactApproximateExpressionsView::SubviewPosition::Center : ScrollableExactApproximateExpressionsView::SubviewPosition::Right;
m_view.setSelectedSubviewPosition(selectedSubview);
reloadScroll();
}
int ScrollableExactApproximateExpressionsCell::numberOfSubviews() const {
return 1;
}

View File

@@ -21,6 +21,7 @@ public:
}
Poincare::Layout layout() const override { return m_view.layout(); }
void didBecomeFirstResponder() override;
void reinitSelection();
private:
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;

View File

@@ -169,7 +169,7 @@ void AbstractScrollableExactApproximateExpressionsView::setLayouts(Poincare::Lay
if (updateLeftLayout || updateCenterLayout || updateRightLayout) {
contentCell()->reloadTextColor();
contentCell()->layoutSubviews();
reloadScroll();
// Do no reload scroll here as 'setLayouts' is called every time the table is re-layout (when scrolling for instance)
}
}

View File

@@ -24,6 +24,7 @@ public:
void setSelectedSubviewPosition(SubviewPosition subviewPosition) {
contentCell()->setSelectedSubviewPosition(subviewPosition);
}
bool displayCenter() const { return constContentCell()->displayCenter(); }
void setDisplayCenter(bool display);
void reloadScroll();
bool handleEvent(Ion::Events::Event event) override;

View File

@@ -121,6 +121,13 @@ void SolutionsController::viewWillAppear() {
}
}
void SolutionsController::didEnterResponderChain(Responder * previousFirstResponder) {
// Select the most left present subview on all cells and reinitialize scroll
for (int i = 0; i < EquationStore::k_maxNumberOfExactSolutions; i++) {
m_exactValueCells[i].reinitSelection();
}
}
/* AlternateEmptyRowDelegate */
bool SolutionsController::isEmpty() const {

View File

@@ -15,6 +15,7 @@ public:
const char * title() override;
View * view() override;
void viewWillAppear() override;
void didEnterResponderChain(Responder * previousFirstResponder) override;
/* AlternateEmptyViewDefaultDelegate */
bool isEmpty() const override;
virtual I18n::Message emptyMessage() override;