diff --git a/apps/settings/Makefile b/apps/settings/Makefile index ac039b8e7..9078f0463 100644 --- a/apps/settings/Makefile +++ b/apps/settings/Makefile @@ -3,6 +3,7 @@ snapshot_headers += apps/settings/app.h app_objs += $(addprefix apps/settings/,\ app.o\ + helpers.o\ language_controller.o\ main_controller.o\ settings_message_tree.o\ diff --git a/apps/settings/helpers.cpp b/apps/settings/helpers.cpp new file mode 100644 index 000000000..2581a0a4c --- /dev/null +++ b/apps/settings/helpers.cpp @@ -0,0 +1,27 @@ +#include "helpers.h" +#include +#include +#include "../../poincare/src/layout/horizontal_layout.h" +#include "../../poincare/src/layout/vertical_offset_layout.h" + +using namespace Poincare; + +namespace Settings { +namespace Helpers { + +ExpressionLayout * CartesianComplexFormat(KDText::FontSize fontSize) { + const char text[] = {'a','+', Ion::Charset::IComplex, 'b', ' '}; + return LayoutEngine::createStringLayout(text, sizeof(text), fontSize); +} + +ExpressionLayout * PolarComplexFormat(KDText::FontSize fontSize) { + const char base[] = {'r', Ion::Charset::Exponential}; + const char superscript[] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' '}; + return new HorizontalLayout( + LayoutEngine::createStringLayout(base, sizeof(base), fontSize), + new VerticalOffsetLayout(LayoutEngine::createStringLayout(superscript, sizeof(superscript), fontSize), VerticalOffsetLayout::Type::Superscript, false), + false); +} + +} +} diff --git a/apps/settings/helpers.h b/apps/settings/helpers.h new file mode 100644 index 000000000..01dacd0ba --- /dev/null +++ b/apps/settings/helpers.h @@ -0,0 +1,15 @@ +#ifndef SETTINGS_HELPERS_H +#define SETTINGS_HELPERS_H + +#include + +namespace Settings { +namespace Helpers { + +Poincare::ExpressionLayout * CartesianComplexFormat(KDText::FontSize fontSize); +Poincare::ExpressionLayout * PolarComplexFormat(KDText::FontSize fontSize); + +} +} + +#endif diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 32a0f7c80..37c1fb4f6 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -1,10 +1,8 @@ #include "main_controller.h" +#include "helpers.h" #include "../global_preferences.h" #include "../i18n.h" -#include "../../poincare/src/layout/baseline_relative_layout.h" -#include "../../poincare/src/layout/string_layout.h" #include -#include using namespace Poincare; @@ -175,12 +173,9 @@ void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { m_complexFormatLayout = nullptr; } if (Preferences::sharedPreferences()->complexFormat() == Expression::ComplexFormat::Cartesian) { - const char text[] = {'a','+', Ion::Charset::IComplex, 'b', ' '}; - m_complexFormatLayout = new StringLayout(text, sizeof(text), KDText::FontSize::Small); + m_complexFormatLayout = Helpers::CartesianComplexFormat(KDText::FontSize::Small); } else { - const char base[] = {'r', Ion::Charset::Exponential}; - const char superscript[] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' '}; - m_complexFormatLayout = new BaselineRelativeLayout(new StringLayout(base, sizeof(base), KDText::FontSize::Small), new StringLayout(superscript, sizeof(superscript), KDText::FontSize::Small), BaselineRelativeLayout::Type::Superscript); + m_complexFormatLayout = Helpers::PolarComplexFormat(KDText::FontSize::Small); } MessageTableCellWithChevronAndExpression * myExpCell = (MessageTableCellWithChevronAndExpression *)cell; myExpCell->setExpressionLayout(m_complexFormatLayout); diff --git a/apps/settings/sub_controller.cpp b/apps/settings/sub_controller.cpp index 6d5b8ec4e..eacaededa 100644 --- a/apps/settings/sub_controller.cpp +++ b/apps/settings/sub_controller.cpp @@ -1,8 +1,7 @@ #include "sub_controller.h" +#include "helpers.h" #include "../global_preferences.h" #include "../apps_container.h" -#include "../../poincare/src/layout/baseline_relative_layout.h" -#include "../../poincare/src/layout/string_layout.h" #include #include @@ -22,11 +21,8 @@ SubController::SubController(Responder * parentResponder) : m_cells[i].setAccessoryFontSize(KDText::FontSize::Small); m_cells[i].setAccessoryTextColor(Palette::GreyDark); } - const char text[] = {'a','+', Ion::Charset::IComplex, 'b', ' '}; - m_complexFormatLayout[0] = new StringLayout(text, sizeof(text)); - const char base[] = {'r', Ion::Charset::Exponential}; - const char superscript[] = {Ion::Charset::IComplex, Ion::Charset::SmallTheta, ' '}; - m_complexFormatLayout[1] = new BaselineRelativeLayout(new StringLayout(base, sizeof(base)), new StringLayout(superscript, sizeof(superscript)), BaselineRelativeLayout::Type::Superscript); + m_complexFormatLayout[0] = Helpers::CartesianComplexFormat(KDText::FontSize::Large); + m_complexFormatLayout[1] = Helpers::PolarComplexFormat(KDText::FontSize::Large); for (int i = 0; i < 2; i++) { m_complexFormatCells[i].setExpressionLayout(m_complexFormatLayout[i]); }