6663b6c9
adorian
projet complet av...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#include "float_parameter_controller.h"
#include "../constant.h"
#include "../apps_container.h"
#include "../shared/poincare_helpers.h"
#include "text_field_delegate_app.h"
#include <assert.h>
#include <cmath>
using namespace Poincare;
namespace Shared {
FloatParameterController::FloatParameterController(Responder * parentResponder) :
DynamicViewController(parentResponder),
m_okButton(nullptr)
{
}
void FloatParameterController::didBecomeFirstResponder() {
if (selectedRow() >= 0) {
int selRow = selectedRow();
selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
int selColumn = selectedColumn();
selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
selectCellAtLocation(selColumn, selRow);
}
app()->setFirstResponder(selectableTableView());
}
void FloatParameterController::viewWillAppear() {
DynamicViewController::viewWillAppear();
if (selectedRow() == -1 || selectedRow() == numberOfRows()-1) {
selectCellAtLocation(0, 0);
} else {
int selRow = selectedRow();
selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
int selColumn = selectedColumn();
selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
selectCellAtLocation(selColumn, selRow);
}
selectableTableView()->reloadData();
}
void FloatParameterController::willExitResponderChain(Responder * nextFirstResponder) {
if (parentResponder() == nullptr) {
selectableTableView()->deselectTable();
selectableTableView()->scrollToCell(0,0);
}
}
bool FloatParameterController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Back) {
stackController()->pop();
return true;
}
return false;
}
int FloatParameterController::typeAtLocation(int i, int j) {
if (j == numberOfRows()-1) {
return 0;
}
return 1;
}
int FloatParameterController::reusableCellCount(int type) {
if (type == 0) {
return 1;
}
return reusableParameterCellCount(type);
}
HighlightCell * FloatParameterController::reusableCell(int index, int type) {
if (type == 0) {
return m_okButton;
}
return reusableParameterCell(index, type);
}
KDCoordinate FloatParameterController::rowHeight(int j) {
if (j == numberOfRows()-1) {
return Metric::ParameterCellHeight+k_buttonMargin;
}
return Metric::ParameterCellHeight;
}
KDCoordinate FloatParameterController::cumulatedHeightFromIndex(int j) {
if (j == numberOfRows()) {
return j*Metric::ParameterCellHeight+k_buttonMargin;
}
return Metric::ParameterCellHeight*j;
}
int FloatParameterController::indexFromCumulatedHeight(KDCoordinate offsetY) {
if (offsetY > numberOfRows()*Metric::ParameterCellHeight + k_buttonMargin) {
return numberOfRows();
}
return (offsetY - 1) / Metric::ParameterCellHeight;
}
void FloatParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
if (index == numberOfRows()-1) {
return;
}
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell;
if (myCell->isEditing()) {
return;
}
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
PrintFloat::convertFloatToText<double>(parameterAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, PrintFloat::Mode::Decimal);
myCell->setAccessoryText(buffer);
}
bool FloatParameterController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) {
return (event == Ion::Events::Down && selectedRow() < numberOfRows()-1)
|| (event == Ion::Events::Up && selectedRow() > 0)
|| TextFieldDelegate::textFieldShouldFinishEditing(textField, event);
}
bool FloatParameterController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
Context * globalContext = appsContainer->globalContext();
double floatBody = PoincareHelpers::ApproximateToScalar<double>(text, *globalContext);
if (std::isnan(floatBody) || std::isinf(floatBody)) {
app()->displayWarning(I18n::Message::UndefinedValue);
return false;
}
if (!setParameterAtIndex(selectedRow(), floatBody)) {
return false;
}
selectableTableView()->reloadCellAtLocation(0, activeCell());
selectableTableView()->reloadData();
if (event == Ion::Events::EXE || event == Ion::Events::OK) {
selectableTableView()->selectCellAtLocation(selectedColumn(), selectedRow()+1);
} else {
selectableTableView()->handleEvent(event);
}
return true;
}
TextFieldDelegateApp * FloatParameterController::textFieldDelegateApp() {
return (TextFieldDelegateApp *)app();
}
int FloatParameterController::activeCell() {
return selectedRow();
}
StackViewController * FloatParameterController::stackController() {
return (StackViewController *)parentResponder();
}
SelectableTableView * FloatParameterController::selectableTableView() {
return (SelectableTableView *)view();
}
void FloatParameterController::buttonAction() {
StackViewController * stack = stackController();
stack->pop();
}
I18n::Message FloatParameterController::okButtonText() {
return I18n::Message::Ok;
}
View * FloatParameterController::loadView() {
SelectableTableView * tableView = new SelectableTableView(this, this, this);
m_okButton = new ButtonWithSeparator(tableView, okButtonText(), Invocation([](void * context, void * sender) {
FloatParameterController * parameterController = (FloatParameterController *) context;
parameterController->buttonAction();
}, this));
return tableView;
}
void FloatParameterController::unloadView(View * view) {
delete m_okButton;
m_okButton = nullptr;
delete view;
}
}
|