mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/sequence] Factorize sequence row index offsets
Change-Id: Id6fa632521858c48fe7d3daf35fd846bf24a05eb
This commit is contained in:
committed by
EmilieNumworks
parent
387d3c9aa1
commit
cfc37f1bac
@@ -20,20 +20,17 @@ SequenceToolbox::SequenceToolbox() :
|
||||
}
|
||||
|
||||
bool SequenceToolbox::handleEvent(Ion::Events::Event event) {
|
||||
if (selectedRow() < m_numberOfAddedCells && stackDepth() == 0) {
|
||||
if (stackDepth() == 0 && selectedRow() < m_numberOfAddedCells) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
return selectAddedCell(selectedRow());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return MathToolbox::handleEventForRow(event, mathToolboxIndex(selectedRow()));
|
||||
return MathToolbox::handleEventForRow(event, selectedRow() - stackRowOffset());
|
||||
}
|
||||
|
||||
int SequenceToolbox::numberOfRows() const {
|
||||
if (stackDepth() == 0) {
|
||||
return MathToolbox::numberOfRows()+m_numberOfAddedCells;
|
||||
}
|
||||
return MathToolbox::numberOfRows();
|
||||
return MathToolbox::numberOfRows() + stackRowOffset();
|
||||
}
|
||||
|
||||
HighlightCell * SequenceToolbox::reusableCell(int index, int type) {
|
||||
@@ -52,14 +49,14 @@ void SequenceToolbox::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
cell->reloadCell();
|
||||
return;
|
||||
}
|
||||
MathToolbox::willDisplayCellForIndex(cell, mathToolboxIndex(index));
|
||||
MathToolbox::willDisplayCellForIndex(cell, index - stackRowOffset());
|
||||
}
|
||||
|
||||
int SequenceToolbox::typeAtLocation(int i, int j) {
|
||||
if (stackDepth() == 0 && j < m_numberOfAddedCells) {
|
||||
return 2;
|
||||
}
|
||||
return MathToolbox::typeAtLocation(i,mathToolboxIndex(j));
|
||||
return MathToolbox::typeAtLocation(i, j - stackRowOffset());
|
||||
}
|
||||
|
||||
void SequenceToolbox::buildExtraCellsLayouts(const char * sequenceName, int recurrenceDepth) {
|
||||
@@ -100,12 +97,4 @@ bool SequenceToolbox::selectAddedCell(int selectedRow){
|
||||
return true;
|
||||
}
|
||||
|
||||
int SequenceToolbox::mathToolboxIndex(int index) {
|
||||
int indexMathToolbox = index;
|
||||
if (stackDepth() == 0) {
|
||||
indexMathToolbox = index - m_numberOfAddedCells;
|
||||
}
|
||||
return indexMathToolbox;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,14 +17,11 @@ public:
|
||||
int typeAtLocation(int i, int j) override;
|
||||
void buildExtraCellsLayouts(const char * sequenceName, int recurrenceDepth);
|
||||
private:
|
||||
int stackRowIndex(int selectedRow) override {
|
||||
/* At 0 depth, mathToolboxIndex() offset must be removed when calling
|
||||
* NestedMenuController::push() so that the pushed row is correct when
|
||||
* popped in NestedMenuController::returnToPreviousMenu(). */
|
||||
return stackDepth() == 0 ? selectedRow + m_numberOfAddedCells : selectedRow;
|
||||
};
|
||||
/* At 0 depth, there are additional rows to display. With the exception of
|
||||
* NestedMenuController::returnToPreviousMenu(), it must be ignored in
|
||||
* parent's classes. */
|
||||
int stackRowOffset() const override { return stackDepth() == 0 ? m_numberOfAddedCells : 0; }
|
||||
bool selectAddedCell(int selectedRow);
|
||||
int mathToolboxIndex(int index);
|
||||
ExpressionTableCell m_addedCells[k_maxNumberOfDisplayedRows];
|
||||
Poincare::Layout m_addedCellLayout[k_maxNumberOfDisplayedRows];
|
||||
int m_numberOfAddedCells;
|
||||
|
||||
@@ -66,7 +66,7 @@ protected:
|
||||
virtual bool selectSubMenu(int selectedRow);
|
||||
virtual bool returnToPreviousMenu();
|
||||
virtual bool selectLeaf(int selectedRow) = 0;
|
||||
virtual int stackRowIndex(int selectedRow) { return selectedRow; }
|
||||
virtual int stackRowOffset() const { return 0; }
|
||||
InputEventHandler * sender() { return m_sender; }
|
||||
virtual HighlightCell * leafCellAtIndex(int index) = 0;
|
||||
virtual HighlightCell * nodeCellAtIndex(int index) = 0;
|
||||
|
||||
@@ -157,7 +157,7 @@ bool NestedMenuController::handleEventForRow(Ion::Events::Event event, int rowIn
|
||||
}
|
||||
|
||||
bool NestedMenuController::selectSubMenu(int selectedRow) {
|
||||
m_stack.push(stackRowIndex(selectedRow), m_selectableTableView.contentOffset().y());
|
||||
m_stack.push(selectedRow, m_selectableTableView.contentOffset().y());
|
||||
m_listController.setFirstSelectedRow(0);
|
||||
Container::activeApp()->setFirstResponder(&m_listController);
|
||||
return true;
|
||||
@@ -166,7 +166,7 @@ bool NestedMenuController::selectSubMenu(int selectedRow) {
|
||||
bool NestedMenuController::returnToPreviousMenu() {
|
||||
assert(m_stack.depth() > 0);
|
||||
NestedMenuController::Stack::State state = m_stack.pop();
|
||||
m_listController.setFirstSelectedRow(state.selectedRow());
|
||||
m_listController.setFirstSelectedRow(state.selectedRow() + stackRowOffset());
|
||||
KDPoint scroll = m_selectableTableView.contentOffset();
|
||||
m_selectableTableView.setContentOffset(KDPoint(scroll.x(), state.verticalScroll()));
|
||||
Container::activeApp()->setFirstResponder(&m_listController);
|
||||
|
||||
Reference in New Issue
Block a user