From ac6c8379edbea2f3b32526313b1bc644db0bc7cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 10 Jan 2018 15:59:08 +0100 Subject: [PATCH] [apps] Enable to specialize the sum layout in Sum Graph Controller --- apps/graph/graph/integral_graph_controller.cpp | 7 +++++++ apps/graph/graph/integral_graph_controller.h | 1 + apps/sequence/graph/term_sum_controller.cpp | 6 ++++++ apps/sequence/graph/term_sum_controller.h | 1 + apps/shared/sum_graph_controller.cpp | 14 +++++++------- apps/shared/sum_graph_controller.h | 3 ++- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/apps/graph/graph/integral_graph_controller.cpp b/apps/graph/graph/integral_graph_controller.cpp index e6c61f05c..49fd032fc 100644 --- a/apps/graph/graph/integral_graph_controller.cpp +++ b/apps/graph/graph/integral_graph_controller.cpp @@ -1,5 +1,6 @@ #include "integral_graph_controller.h" #include "../../shared/text_field_delegate.h" +#include "../../../poincare/src/layout/string_layout.h" #include "../app.h" #include @@ -35,4 +36,10 @@ double IntegralGraphController::cursorNextStep(double x, int direction) { return (direction > 0 ? x + m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit : x - m_graphRange->xGridUnit()/k_numberOfCursorStepsInGradUnit); } +ExpressionLayout * IntegralGraphController::createFunctionLayout(const char * functionName) { + char buffer[7] = "0(x)dx"; + buffer[0] = functionName[0]; + return new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small); +} + } diff --git a/apps/graph/graph/integral_graph_controller.h b/apps/graph/graph/integral_graph_controller.h index d6a654402..5c0aaf8cc 100644 --- a/apps/graph/graph/integral_graph_controller.h +++ b/apps/graph/graph/integral_graph_controller.h @@ -14,6 +14,7 @@ public: private: I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; + Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) override; }; } diff --git a/apps/sequence/graph/term_sum_controller.cpp b/apps/sequence/graph/term_sum_controller.cpp index e40e92af4..7aca21bfd 100644 --- a/apps/sequence/graph/term_sum_controller.cpp +++ b/apps/sequence/graph/term_sum_controller.cpp @@ -1,5 +1,7 @@ #include "term_sum_controller.h" #include "../../shared/text_field_delegate.h" +#include "../../../poincare/src/layout/baseline_relative_layout.h" +#include "../../../poincare/src/layout/string_layout.h" #include "../app.h" #include @@ -43,4 +45,8 @@ double TermSumController::cursorNextStep(double x, int direction) { return std::round(m_cursor->x()+delta); } +ExpressionLayout * TermSumController::createFunctionLayout(const char * functionName) { + return new BaselineRelativeLayout(new StringLayout(functionName, 1, KDText::FontSize::Small), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); +} + } diff --git a/apps/sequence/graph/term_sum_controller.h b/apps/sequence/graph/term_sum_controller.h index a5472f8d4..11a5d904a 100644 --- a/apps/sequence/graph/term_sum_controller.h +++ b/apps/sequence/graph/term_sum_controller.h @@ -16,6 +16,7 @@ private: bool moveCursorHorizontallyToPosition(double position) override; I18n::Message legendMessageAtStep(Step step) override; double cursorNextStep(double position, int direction) override; + Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) override; }; } diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index a9d2826ad..f4b1a5c50 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -1,6 +1,5 @@ #include "sum_graph_controller.h" #include "../apps_container.h" -#include "../../poincare/src/layout/baseline_relative_layout.h" #include "../../poincare/src/layout/condensed_sum_layout.h" #include "../../poincare/src/layout/string_layout.h" #include "../../poincare/src/layout/horizontal_layout.h" @@ -194,7 +193,7 @@ bool SumGraphController::handleEnter() { m_step = (Step)((int)m_step+1); TextFieldDelegateApp * myApp = static_cast(app()); double sum = m_function->sumBetweenBounds(m_startSum, m_endSum, myApp->localContext()); - m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, m_function->name()); + m_legendView.setSumSymbol(m_step, m_startSum, m_endSum, sum, createFunctionLayout(m_function->name())); m_legendView.setLegendMessage(I18n::Message::Default, m_step); m_graphView->setAreaHighlightColor(true); m_graphView->setCursorView(nullptr); @@ -240,7 +239,8 @@ void SumGraphController::LegendView::setEditableZone(double d) { m_editableZone.setText(buffer); } -void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, const char * sequenceName) { +void SumGraphController::LegendView::setSumSymbol(Step step, double start, double end, double result, ExpressionLayout * functionLayout) { + assert(step == Step::Result || functionLayout == nullptr); if (m_sumLayout) { delete m_sumLayout; m_sumLayout = nullptr; @@ -263,10 +263,10 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl ExpressionLayout * childrenLayouts[3]; strlcpy(buffer, "= ", 3); Complex::convertFloatToText(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); - childrenLayouts[2] = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small); - childrenLayouts[1] = new BaselineRelativeLayout(new StringLayout(sequenceName, 1, KDText::FontSize::Small), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); - childrenLayouts[0] = m_sumLayout; - m_sumLayout = new HorizontalLayout(childrenLayouts, 3); + childrenLayouts[2] = new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small); + childrenLayouts[1] = functionLayout; + childrenLayouts[0] = m_sumLayout; + m_sumLayout = new HorizontalLayout(childrenLayouts, 3); } m_sum.setExpression(m_sumLayout); if (step == Step::Result) { diff --git a/apps/shared/sum_graph_controller.h b/apps/shared/sum_graph_controller.h index 93bf4bda1..94a29d986 100644 --- a/apps/shared/sum_graph_controller.h +++ b/apps/shared/sum_graph_controller.h @@ -41,6 +41,7 @@ private: constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/graphViewWidth virtual I18n::Message legendMessageAtStep(Step step) = 0; virtual double cursorNextStep(double position, int direction) = 0; + virtual Poincare::ExpressionLayout * createFunctionLayout(const char * functionName) = 0; Shared::InteractiveCurveViewRange * interactiveCurveViewRange() override { return m_graphRange; } Shared::CurveView * curveView() override { return m_graphView; } TextFieldDelegateApp * textFieldDelegateApp() override { @@ -60,7 +61,7 @@ private: void drawRect(KDContext * ctx, KDRect rect) const override; void setLegendMessage(I18n::Message message, Step step); void setEditableZone(double d); - void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, const char * sequenceName = nullptr); + void setSumSymbol(Step step, double start = NAN, double end = NAN, double result = NAN, Poincare::ExpressionLayout * sequenceName = nullptr); private: constexpr static KDCoordinate k_legendHeight = 35; constexpr static KDCoordinate k_editableZoneWidth = 4*KDText::charSize(KDText::FontSize::Small).width();