range_parameter_controller.cpp
4.7 KB
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
#include "range_parameter_controller.h"
#include "text_field_delegate_app.h"
#include "../apps_container.h"
#include <assert.h>
using namespace Poincare;
namespace Shared {
RangeParameterController::RangeParameterController(Responder * parentResponder, InteractiveCurveViewRange * interactiveRange) :
FloatParameterController(parentResponder),
m_interactiveRange(interactiveRange),
m_xRangeCells{},
m_yRangeCells{},
m_yAutoCell(nullptr)
{
}
const char * RangeParameterController::title() {
return I18n::translate(I18n::Message::Axis);
}
int RangeParameterController::numberOfRows() {
return k_numberOfTextCell+2;
}
int RangeParameterController::typeAtLocation(int i, int j) {
if (j == numberOfRows()-1) {
return 0;
}
if (j >= 0 && j < 2) {
return 1;
}
if (j == 2) {
return 2;
}
return 3;
}
void RangeParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
if (index == numberOfRows()-1) {
return;
}
if (index == 2) {
SwitchView * switchView = (SwitchView *)m_yAutoCell->accessoryView();
switchView->setState(m_interactiveRange->yAuto());
return;
}
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)cell;
I18n::Message labels[k_numberOfTextCell+1] = {I18n::Message::XMin, I18n::Message::XMax, I18n::Message::Default, I18n::Message::YMin, I18n::Message::YMax};
myCell->setMessage(labels[index]);
KDColor yColor = m_interactiveRange->yAuto() ? Palette::GreyDark : KDColorBlack;
KDColor colors[k_numberOfTextCell+1] = {KDColorBlack, KDColorBlack, KDColorBlack, yColor, yColor};
myCell->setTextColor(colors[index]);
FloatParameterController::willDisplayCellForIndex(cell, index);
}
bool RangeParameterController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
if (FloatParameterController::textFieldDidFinishEditing(textField, text, event)) {
selectableTableView()->reloadData();
return true;
}
return false;
}
bool RangeParameterController::handleEvent(Ion::Events::Event event) {
if (activeCell() == 2 && (event == Ion::Events::OK || event == Ion::Events::EXE)) {
m_interactiveRange->setYAuto(!m_interactiveRange->yAuto());
selectableTableView()->reloadData();
return true;
}
return FloatParameterController::handleEvent(event);
}
double RangeParameterController::parameterAtIndex(int parameterIndex) {
ParameterGetterPointer getters[k_numberOfTextCell] = {&InteractiveCurveViewRange::xMin,
&InteractiveCurveViewRange::xMax, &InteractiveCurveViewRange::yMin, &InteractiveCurveViewRange::yMax};
int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
return (m_interactiveRange->*getters[index])();
}
bool RangeParameterController::setParameterAtIndex(int parameterIndex, double f) {
ParameterSetterPointer setters[k_numberOfTextCell] = {&InteractiveCurveViewRange::setXMin,
&InteractiveCurveViewRange::setXMax, &InteractiveCurveViewRange::setYMin, &InteractiveCurveViewRange::setYMax};
int index = parameterIndex > 2 ? parameterIndex - 1 : parameterIndex;
(m_interactiveRange->*setters[index])(f);
return true;
}
HighlightCell * RangeParameterController::reusableParameterCell(int index, int type) {
if (type == 2) {
assert(index == 0);
return m_yAutoCell;
}
if (type == 1) {
assert(index >= 0);
assert(index < k_numberOfEditableTextCell);
return m_xRangeCells[index];
}
assert(index >= 0);
assert(index < k_numberOfConvertibleTextCell);
return m_yRangeCells[index];
}
int RangeParameterController::reusableParameterCellCount(int type) {
if (type == 2) {
return 1;
}
if (type == 1) {
return k_numberOfEditableTextCell;
}
return k_numberOfConvertibleTextCell;
}
View * RangeParameterController::loadView() {
SelectableTableView * tableView = (SelectableTableView *)FloatParameterController::loadView();
m_yAutoCell = new MessageTableCellWithSwitch(I18n::Message::YAuto);
for (int i = 0; i < k_numberOfEditableTextCell; i++) {
m_xRangeCells[i] = new MessageTableCellWithEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default);
}
for (int i = 0; i < k_numberOfConvertibleTextCell; i++) {
m_yRangeCells[i] = new MessageTableCellWithConvertibleEditableText(tableView, this, m_draftTextBuffer, I18n::Message::Default, m_interactiveRange);
}
return tableView;
}
void RangeParameterController::unloadView(View * view) {
delete m_yAutoCell;
m_yAutoCell = nullptr;
for (int i = 0; i < k_numberOfEditableTextCell; i++) {
delete m_xRangeCells[i];
m_xRangeCells[i] = nullptr;
}
for (int i = 0; i < k_numberOfConvertibleTextCell; i++) {
delete m_yRangeCells[i];
m_yRangeCells[i] = nullptr;
}
FloatParameterController::unloadView(view);
}
}