diff --git a/apps/expression_editor/controller.cpp b/apps/expression_editor/controller.cpp index 7e747e03d..1ed4f7d7e 100644 --- a/apps/expression_editor/controller.cpp +++ b/apps/expression_editor/controller.cpp @@ -64,6 +64,14 @@ bool Controller::handleMoveEvent(Ion::Events::Event event) { if (event == Ion::Events::Down) { return m_cursor.moveDown(); } + if (event == Ion::Events::ShiftLeft) { + //TODO + return false; + } + if (event == Ion::Events::ShiftRight) { + //TODO + return false; + } return false; } @@ -71,6 +79,25 @@ ExpressionLayout * Controller::handleAddEvent(Ion::Events::Event event) { if (event == Ion::Events::Division) { return m_cursor.addEmptyFractionLayout(); } + if (event == Ion::Events::XNT) { + //TODO + return nullptr; + } + if (event == Ion::Events::Exp) { + return m_cursor.addEmptyExponentialLayout(); + } + if (event == Ion::Events::Log) { + return m_cursor.addEmptyLogarithmLayout(); + } + if (event == Ion::Events::Power) { + return m_cursor.addEmptyPowerLayout(); + } + if (event == Ion::Events::Sqrt) { + return m_cursor.addEmptyRootLayout(); + } + if (event == Ion::Events::Square) { + return m_cursor.addEmptySquarePowerLayout(); + } if (event.hasText()) { return m_cursor.insertText(event.text()); } diff --git a/poincare/include/poincare/expression_layout_cursor.h b/poincare/include/poincare/expression_layout_cursor.h index 88b29d81f..d7bb195ff 100644 --- a/poincare/include/poincare/expression_layout_cursor.h +++ b/poincare/include/poincare/expression_layout_cursor.h @@ -43,7 +43,12 @@ public: bool moveDown(); /* Edition */ + ExpressionLayout * addEmptyExponentialLayout(); ExpressionLayout * addEmptyFractionLayout(); + ExpressionLayout * addEmptyLogarithmLayout(); + ExpressionLayout * addEmptyPowerLayout(); + ExpressionLayout * addEmptyRootLayout(); + ExpressionLayout * addEmptySquarePowerLayout(); ExpressionLayout * insertText(const char * text); private: diff --git a/poincare/src/expression_layout_cursor.cpp b/poincare/src/expression_layout_cursor.cpp index 1fc9935bc..8db913a3f 100644 --- a/poincare/src/expression_layout_cursor.cpp +++ b/poincare/src/expression_layout_cursor.cpp @@ -1,8 +1,15 @@ #include #include #include //TODO move from there. -#include //TODO move from there. +#include //TODO move from there. #include //TODO move from there. +#include //TODO move from there. +#include //TODO move from there. +#include //TODO move from there. +#include //TODO move from there. +#include //TODO move from there. +#include //TODO move from there. +#include #include namespace Poincare { @@ -45,6 +52,14 @@ bool ExpressionLayoutCursor::moveDown() { return m_pointedExpressionLayout->moveDown(this); } +ExpressionLayout * ExpressionLayoutCursor::addEmptyExponentialLayout() { + CharLayout * child1 = new CharLayout(Ion::Charset::Exponential); + EmptyVisibleLayout * child2 = new EmptyVisibleLayout(); + EditableBaselineRelativeLayout * newChild = new EditableBaselineRelativeLayout(child1, child2, BaselineRelativeLayout::Type::Superscript, false); + pointedExpressionLayout()->addBrother(this, newChild); + return child2; +} + ExpressionLayout * ExpressionLayoutCursor::addEmptyFractionLayout() { EmptyVisibleLayout * child1 = new EmptyVisibleLayout(); EmptyVisibleLayout * child2 = new EmptyVisibleLayout(); @@ -53,15 +68,61 @@ ExpressionLayout * ExpressionLayoutCursor::addEmptyFractionLayout() { return child1; } +ExpressionLayout * ExpressionLayoutCursor::addEmptyLogarithmLayout() { + StringLayout * child1 = new StringLayout("log", 3); + EmptyVisibleLayout * child2 = new EmptyVisibleLayout(); + EditableBaselineRelativeLayout * newChild = new EditableBaselineRelativeLayout(child1, child2, BaselineRelativeLayout::Type::Subscript, false); + m_pointedExpressionLayout->addBrother(this, newChild); + m_pointedExpressionLayout = newChild; + m_position = Position::Right; + return insertText("()"); +} + +ExpressionLayout * ExpressionLayoutCursor::addEmptyPowerLayout() { + EmptyVisibleLayout * child1 = new EmptyVisibleLayout(); + EmptyVisibleLayout * child2 = new EmptyVisibleLayout(); + EditableBaselineRelativeLayout * newChild = new EditableBaselineRelativeLayout(child1, child2, BaselineRelativeLayout::Type::Superscript, false); + m_pointedExpressionLayout->addBrother(this, newChild); + return child1; +} + +ExpressionLayout * ExpressionLayoutCursor::addEmptyRootLayout() { + EmptyVisibleLayout * child1 = new EmptyVisibleLayout(); + EmptyVisibleLayout * child2 = new EmptyVisibleLayout(); + NthRootLayout * newChild = new NthRootLayout(child1, child2, false); + m_pointedExpressionLayout->addBrother(this, newChild); + return child1; +} + +ExpressionLayout * ExpressionLayoutCursor::addEmptySquarePowerLayout() { + EmptyVisibleLayout * child1 = new EmptyVisibleLayout(); + CharLayout * child2 = new CharLayout('2'); + EditableBaselineRelativeLayout * newChild = new EditableBaselineRelativeLayout(child1, child2, BaselineRelativeLayout::Type::Superscript, false); + m_pointedExpressionLayout->addBrother(this, newChild); + return child1; +} + ExpressionLayout * ExpressionLayoutCursor::insertText(const char * text) { int textLength = strlen(text); if (textLength <= 0) { return nullptr; } - CharLayout * newChild = nullptr; + ExpressionLayout * newChild = nullptr; for (int i = 0; i < textLength; i++) { - newChild = new CharLayout(text[i]); - pointedExpressionLayout()->addBrother(this, newChild); + if (text[i] == '(') { + newChild = new ParenthesisLeftLayout(); + } else if (text[i] == ')') { + newChild = new ParenthesisRightLayout(); + } else if (text[i] == '[') { + newChild = new BracketLeftLayout(); + } else if (text[i] == ']') { + newChild = new BracketRightLayout(); + } else { + newChild = new CharLayout(text[i]); + } + m_pointedExpressionLayout->addBrother(this, newChild); + m_pointedExpressionLayout = newChild; + m_position = Position::Right; } assert(newChild != nullptr); return newChild; diff --git a/poincare/src/layout/bracket_left_right_layout.cpp b/poincare/src/layout/bracket_left_right_layout.cpp index 98d01121e..3a43c0536 100644 --- a/poincare/src/layout/bracket_left_right_layout.cpp +++ b/poincare/src/layout/bracket_left_right_layout.cpp @@ -9,7 +9,7 @@ namespace Poincare { BracketLeftRightLayout::BracketLeftRightLayout() : StaticLayoutHierarchy<0>(), - m_operandHeight(36) //TODO + m_operandHeight(18) //TODO { } @@ -50,12 +50,12 @@ bool BracketLeftRightLayout::moveRight(ExpressionLayoutCursor * cursor) { KDSize BracketLeftRightLayout::computeSize() { //TODO: compute the operandHeight according to the brothers - return KDSize(k_externWidthMargin + k_lineThickness + k_bracketWidth + k_widthMargin, m_operandHeight); + return KDSize(k_externWidthMargin + k_lineThickness + k_widthMargin, m_operandHeight); } void BracketLeftRightLayout::computeBaseline() { //TODO: compute the operandHeight according to the brothers - m_baseline = m_operandHeight; + m_baseline = m_operandHeight/2; m_baselined = true; } diff --git a/poincare/src/layout/bracket_right_layout.cpp b/poincare/src/layout/bracket_right_layout.cpp index 86c43e66f..c6f8bbb14 100644 --- a/poincare/src/layout/bracket_right_layout.cpp +++ b/poincare/src/layout/bracket_right_layout.cpp @@ -10,15 +10,8 @@ ExpressionLayout * BracketRightLayout::clone() const { void BracketRightLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { //TODO Make sure m_operandHeight is up-to-date. ctx->fillRect(KDRect(p.x()+k_widthMargin, p.y(), k_lineThickness, m_operandHeight), expressionColor); - ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth, p.y(), k_bracketWidth, k_lineThickness), expressionColor); - ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth, p.y() + m_operandHeight, k_bracketWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y(), k_bracketWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y() + m_operandHeight, k_bracketWidth, k_lineThickness), expressionColor); } } - - - - - - - diff --git a/poincare/src/layout/empty_visible_layout.h b/poincare/src/layout/empty_visible_layout.h index 7a88565b9..1a549d9ce 100644 --- a/poincare/src/layout/empty_visible_layout.h +++ b/poincare/src/layout/empty_visible_layout.h @@ -20,7 +20,7 @@ private: constexpr static KDCoordinate k_width = 7; constexpr static KDCoordinate k_height = 13; constexpr static KDCoordinate k_marginWidth = 1; - constexpr static KDCoordinate k_marginHeight = 3; + constexpr static KDCoordinate k_marginHeight = 2; constexpr static KDCoordinate k_lineThickness = 1; KDColor m_fillRectColor; diff --git a/poincare/src/layout/parenthesis_left_right_layout.cpp b/poincare/src/layout/parenthesis_left_right_layout.cpp index 1baceff6b..0764efa73 100644 --- a/poincare/src/layout/parenthesis_left_right_layout.cpp +++ b/poincare/src/layout/parenthesis_left_right_layout.cpp @@ -9,7 +9,7 @@ namespace Poincare { ParenthesisLeftRightLayout::ParenthesisLeftRightLayout() : StaticLayoutHierarchy<0>(), - m_operandHeight(36) //TODO + m_operandHeight(18) //TODO { computeBaseline(); }