diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index fa249584c..c63fb06e9 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -6,6 +6,7 @@ extern "C" { } #include "layout/horizontal_layout.h" #include "layout/string_layout.h" +#include "layout/parenthesis_layout.h" Addition::Addition(Expression ** operands, int numberOfOperands, @@ -81,7 +82,7 @@ ExpressionLayout * Addition::createLayout() const { children_layouts[0] = m_operands[0]->createLayout(); for (int i=1; icreateLayout(); + children_layouts[2*i] = m_operands[i]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[i]->createLayout()) : m_operands[i]->createLayout(); } return new HorizontalLayout(children_layouts, number_of_children); } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index bae3ad2e0..f216e33ea 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -6,6 +6,7 @@ extern "C" { #include #include "layout/string_layout.h" #include "layout/horizontal_layout.h" +#include "layout/parenthesis_layout.h" Expression::Type Multiplication::type() const { return Expression::Type::Multiplication; @@ -15,7 +16,7 @@ ExpressionLayout * Multiplication::createLayout() const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(3*sizeof(ExpressionLayout *)); children_layouts[0] = m_operands[0]->createLayout(); children_layouts[1] = new StringLayout("*", 1); - children_layouts[2] = m_operands[1]->createLayout(); + children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout(); return new HorizontalLayout(children_layouts, 3); } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 2a090ebc1..99834ef16 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -4,6 +4,7 @@ extern "C" { #include } #include "layout/horizontal_layout.h" +#include "layout/parenthesis_layout.h" #include "layout/string_layout.h" Opposite::Opposite(Expression * operand, bool cloneOperands) { @@ -52,7 +53,7 @@ ExpressionLayout * Opposite::createLayout() const { ExpressionLayout** children_layouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *)); char string[2] = {'-', '\0'}; children_layouts[0] = new StringLayout(string, 1); - children_layouts[1] = m_operand->createLayout(); + children_layouts[1] = m_operand->type() == Type::Opposite ? new ParenthesisLayout(m_operand->createLayout()) : m_operand->createLayout(); return new HorizontalLayout(children_layouts, 2); } diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index bbff4f167..7df835b29 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -6,6 +6,7 @@ extern "C" { #include #include "layout/horizontal_layout.h" #include "layout/string_layout.h" +#include "layout/parenthesis_layout.h" Expression * Subtraction::cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands) const { @@ -27,7 +28,7 @@ ExpressionLayout * Subtraction::createLayout() const { children_layouts[0] = m_operands[0]->createLayout(); char string[2] = {'-', '\0'}; children_layouts[1] = new StringLayout(string, 1); - children_layouts[2] = m_operands[1]->createLayout(); + children_layouts[2] = m_operands[1]->type() == Type::Opposite ? new ParenthesisLayout(m_operands[1]->createLayout()) : m_operands[1]->createLayout(); return new HorizontalLayout(children_layouts, 3); }