mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
#include "list_controller.h"
|
|
#include <assert.h>
|
|
|
|
ListController::ListController(Responder * parentResponder, Graph::FunctionStore * functionStore) :
|
|
ViewController(parentResponder),
|
|
m_tableView(TableView(this)),
|
|
m_activeCell(0),
|
|
m_manualScrolling(0),
|
|
m_functionStore(functionStore)
|
|
{
|
|
}
|
|
|
|
View * ListController::view() {
|
|
return &m_tableView;
|
|
}
|
|
|
|
const char * ListController::title() const {
|
|
return "Fonctions";
|
|
}
|
|
|
|
void ListController::setActiveCell(int index) {
|
|
if (index < 0 || index >= m_functionStore->numberOfFunctions()) {
|
|
return;
|
|
}
|
|
|
|
m_activeCell = index;
|
|
m_tableView.scrollToRow(index);
|
|
FunctionCell * cell = (FunctionCell *)(m_tableView.cellAtIndex(index));
|
|
cell->setParentResponder(this);
|
|
app()->focus(cell);
|
|
}
|
|
|
|
bool ListController::handleEvent(ion_event_t event) {
|
|
switch (event) {
|
|
case DOWN_ARROW:
|
|
setActiveCell(m_activeCell+1);
|
|
return true;
|
|
case UP_ARROW:
|
|
setActiveCell(m_activeCell-1);
|
|
return true;
|
|
case ENTER:
|
|
m_manualScrolling += 10;
|
|
m_tableView.setContentOffset({0, m_manualScrolling});
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int ListController::numberOfCells() {
|
|
return m_functionStore->numberOfFunctions();
|
|
};
|
|
|
|
View * ListController::reusableCell(int index) {
|
|
assert(index >= 0);
|
|
assert(index < k_maxNumberOfCells);
|
|
return &m_cells[index];
|
|
}
|
|
|
|
int ListController::reusableCellCount() {
|
|
return k_maxNumberOfCells;
|
|
}
|
|
|
|
void ListController::willDisplayCellForIndex(View * cell, int index) {
|
|
FunctionCell * myCell = (FunctionCell *)cell;
|
|
myCell->setFunction(m_functionStore->functionAtIndex(index));
|
|
myCell->setEven(index%2 == 0);
|
|
}
|
|
|
|
KDCoordinate ListController::cellHeight() {
|
|
return 40;
|
|
}
|