Numworks Epsilon  1.4.1
Graphing Calculator Operating System
interval_parameter_controller.cpp
Go to the documentation of this file.
2 #include <assert.h>
3 
4 namespace Shared {
5 
7  FloatParameterController(parentResponder),
8  m_interval(interval),
9  m_intervalCells{}
10 {
11 }
12 
14  return I18n::translate(I18n::Message::IntervalSet);
15 }
16 
18  return k_totalNumberOfCell+1;
19 }
20 
22  if (index == numberOfRows()-1) {
23  return;
24  }
26  I18n::Message labels[k_totalNumberOfCell] = {I18n::Message::XStart, I18n::Message::XEnd, I18n::Message::Step};
27  myCell->setMessage(labels[index]);
29 }
30 
32  return m_interval;
33 }
34 
35 double IntervalParameterController::parameterAtIndex(int index) {
37  return (m_interval->*getters[index])();
38 }
39 
40 bool IntervalParameterController::setParameterAtIndex(int parameterIndex, double f) {
41  if (f <= 0.0f && parameterIndex == 2) {
42  app()->displayWarning(I18n::Message::ForbiddenValue);
43  return false;
44  }
45  double start = parameterIndex == 0 ? f : m_interval->start();
46  double end = parameterIndex == 1 ? f : m_interval->end();
47  if (start > end) {
48  if (parameterIndex == 1) {
49  app()->displayWarning(I18n::Message::ForbiddenValue);
50  return false;
51  }
52  double g = f+1.0;
53  m_interval->setEnd(g);
54  }
56  (m_interval->*setters[parameterIndex])(f);
57  return true;
58 }
59 
60 HighlightCell * IntervalParameterController::reusableParameterCell(int index, int type) {
61  assert(index >= 0);
62  assert(index < k_totalNumberOfCell);
63  return m_intervalCells[index];
64 }
65 
67  if (event == Ion::Events::Left && stackController()->depth() > 2) {
68  stackController()->pop();
69  return true;
70  }
71  return false;
72 }
73 
74 int IntervalParameterController::reusableParameterCellCount(int type) {
75  return k_totalNumberOfCell;
76 }
77 
78 void IntervalParameterController::buttonAction() {
80  stack->pop();
81  if (stack->depth() > 1) {
82  stack->pop();
83  }
84 }
85 
86 View * IntervalParameterController::loadView() {
88  for (int i = 0; i < k_totalNumberOfCell; i++) {
89  m_intervalCells[i] = new MessageTableCellWithEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default);
90  }
91  return tableView;
92 }
93 
94 void IntervalParameterController::unloadView(View * view) {
95  for (int i = 0; i < k_totalNumberOfCell; i++) {
96  delete m_intervalCells[i];
97  m_intervalCells[i] = nullptr;
98  }
100 }
101 
102 }
void setStep(double f)
Definition: interval.cpp:56
#define assert(e)
Definition: assert.h:9
void(Interval::* SetterPointer)(double)
Definition: interval.h:33
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
bool setParameterAtIndex(int parameterIndex, double f) override
double start()
Definition: interval.cpp:34
void displayWarning(I18n::Message warningMessage)
Definition: app.cpp:97
constexpr Event Left
Definition: events.h:61
void start()
Definition: rt0.cpp:31
void setStart(double f)
Definition: interval.cpp:46
bool handleEvent(Ion::Events::Event event) override
void setMessage(I18n::Message message)
void willDisplayCellForIndex(HighlightCell *cell, int index) override
void willDisplayCellForIndex(HighlightCell *cell, int index) override
double end()
Definition: interval.cpp:38
Definition: view.h:23
IntervalParameterController(Responder *parentResponder, Interval *interval)
App * app()
Definition: responder.cpp:77
void setEnd(double f)
Definition: interval.cpp:51
double(Interval::* GetterPointer)()
Definition: interval.h:34
double step()
Definition: interval.cpp:42