From 5a79139fb769c8e599f97d4fd0788de16bf4b048 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Fri, 5 Jul 2019 10:25:24 +0200 Subject: [PATCH] [apps/graph/list] Define PlotTypeHelper --- apps/graph/Makefile | 1 + apps/graph/list/type_helper.cpp | 37 +++++++++++++++++++++++++++++++++ apps/graph/list/type_helper.h | 19 +++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 apps/graph/list/type_helper.cpp create mode 100644 apps/graph/list/type_helper.h diff --git a/apps/graph/Makefile b/apps/graph/Makefile index 71fd982ac..67c70667d 100644 --- a/apps/graph/Makefile +++ b/apps/graph/Makefile @@ -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 \ diff --git a/apps/graph/list/type_helper.cpp b/apps/graph/list/type_helper.cpp new file mode 100644 index 000000000..917dc245c --- /dev/null +++ b/apps/graph/list/type_helper.cpp @@ -0,0 +1,37 @@ +#include "type_helper.h" +#include +#include +#include + +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); +} + +} + +} diff --git a/apps/graph/list/type_helper.h b/apps/graph/list/type_helper.h new file mode 100644 index 000000000..0d5aef810 --- /dev/null +++ b/apps/graph/list/type_helper.h @@ -0,0 +1,19 @@ +#ifndef GRAPH_LIST_TYPE_HELPER_H +#define GRAPH_LIST_TYPE_HELPER_H + +#include +#include + +namespace Graph { + +namespace PlotTypeHelper { + +constexpr static int NumberOfTypes = 3; +I18n::Message Message(int index); +Poincare::Layout Layout(int index); + +} + +} + +#endif