mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 22:00:28 +01:00
[apps/graph/list] Use selectable table view in the list controller
Change-Id: I7b4429ab04e7f452c5ff12f6483fc39fd39cea85
This commit is contained in:
@@ -5,10 +5,8 @@
|
||||
namespace Graph {
|
||||
|
||||
ListController::ListController(Responder * parentResponder, FunctionStore * functionStore) :
|
||||
HeaderViewController(parentResponder, &m_tableView),
|
||||
m_tableView(TableView(this)),
|
||||
m_activeCellx(0),
|
||||
m_activeCelly(-1),
|
||||
HeaderViewController(parentResponder, &m_selectableTableView),
|
||||
m_selectableTableView(SelectableTableView(this, this)),
|
||||
m_manualScrolling(0),
|
||||
m_functionStore(functionStore),
|
||||
m_parameterController(ParameterController(this, functionStore))
|
||||
@@ -49,7 +47,7 @@ KDCoordinate ListController::columnWidth(int i) {
|
||||
case 0:
|
||||
return k_functionNameWidth;
|
||||
case 1:
|
||||
return m_tableView.bounds().width()-k_functionNameWidth;
|
||||
return m_selectableTableView.bounds().width()-k_functionNameWidth;
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
@@ -63,7 +61,7 @@ KDCoordinate ListController::cumulatedWidthFromIndex(int i) {
|
||||
case 1:
|
||||
return k_functionNameWidth;
|
||||
case 2:
|
||||
return m_tableView.bounds().width();
|
||||
return m_selectableTableView.bounds().width();
|
||||
default:
|
||||
assert(false);
|
||||
return 0;
|
||||
@@ -82,7 +80,7 @@ int ListController::indexFromCumulatedWidth(KDCoordinate offsetX) {
|
||||
if (offsetX <= k_functionNameWidth) {
|
||||
return 0;
|
||||
} else {
|
||||
if (offsetX <= m_tableView.bounds().width())
|
||||
if (offsetX <= m_selectableTableView.bounds().width())
|
||||
return 1;
|
||||
else {
|
||||
return 2;
|
||||
@@ -99,39 +97,13 @@ int ListController::indexFromCumulatedHeight(KDCoordinate offsetY) {
|
||||
return (result < offsetY || offsetY == 0) ? j : j - 1;
|
||||
}
|
||||
|
||||
void ListController::setActiveCell(int i, int j) {
|
||||
if (i < 0 || i >= numberOfColumns()) {
|
||||
return;
|
||||
}
|
||||
if (j < -1 || j >= numberOfRows()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_activeCelly >= 0) {
|
||||
EvenOddCell * previousCell = (EvenOddCell *)(m_tableView.cellAtLocation(m_activeCellx, m_activeCelly));
|
||||
previousCell->setHighlighted(false);
|
||||
}
|
||||
|
||||
m_activeCellx = i;
|
||||
m_activeCelly = j;
|
||||
if (m_activeCelly >= 0) {
|
||||
m_tableView.scrollToCell(i, j);
|
||||
EvenOddCell * cell = (EvenOddCell *)(m_tableView.cellAtLocation(i, j));
|
||||
cell->setHighlighted(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ListController::didBecomeFirstResponder() {
|
||||
m_tableView.reloadData();
|
||||
if (m_activeCelly == -1) {
|
||||
setActiveCell(1,0);
|
||||
if (m_selectableTableView.selectedRow() == -1) {
|
||||
m_selectableTableView.setSelectedCellAtLocation(1, 0);
|
||||
} else {
|
||||
if (m_activeCelly <= m_functionStore->numberOfFunctions()) {
|
||||
setActiveCell(m_activeCellx, m_activeCelly);
|
||||
} else {
|
||||
setActiveCell(m_activeCellx, m_functionStore->numberOfFunctions());
|
||||
}
|
||||
m_selectableTableView.setSelectedCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
|
||||
}
|
||||
app()->setFirstResponder(&m_selectableTableView);
|
||||
}
|
||||
|
||||
void ListController::configureFunction(Function * function) {
|
||||
@@ -165,59 +137,49 @@ void ListController::editExpression(FunctionExpressionView * functionCell, bool
|
||||
|
||||
bool ListController::handleEvent(Ion::Events::Event event) {
|
||||
switch (event) {
|
||||
case Ion::Events::Event::DOWN_ARROW:
|
||||
setActiveCell(m_activeCellx, m_activeCelly+1);
|
||||
return true;
|
||||
case Ion::Events::Event::UP_ARROW:
|
||||
setActiveCell(m_activeCellx, m_activeCelly-1);
|
||||
if (m_activeCelly == -1) {
|
||||
app()->setFirstResponder(tabController());
|
||||
}
|
||||
return true;
|
||||
case Ion::Events::Event::LEFT_ARROW:
|
||||
setActiveCell(m_activeCellx-1, m_activeCelly);
|
||||
return true;
|
||||
case Ion::Events::Event::RIGHT_ARROW:
|
||||
setActiveCell(m_activeCellx+1, m_activeCelly);
|
||||
m_selectableTableView.deselectTable();
|
||||
assert(m_selectableTableView.selectedRow() == -1);
|
||||
app()->setFirstResponder(tabController());
|
||||
return true;
|
||||
case Ion::Events::Event::PLUS:
|
||||
m_manualScrolling += 10;
|
||||
m_tableView.setContentOffset({0, m_manualScrolling});
|
||||
m_selectableTableView.setContentOffset({0, m_manualScrolling});
|
||||
return true;
|
||||
case Ion::Events::Event::ENTER:
|
||||
return handleEnter();
|
||||
default:
|
||||
if ((int)event >= 0x100 || m_activeCellx == 0) {
|
||||
if ((int)event >= 0x100 || m_selectableTableView.selectedColumn() == 0) {
|
||||
return false;
|
||||
}
|
||||
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_tableView.cellAtLocation(m_activeCellx, m_activeCelly));
|
||||
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
|
||||
editExpression(functionCell, true, (char)event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool ListController::handleEnter() {
|
||||
switch (m_activeCellx) {
|
||||
switch (m_selectableTableView.selectedColumn()) {
|
||||
case 0:
|
||||
{
|
||||
if (m_activeCelly == numberOfRows() - 1) {
|
||||
if (m_selectableTableView.selectedRow() == numberOfRows() - 1) {
|
||||
return true;
|
||||
}
|
||||
configureFunction(m_functionStore->functionAtIndex(m_activeCelly));
|
||||
configureFunction(m_functionStore->functionAtIndex(m_selectableTableView.selectedRow()));
|
||||
return true;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (m_activeCelly == numberOfRows() - 1) {
|
||||
if (m_selectableTableView.selectedRow() == numberOfRows() - 1) {
|
||||
if (m_functionStore->numberOfFunctions() < FunctionStore::k_maxNumberOfFunctions) {
|
||||
m_functionStore->addEmptyFunction();
|
||||
m_tableView.reloadData();
|
||||
m_selectableTableView.reloadData();
|
||||
return true;
|
||||
}
|
||||
// Add a warning to tell the user there is no more space for new functions
|
||||
return false;
|
||||
}
|
||||
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_tableView.cellAtLocation(m_activeCellx, m_activeCelly));
|
||||
FunctionExpressionView * functionCell = (FunctionExpressionView *)(m_selectableTableView.cellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()));
|
||||
editExpression(functionCell, false);
|
||||
return true;
|
||||
}
|
||||
@@ -278,7 +240,7 @@ void ListController::willDisplayCellAtLocation(TableViewCell * cell, int i, int
|
||||
}
|
||||
EvenOddCell * myCell = (EvenOddCell *)cell;
|
||||
myCell->setEven(j%2 == 0);
|
||||
myCell->setHighlighted(i == m_activeCellx && j == m_activeCelly);
|
||||
myCell->setHighlighted(i == m_selectableTableView.selectedColumn() && j == m_selectableTableView.selectedRow());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ namespace Graph {
|
||||
class ListController : public HeaderViewController, public TableViewDataSource {
|
||||
public:
|
||||
ListController(Responder * parentResponder, FunctionStore * functionStore);
|
||||
|
||||
void setActiveCell(int i, int j);
|
||||
|
||||
const char * title() const override;
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
bool handleEnter();
|
||||
@@ -48,9 +45,7 @@ private:
|
||||
FunctionExpressionView m_expressionCells[k_maxNumberOfRows];
|
||||
EvenOddCell m_emptyCell;
|
||||
NewFunctionCell m_addNewFunction;
|
||||
TableView m_tableView;
|
||||
int m_activeCellx;
|
||||
int m_activeCelly;
|
||||
SelectableTableView m_selectableTableView;
|
||||
KDCoordinate m_manualScrolling;
|
||||
FunctionStore * m_functionStore;
|
||||
ParameterController m_parameterController;
|
||||
|
||||
Reference in New Issue
Block a user