[apps/graph/list] Define PlotTypeHelper

This commit is contained in:
Ruben Dashyan
2019-07-05 10:25:24 +02:00
committed by Léa Saviot
parent 0f3fc46ad1
commit 5a79139fb7
3 changed files with 57 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ app_graph_src = $(addprefix apps/graph/,\
list/list_controller.cpp \
list/list_parameter_controller.cpp \
list/text_field_function_title_cell.cpp \
list/type_helper.cpp \
values/derivative_parameter_controller.cpp \
values/function_parameter_controller.cpp \
values/values_controller.cpp \

View File

@@ -0,0 +1,37 @@
#include "type_helper.h"
#include <apps/i18n.h>
#include <poincare/expression.h>
#include <poincare/layout_helper.h>
namespace Graph {
namespace PlotTypeHelper {
I18n::Message Message(int index) {
assert(0 <= index && index < NumberOfTypes);
static constexpr I18n::Message message[NumberOfTypes] = {
I18n::Message::Cartesian,
I18n::Message::Polar,
I18n::Message::Parametric
};
return message[index];
}
Poincare::Layout Layout(int index) {
assert(0 <= index && index < NumberOfTypes);
static constexpr const char * texts[NumberOfTypes] = {
"y=f(x)",
"r=f(θ)",
"[[x][y]]=f(t)"
};
const char * text = texts[index];
if (index < 2) {
return Poincare::LayoutHelper::String(text, strlen(text));
}
Poincare::Expression parametric = Poincare::Expression::Parse(text);
return parametric.createLayout(Poincare::Preferences::PrintFloatMode::Decimal, 1);
}
}
}

View File

@@ -0,0 +1,19 @@
#ifndef GRAPH_LIST_TYPE_HELPER_H
#define GRAPH_LIST_TYPE_HELPER_H
#include <escher/i18n.h>
#include <poincare/layout.h>
namespace Graph {
namespace PlotTypeHelper {
constexpr static int NumberOfTypes = 3;
I18n::Message Message(int index);
Poincare::Layout Layout(int index);
}
}
#endif