10 VariableBoxController::ContentViewController::ContentViewController(
Responder * parentResponder,
GlobalContext * context) :
13 m_textFieldCaller(nullptr),
14 m_firstSelectedRow(0),
15 m_previousSelectedRow(0),
16 m_currentPage(Page::RootMenu),
17 m_selectableTableView(this)
19 m_selectableTableView.setMargins(0);
20 m_selectableTableView.setShowsIndicators(
false);
23 const char * VariableBoxController::ContentViewController::title() {
27 View * VariableBoxController::ContentViewController::view() {
28 return &m_selectableTableView;
31 void VariableBoxController::ContentViewController::didBecomeFirstResponder() {
32 m_selectableTableView.reloadData();
33 m_selectableTableView.scrollToCell(0,0);
34 selectCellAtLocation(0, m_firstSelectedRow);
35 app()->setFirstResponder(&m_selectableTableView);
38 bool VariableBoxController::ContentViewController::handleEvent(
Ion::Events::Event event) {
44 m_firstSelectedRow = 0;
45 app()->dismissModalViewController();
49 m_firstSelectedRow = m_previousSelectedRow;
51 m_selectableTableView.deselectTable();
52 m_currentPage = Page::RootMenu;
54 app()->setFirstResponder(
this);
58 if (m_currentPage == Page::RootMenu) {
59 m_previousSelectedRow = selectedRow();
60 m_firstSelectedRow = 0;
61 m_selectableTableView.deselectTable();
62 m_currentPage = pageAtIndex(m_previousSelectedRow);
63 app()->setFirstResponder(
this);
66 m_firstSelectedRow = 0;
68 putLabelAtIndexInBuffer(selectedRow(), label);
69 const char * editedText = label;
70 m_textFieldCaller->handleEventWithText(editedText);
72 m_selectableTableView.deselectTable();
73 m_currentPage = Page::RootMenu;
75 app()->dismissModalViewController();
79 if (m_currentPage == Page::Scalar) {
80 const Symbol symbol(
'A'+selectedRow());
81 m_context->setExpressionForSymbolName(
nullptr, &symbol, *m_context);
83 if (m_currentPage == Page::Matrix) {
84 const Symbol symbol = Symbol::matrixSymbol(
'0'+(
char)selectedRow());
85 m_context->setExpressionForSymbolName(
nullptr, &symbol, *m_context);
87 m_selectableTableView.reloadData();
94 switch (m_currentPage) {
96 return k_numberOfMenuRows;
98 return GlobalContext::k_maxNumberOfScalarExpressions;
101 return GlobalContext::k_maxNumberOfListExpressions;
104 return GlobalContext::k_maxNumberOfMatrixExpressions;
110 HighlightCell * VariableBoxController::ContentViewController::reusableCell(
int index,
int type) {
114 assert(index < k_maxNumberOfDisplayedRows);
115 return &m_leafCells[index];
117 assert(index < k_numberOfMenuRows);
118 return &m_nodeCells[index];
121 int VariableBoxController::ContentViewController::reusableCellCount(
int type) {
124 return k_maxNumberOfDisplayedRows;
126 return k_numberOfMenuRows;
129 void VariableBoxController::ContentViewController::willDisplayCellForIndex(
HighlightCell * cell,
int index) {
130 if (m_currentPage == Page::RootMenu) {
131 I18n::Message label = nodeLabelAtIndex(index);
138 putLabelAtIndexInBuffer(index, label);
140 const Expression * evaluation = expressionForIndex(index);
141 if (m_currentPage == Page::Scalar) {
153 const Matrix * matrixEvaluation =
static_cast<const Matrix *
>(evaluation);
155 char buffer[2*PrintFloat::bufferSizeForFloatsWithPrecision(2)+1];
156 int numberOfChars = PrintFloat::convertFloatToText<float>(matrixEvaluation->
numberOfRows(), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, PrintFloat::Mode::Decimal);
157 buffer[numberOfChars++] =
'x';
158 PrintFloat::convertFloatToText<float>(matrixEvaluation->
numberOfColumns(), buffer+numberOfChars, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, PrintFloat::Mode::Decimal);
166 KDCoordinate VariableBoxController::ContentViewController::rowHeight(
int index) {
167 if (m_currentPage == Page::RootMenu || m_currentPage == Page::Scalar) {
171 if (expressionLayout) {
172 return expressionLayout->
size().
height()+k_leafMargin;
177 KDCoordinate VariableBoxController::ContentViewController::cumulatedHeightFromIndex(
int j) {
179 for (
int k = 0; k < j; k++) {
180 result += rowHeight(k);
185 int VariableBoxController::ContentViewController::indexFromCumulatedHeight(
KDCoordinate offsetY) {
189 result += rowHeight(j++);
191 return (result < offsetY || offsetY == 0) ? j : j - 1;
194 int VariableBoxController::ContentViewController::typeAtLocation(
int i,
int j) {
195 if (m_currentPage == Page::RootMenu) {
201 const Expression * VariableBoxController::ContentViewController::expressionForIndex(
int index) {
202 if (m_currentPage == Page::Scalar) {
204 return m_context->expressionForSymbol(&symbol);
206 if (m_currentPage == Page::Matrix) {
207 const Symbol symbol = Symbol::matrixSymbol(
'0'+(
char)index);
208 return m_context->expressionForSymbol(&symbol);
211 if (m_currentPage == Page::List) {
218 ExpressionLayout * VariableBoxController::ContentViewController::expressionLayoutForIndex(
int index) {
219 if (m_currentPage == Page::Matrix) {
220 const Symbol symbol = Symbol::matrixSymbol(
'0'+(
char)index);
221 return m_context->expressionLayoutForSymbol(&symbol);
224 if (m_currentPage == Page::List) {
231 VariableBoxController::ContentViewController::Page VariableBoxController::ContentViewController::pageAtIndex(
int index) {
233 Page pages[3] = {Page::Scalar, Page::List, Page::Matrix};
235 Page pages[2] = {Page::Scalar, Page::Matrix};
240 void VariableBoxController::ContentViewController::putLabelAtIndexInBuffer(
int index,
char * buffer) {
241 if (m_currentPage == Page::Scalar) {
242 buffer[0] =
'A' + index;
246 if (m_currentPage == Page::List) {
248 buffer[1] =
'0' + index;
252 if (m_currentPage == Page::Matrix) {
254 buffer[1] =
'0' + index;
259 I18n::Message VariableBoxController::ContentViewController::nodeLabelAtIndex(
int index) {
260 assert(m_currentPage == Page::RootMenu);
262 I18n::Message labels[3] = {I18n::Message::Number, I18n::Message::List, I18n::Message::Matrix};
264 I18n::Message labels[2] = {I18n::Message::Number, I18n::Message::Matrix};
266 return labels[index];
269 void VariableBoxController::ContentViewController::setTextFieldCaller(
TextField * textField) {
270 m_textFieldCaller = textField;
273 void VariableBoxController::ContentViewController::reloadData() {
274 m_selectableTableView.reloadData();
277 void VariableBoxController::ContentViewController::resetPage() {
279 m_currentPage = Page::RootMenu;
281 m_currentPage = Page::Scalar;
285 void VariableBoxController::ContentViewController::viewDidDisappear() {
286 m_selectableTableView.deselectTable();
292 m_contentViewController(this, context)
301 m_contentViewController.setTextFieldCaller(textField);
306 m_contentViewController.resetPage();
307 m_contentViewController.reloadData();
int numberOfColumns() const
void setTextFieldCaller(TextField *textField)
void setLabel(const char *text)
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
void viewDidDisappear() override
constexpr KDColor KDColorWhite
void setExpressionLayout(Poincare::ExpressionLayout *expressionLayout)
void viewDidDisappear() override
void displayExpression(bool displayExpression)
static constexpr int LargeNumberOfSignificantDigits
void viewWillAppear() override
void setMessage(I18n::Message message)
void viewWillAppear() override
void setFirstResponder(Responder *responder)
static constexpr KDCoordinate ToolboxRowHeight
VariableBoxController(MenuController *menuController, ScriptStore *scriptStore)
virtual void viewDidDisappear()
void setSubtitle(const char *text)
constexpr uint8_t numberOfRows
void didBecomeFirstResponder() override
virtual int writeTextInBuffer(char *buffer, int bufferSize, int numberOfSignificantDigits=PrintFloat::k_numberOfStoredSignificantDigits) const =0
constexpr Event Backspace
constexpr KDCoordinate height() const