mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
118 lines
2.9 KiB
C++
118 lines
2.9 KiB
C++
#include "tool_box_controller.h"
|
|
#include <assert.h>
|
|
|
|
static const char * labels[] = {
|
|
"Abs()",
|
|
"Root()",
|
|
"Log()",
|
|
"Calcul",
|
|
"Nombres complexes",
|
|
"Probabilite",
|
|
"Arithmetiques",
|
|
"Matrices",
|
|
"Listes",
|
|
"Approximation",
|
|
"Trigonometrie hyperbolique"
|
|
};
|
|
|
|
static const char * mathCommands[] = {
|
|
"abs()",
|
|
"root(,)",
|
|
"log()"
|
|
};
|
|
|
|
ToolBoxController::ToolBoxController() :
|
|
StackViewController(nullptr, this, true),
|
|
m_selectableTableView(SelectableTableView(this, this))
|
|
{
|
|
}
|
|
|
|
const char * ToolBoxController::title() const {
|
|
return "ToolBoxController";
|
|
}
|
|
|
|
bool ToolBoxController::handleEvent(Ion::Events::Event event) {
|
|
switch (event) {
|
|
case Ion::Events::Event::ENTER:
|
|
return handleEnter();
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool ToolBoxController::handleEnter() {
|
|
if (m_selectableTableView.selectedRow() < 3) {
|
|
m_textFieldCaller->appendText(mathCommands[m_selectableTableView.selectedRow()]);
|
|
int cursorPosition = m_selectableTableView.selectedRow() == 1 ? -2 : -1;
|
|
m_textFieldCaller->moveCursor(cursorPosition);
|
|
app()->dismissModalViewController();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void ToolBoxController::didBecomeFirstResponder() {
|
|
m_selectableTableView.selectCellAtLocation(0, 0);
|
|
app()->setFirstResponder(&m_selectableTableView);
|
|
}
|
|
|
|
int ToolBoxController::numberOfRows() {
|
|
return k_numberOfCommandRows + k_numberOfMenuRows;
|
|
}
|
|
|
|
TableViewCell * ToolBoxController::reusableCell(int index, int type) {
|
|
assert(type < 2);
|
|
assert(index >= 0);
|
|
if (type == 0) {
|
|
assert(index < k_numberOfCommandRows);
|
|
return &m_commandCells[index];
|
|
}
|
|
assert(index < k_maxNumberOfDisplayedRows);
|
|
return &m_menuCells[index];
|
|
}
|
|
|
|
int ToolBoxController::reusableCellCount(int type) {
|
|
assert(type < 2);
|
|
if (type == 0) {
|
|
return k_numberOfCommandRows;
|
|
}
|
|
return k_maxNumberOfDisplayedRows;
|
|
}
|
|
|
|
void ToolBoxController::willDisplayCellForIndex(TableViewCell * cell, int index) {
|
|
MenuListCell * myCell = (MenuListCell *)cell;
|
|
myCell->setText(labels[index]);
|
|
}
|
|
|
|
KDCoordinate ToolBoxController::rowHeight(int j) {
|
|
if (typeAtLocation(0, j) == 0) {
|
|
return k_commandRowHeight;
|
|
}
|
|
return k_menuRowHeight;
|
|
}
|
|
|
|
KDCoordinate ToolBoxController::cumulatedHeightFromIndex(int j) {
|
|
if (j < k_numberOfCommandRows) {
|
|
return j*k_commandRowHeight;
|
|
}
|
|
return k_commandRowHeight*k_numberOfCommandRows + k_menuRowHeight*(j-k_numberOfCommandRows);
|
|
}
|
|
|
|
int ToolBoxController::indexFromCumulatedHeight(KDCoordinate offsetY) {
|
|
if (offsetY < k_commandRowHeight*k_numberOfCommandRows) {
|
|
return offsetY/k_commandRowHeight;
|
|
}
|
|
return k_numberOfCommandRows + (offsetY - k_commandRowHeight*k_numberOfCommandRows)/k_menuRowHeight;
|
|
}
|
|
|
|
int ToolBoxController::typeAtLocation(int i, int j) {
|
|
if (j < k_numberOfCommandRows) {
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void ToolBoxController::setTextFieldCaller(TextField * textField) {
|
|
m_textFieldCaller = textField;
|
|
}
|