term_sum_controller.cpp
1.74 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
#include "term_sum_controller.h"
#include "../../shared/text_field_delegate.h"
#include "../app.h"
#include "../../../poincare/src/layout/char_layout.h"
#include "../../../poincare/src/layout/horizontal_layout.h"
#include "../../../poincare/src/layout/vertical_offset_layout.h"
#include <cmath>
extern "C" {
#include <assert.h>
#include <stdlib.h>
}
using namespace Shared;
using namespace Poincare;
namespace Sequence {
TermSumController::TermSumController(Responder * parentResponder, GraphView * graphView, CurveViewRange * graphRange, CurveViewCursor * cursor) :
SumGraphController(parentResponder, graphView, graphRange, cursor, Ion::Charset::CapitalSigma)
{
}
const char * TermSumController::title() {
return I18n::translate(I18n::Message::TermSum);
}
bool TermSumController::moveCursorHorizontallyToPosition(double position) {
if (position < 0.0) {
return false;
}
return SumGraphController::moveCursorHorizontallyToPosition(std::round(position));
}
I18n::Message TermSumController::legendMessageAtStep(Step step) {
switch(step) {
case Step::FirstParameter:
return I18n::Message::SelectFirstTerm;
case Step::SecondParameter:
return I18n::Message::SelectLastTerm;
default:
return I18n::Message::Default;
}
}
double TermSumController::cursorNextStep(double x, int direction) {
double delta = direction > 0 ? 1.0 : -1.0;
return std::round(m_cursor->x()+delta);
}
ExpressionLayout * TermSumController::createFunctionLayout(const char * functionName) {
return new HorizontalLayout(
new CharLayout(functionName[0], KDText::FontSize::Small),
new VerticalOffsetLayout(
new CharLayout('n', KDText::FontSize::Small),
VerticalOffsetLayout::Type::Subscript,
false),
false);
}
}