Numworks Epsilon  1.4.1
Graphing Calculator Operating System
float_parameter_controller.cpp
Go to the documentation of this file.
2 #include "../constant.h"
3 #include "../apps_container.h"
5 #include <assert.h>
6 #include <cmath>
7 
8 using namespace Poincare;
9 
10 namespace Shared {
11 
12 FloatParameterController::FloatParameterController(Responder * parentResponder) :
13  DynamicViewController(parentResponder),
14  m_okButton(nullptr)
15 {
16 }
17 
19  if (selectedRow() >= 0) {
20  int selRow = selectedRow();
21  selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
22  int selColumn = selectedColumn();
23  selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
24  selectCellAtLocation(selColumn, selRow);
25  }
27 }
28 
31  if (selectedRow() == -1 || selectedRow() == numberOfRows()-1) {
33  } else {
34  int selRow = selectedRow();
35  selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
36  int selColumn = selectedColumn();
37  selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
38  selectCellAtLocation(selColumn, selRow);
39  }
41 }
42 
44  if (parentResponder() == nullptr) {
47  }
48 }
49 
51  if (event == Ion::Events::Back) {
52  stackController()->pop();
53  return true;
54  }
55  return false;
56 }
57 
59  if (j == numberOfRows()-1) {
60  return 0;
61  }
62  return 1;
63 }
64 
66  if (type == 0) {
67  return 1;
68  }
69  return reusableParameterCellCount(type);
70 }
71 
73  if (type == 0) {
74  return m_okButton;
75  }
76  return reusableParameterCell(index, type);
77 }
78 
80  if (j == numberOfRows()-1) {
81  return Metric::ParameterCellHeight+k_buttonMargin;
82  }
84 }
85 
87  if (j == numberOfRows()) {
88  return j*Metric::ParameterCellHeight+k_buttonMargin;
89  }
91 }
92 
94  if (offsetY > numberOfRows()*Metric::ParameterCellHeight + k_buttonMargin) {
95  return numberOfRows();
96  }
97  return (offsetY - 1) / Metric::ParameterCellHeight;
98 }
99 
101  if (index == numberOfRows()-1) {
102  return;
103  }
105  if (myCell->isEditing()) {
106  return;
107  }
108  char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
109  PrintFloat::convertFloatToText<double>(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
110  myCell->setAccessoryText(buffer);
111 }
112 
114  return (event == Ion::Events::Down && selectedRow() < numberOfRows()-1)
115  || (event == Ion::Events::Up && selectedRow() > 0)
117 }
118 
120  AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
121  Context * globalContext = appsContainer->globalContext();
122  double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
123  if (std::isnan(floatBody) || std::isinf(floatBody)) {
124  app()->displayWarning(I18n::Message::UndefinedValue);
125  return false;
126  }
127  if (!setParameterAtIndex(selectedRow(), floatBody)) {
128  return false;
129  }
132  if (event == Ion::Events::EXE || event == Ion::Events::OK) {
134  } else {
136  }
137  return true;
138 }
139 
140 TextFieldDelegateApp * FloatParameterController::textFieldDelegateApp() {
141  return (TextFieldDelegateApp *)app();
142 }
143 
145  return selectedRow();
146 }
147 
150 }
151 
153  return (SelectableTableView *)view();
154 }
155 
156 void FloatParameterController::buttonAction() {
158  stack->pop();
159 }
160 
161 I18n::Message FloatParameterController::okButtonText() {
162  return I18n::Message::Ok;
163 }
164 
166  SelectableTableView * tableView = new SelectableTableView(this, this, this);
167  m_okButton = new ButtonWithSeparator(tableView, okButtonText(), Invocation([](void * context, void * sender) {
168  FloatParameterController * parameterController = (FloatParameterController *) context;
169  parameterController->buttonAction();
170  }, this));
171  return tableView;
172 }
173 
175  delete m_okButton;
176  m_okButton = nullptr;
177  delete view;
178 }
179 
180 }
int indexFromCumulatedHeight(KDCoordinate offsetY) override
#define isinf(x)
Definition: math.h:44
int numberOfColumns() override
constexpr Event EXE
Definition: events.h:114
int16_t KDCoordinate
Definition: coordinate.h:6
Responder * parentResponder() const
Definition: responder.cpp:12
constexpr Event Up
Definition: events.h:62
constexpr Event Down
Definition: events.h:63
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
virtual SelectableTableView * selectableTableView()
virtual void scrollToCell(int i, int j)
Definition: table_view.cpp:26
constexpr Event Back
Definition: events.h:66
HighlightCell * reusableCell(int index, int type) override
void reloadData(bool setFirstResponder=true)
void displayWarning(I18n::Message warningMessage)
Definition: app.cpp:97
void reloadCellAtLocation(int i, int j)
Definition: table_view.cpp:49
void willExitResponderChain(Responder *nextFirstResponder) override
Poincare::Context * globalContext()
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
#define isnan(x)
Definition: math.h:43
virtual double parameterAtIndex(int index)=0
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
static constexpr KDCoordinate ParameterCellHeight
Definition: metric.h:15
void willDisplayCellForIndex(HighlightCell *cell, int index) override
virtual int numberOfRows()=0
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
bool handleEvent(Ion::Events::Event event) override
virtual bool handleEvent(Ion::Events::Event event) override
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
KDCoordinate cumulatedHeightFromIndex(int j) override