Numworks Epsilon  1.4.1
Graphing Calculator Operating System
range_parameter_controller.cpp
Go to the documentation of this file.
3 #include "../apps_container.h"
4 #include <assert.h>
5 
6 using namespace Poincare;
7 
8 namespace Shared {
9 
10 RangeParameterController::RangeParameterController(Responder * parentResponder, InteractiveCurveViewRange * interactiveRange) :
11  FloatParameterController(parentResponder),
12  m_interactiveRange(interactiveRange),
13  m_xRangeCells{},
14  m_yRangeCells{},
15  m_yAutoCell(nullptr)
16 {
17 }
18 
20  return I18n::translate(I18n::Message::Axis);
21 }
22 
24  return k_numberOfTextCell+2;
25 }
26 
28  if (j == numberOfRows()-1) {
29  return 0;
30  }
31  if (j >= 0 && j < 2) {
32  return 1;
33  }
34  if (j == 2) {
35  return 2;
36  }
37  return 3;
38 }
39 
41  if (index == numberOfRows()-1) {
42  return;
43  }
44  if (index == 2) {
45  SwitchView * switchView = (SwitchView *)m_yAutoCell->accessoryView();
46  switchView->setState(m_interactiveRange->yAuto());
47  return;
48  }
50  I18n::Message labels[k_numberOfTextCell+1] = {I18n::Message::XMin, I18n::Message::XMax, I18n::Message::Default, I18n::Message::YMin, I18n::Message::YMax};
51  myCell->setMessage(labels[index]);
52  KDColor yColor = m_interactiveRange->yAuto() ? Palette::GreyDark : KDColorBlack;
53  KDColor colors[k_numberOfTextCell+1] = {KDColorBlack, KDColorBlack, KDColorBlack, yColor, yColor};
54  myCell->setTextColor(colors[index]);
56 }
57 
59  if (FloatParameterController::textFieldDidFinishEditing(textField, text, event)) {
61  return true;
62  }
63  return false;
64 }
65 
67  if (activeCell() == 2 && (event == Ion::Events::OK || event == Ion::Events::EXE)) {
68  m_interactiveRange->setYAuto(!m_interactiveRange->yAuto());
70  return true;
71  }
73 }
74 
75 double RangeParameterController::parameterAtIndex(int parameterIndex) {
76  ParameterGetterPointer getters[k_numberOfTextCell] = {&InteractiveCurveViewRange::xMin,
78  int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
79  return (m_interactiveRange->*getters[index])();
80 }
81 
82 bool RangeParameterController::setParameterAtIndex(int parameterIndex, double f) {
83  ParameterSetterPointer setters[k_numberOfTextCell] = {&InteractiveCurveViewRange::setXMin,
85  int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
86  (m_interactiveRange->*setters[index])(f);
87  return true;
88 }
89 
90 HighlightCell * RangeParameterController::reusableParameterCell(int index, int type) {
91  if (type == 2) {
92  assert(index == 0);
93  return m_yAutoCell;
94  }
95  if (type == 1) {
96  assert(index >= 0);
97  assert(index < k_numberOfEditableTextCell);
98  return m_xRangeCells[index];
99  }
100  assert(index >= 0);
101  assert(index < k_numberOfConvertibleTextCell);
102  return m_yRangeCells[index];
103 }
104 
105 int RangeParameterController::reusableParameterCellCount(int type) {
106  if (type == 2) {
107  return 1;
108  }
109  if (type == 1) {
110  return k_numberOfEditableTextCell;
111  }
112  return k_numberOfConvertibleTextCell;
113 }
114 
115 View * RangeParameterController::loadView() {
117  m_yAutoCell = new MessageTableCellWithSwitch(I18n::Message::YAuto);
118  for (int i = 0; i < k_numberOfEditableTextCell; i++) {
119  m_xRangeCells[i] = new MessageTableCellWithEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default);
120  }
121  for (int i = 0; i < k_numberOfConvertibleTextCell; i++) {
122  m_yRangeCells[i] = new MessageTableCellWithConvertibleEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default, m_interactiveRange);
123  }
124  return tableView;
125 }
126 
127 void RangeParameterController::unloadView(View * view) {
128  delete m_yAutoCell;
129  m_yAutoCell = nullptr;
130  for (int i = 0; i < k_numberOfEditableTextCell; i++) {
131  delete m_xRangeCells[i];
132  m_xRangeCells[i] = nullptr;
133  }
134  for (int i = 0; i < k_numberOfConvertibleTextCell; i++) {
135  delete m_yRangeCells[i];
136  m_yRangeCells[i] = nullptr;
137  }
139 }
140 
141 }
142 
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
void willDisplayCellForIndex(HighlightCell *cell, int index) override
#define assert(e)
Definition: assert.h:9
constexpr Event EXE
Definition: events.h:114
static constexpr KDColor GreyDark
Definition: palette.h:15
virtual SelectableTableView * selectableTableView()
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
constexpr KDColor KDColorBlack
Definition: color.h:41
bool handleEvent(Ion::Events::Event event) override
float(InteractiveCurveViewRange::* ParameterGetterPointer)()
void setMessage(I18n::Message message)
Definition: color.h:6
void willDisplayCellForIndex(HighlightCell *cell, int index) override
Definition: view.h:23
bool handleEvent(Ion::Events::Event event) override
void(InteractiveCurveViewRange::* ParameterSetterPointer)(float)
constexpr Event OK
Definition: events.h:65
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
void setState(bool state)
Definition: switch_view.cpp:45