From 8eed045315a3f87acea12fedf0019ac15f11e561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 13 Jan 2017 16:12:01 +0100 Subject: [PATCH] [poincare] Improve logarithm layout Change-Id: I0bd84672b5e24389308e7d1fd8609056f25cf2d4 --- poincare/include/poincare/function.h | 1 - poincare/include/poincare/logarithm.h | 1 + poincare/src/logarithm.cpp | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/poincare/include/poincare/function.h b/poincare/include/poincare/function.h index a868d20cb..173b54881 100644 --- a/poincare/include/poincare/function.h +++ b/poincare/include/poincare/function.h @@ -21,7 +21,6 @@ public: protected: Expression ** m_args; int m_numberOfArguments; -private: const char * m_name; }; diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index fe81ddb0d..38bfba520 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -10,6 +10,7 @@ public: Type type() const override; Expression * cloneWithDifferentOperands(Expression ** newOperands, int numberOfOperands, bool cloneOperands = true) const override; + ExpressionLayout * createLayout() const override; }; #endif diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index ede6cd6f4..eafefea6e 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -2,7 +2,12 @@ extern "C" { #include #include +#include } +#include "layout/horizontal_layout.h" +#include "layout/parenthesis_layout.h" +#include "layout/string_layout.h" +#include "layout/subscript_layout.h" Logarithm::Logarithm() : Function("log") @@ -28,3 +33,13 @@ float Logarithm::approximate(Context& context) const { } return log10f(m_args[1]->approximate(context))/log10f(m_args[0]->approximate(context)); } + +ExpressionLayout * Logarithm::createLayout() const { + if (m_numberOfArguments == 1) { + return Function::createLayout(); + } + ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); + childrenLayouts[0] = new SubscriptLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout()); + childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout()); + return new HorizontalLayout(childrenLayouts, 2); +}