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); +}