Numworks Epsilon  1.4.1
Graphing Calculator Operating System
type_parameter_controller.cpp
Go to the documentation of this file.
2 #include "list_controller.h"
3 #include "../app.h"
4 #include <assert.h>
5 #include "../../../poincare/src/layout/baseline_relative_layout.h"
6 #include "../../../poincare/src/layout/string_layout.h"
7 
8 using namespace Poincare;
9 
10 namespace Sequence {
11 
12 TypeParameterController::TypeParameterController(Responder * parentResponder, SequenceStore * sequenceStore, ListController * list, TableCell::Layout cellLayout,
13  KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) :
14  ViewController(parentResponder),
15  m_expliciteCell(I18n::Message::Explicit, cellLayout),
16  m_singleRecurrenceCell(I18n::Message::SingleRecurrence, cellLayout),
17  m_doubleRecurenceCell(I18n::Message::DoubleRecurrence, cellLayout),
18  m_expressionLayouts{},
19  m_selectableTableView(this),
20  m_sequenceStore(sequenceStore),
21  m_sequence(nullptr),
22  m_listController(list)
23 {
24  m_selectableTableView.setMargins(topMargin, rightMargin, bottomMargin, leftMargin);
25  m_selectableTableView.setShowsIndicators(false);
26 }
27 
29  for (int i = 0; i < k_totalNumberOfCell; i++) {
30  if (m_expressionLayouts[i]) {
31  delete m_expressionLayouts[i];
32  m_expressionLayouts[i] = nullptr;
33  }
34  }
35 }
36 
38  if (m_sequence) {
39  return I18n::translate(I18n::Message::SequenceType);
40  }
41  return I18n::translate(I18n::Message::ChooseSequenceType);
42 }
43 
45  return &m_selectableTableView;
46 }
47 
50  m_selectableTableView.reloadData();
51 }
52 
54  m_selectableTableView.deselectTable();
56 }
57 
60  app()->setFirstResponder(&m_selectableTableView);
61 }
62 
64  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
65  if (m_sequence) {
66  Sequence::Type sequenceType = (Sequence::Type)selectedRow();
67  if (m_sequence->type() != sequenceType) {
68  m_listController->selectPreviousNewSequenceCell();
69  m_sequence->setType(sequenceType);
70  // Invalidate sequence context cache when changing sequence type
71  static_cast<App *>(app())->localContext()->resetCache();
72  // Reset the first index if the new type is "Explicit"
73  if (sequenceType == Sequence::Type::Explicit) {
74  m_sequence->setInitialRank(0);
75  }
76  }
77  StackViewController * stack = stackController();
78  assert(stack->depth()>2);
79  stack->pop();
80  stack->pop();
81  return true;
82  }
83  Sequence * newSequence = m_sequenceStore->addEmptyFunction();
84  newSequence->setType((Sequence::Type)selectedRow());
86  return true;
87  }
88  if (event == Ion::Events::Left && m_sequence) {
89  stackController()->pop();
90  return true;
91  }
92  return false;
93 }
94 
96  return k_totalNumberOfCell;
97 };
98 
100  assert(index >= 0);
101  assert(index < k_totalNumberOfCell);
102  HighlightCell * cells[] = {&m_expliciteCell, &m_singleRecurrenceCell, &m_doubleRecurenceCell};
103  return cells[index];
104 }
105 
107  return k_totalNumberOfCell;
108 }
109 
111  if (m_sequence) {
113  }
114  return 50;
115 }
116 
118  const char * nextName = m_sequenceStore->firstAvailableName();
120  if (m_sequence) {
121  nextName = m_sequence->name();
123  }
124  const char * subscripts[3] = {"n", "n+1", "n+2"};
125  if (m_expressionLayouts[j]) {
126  delete m_expressionLayouts[j];
127  m_expressionLayouts[j] = nullptr;
128  }
129  m_expressionLayouts[j] = new BaselineRelativeLayout(new StringLayout(nextName, 1, size), new StringLayout(subscripts[j], strlen(subscripts[j]), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
131  myCell->setExpression(m_expressionLayouts[j]);
132 }
133 
135  m_sequence = sequence;
136 }
137 
138 StackViewController * TypeParameterController::stackController() const {
140 }
141 
142 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
const Event sequence[]
constexpr Event EXE
Definition: events.h:114
int16_t KDCoordinate
Definition: coordinate.h:6
Responder * parentResponder() const
Definition: responder.cpp:12
bool handleEvent(Ion::Events::Event event) override
void reloadData(bool setFirstResponder=true)
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
size_t strlen(const char *s)
Definition: strlen.c:3
void setExpression(Poincare::ExpressionLayout *expressionLayout)
virtual void viewWillAppear()
const char * name() const
Definition: function.cpp:68
void willDisplayCellAtLocation(HighlightCell *cell, int i, int j) override
list
Definition: grammar.h:158
void setType(Type type)
Definition: sequence.cpp:107
constexpr Event Left
Definition: events.h:61
Sequence * addEmptyFunction() override
static constexpr KDCoordinate ParameterCellHeight
Definition: metric.h:15
Definition: app.cpp:7
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
void setInitialRank(int rank)
Definition: sequence.cpp:138
virtual void viewDidDisappear()
App * app()
Definition: responder.cpp:77
void dismissModalViewController()
Definition: app.cpp:93
constexpr Event OK
Definition: events.h:65
FontSize
Definition: text.h:10
HighlightCell * reusableCell(int index) override
const char * firstAvailableName() override