diff --git a/poincare/Makefile b/poincare/Makefile index a5a5f5548..c778125ba 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -85,6 +85,9 @@ objs += $(addprefix poincare/src/,\ objs += $(addprefix poincare/src/layout/,\ baseline_relative_layout.o\ bracket_layout.o\ + bracket_left_layout.o\ + bracket_left_right_layout.o\ + bracket_right_layout.o\ condensed_sum_layout.o\ conjugate_layout.o\ editable_baseline_relative_layout.o\ diff --git a/poincare/src/layout/bracket_left_layout.cpp b/poincare/src/layout/bracket_left_layout.cpp new file mode 100644 index 000000000..f9024923e --- /dev/null +++ b/poincare/src/layout/bracket_left_layout.cpp @@ -0,0 +1,12 @@ +#include "bracket_left_layout.h" + +namespace Poincare { + +void BracketLeftLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + //TODO Make sure m_operandHeight is up-to-date. + ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y(), k_lineThickness, m_operandHeight), expressionColor); + ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y(), k_bracketWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y() + m_operandHeight, k_bracketWidth, k_lineThickness), expressionColor); +} + +} diff --git a/poincare/src/layout/bracket_left_layout.h b/poincare/src/layout/bracket_left_layout.h new file mode 100644 index 000000000..ce025ec99 --- /dev/null +++ b/poincare/src/layout/bracket_left_layout.h @@ -0,0 +1,17 @@ +#ifndef POINCARE_BRACKET_LEFT_LAYOUT_H +#define POINCARE_BRACKET_LEFT_LAYOUT_H + +#include + +namespace Poincare { + +class BracketLeftLayout : public BracketLeftRightLayout { +public: + using BracketLeftRightLayout::BracketLeftRightLayout; +protected: + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; +}; + +} + +#endif diff --git a/poincare/src/layout/bracket_left_right_layout.cpp b/poincare/src/layout/bracket_left_right_layout.cpp new file mode 100644 index 000000000..44c6eaa79 --- /dev/null +++ b/poincare/src/layout/bracket_left_right_layout.cpp @@ -0,0 +1,43 @@ +#include "bracket_left_right_layout.h" +#include +extern "C" { +#include +#include +} + +namespace Poincare { + +BracketLeftRightLayout::BracketLeftRightLayout() : + ExpressionLayout(), + m_operandHeight(36) //TODO +{ +} + +bool BracketLeftRightLayout::moveLeft(ExpressionLayoutCursor * cursor) { + assert(cursor->pointedExpressionLayout() == this); + // Case: Right. + // Go Left. + if (cursor->position() == ExpressionLayoutCursor::Position::Right) { + cursor->setPosition(ExpressionLayoutCursor::Position::Left); + return true; + } + assert(cursor->position() == ExpressionLayoutCursor::Position::Left); + // Case: Left. + // Ask the parent. + if (m_parent) { + return m_parent->moveLeft(cursor); + } + return false; +} + +KDSize BracketLeftRightLayout::computeSize() { + //TODO: compute the operandHeight according to the brothers + return KDSize(k_externWidthMargin + k_lineThickness + k_bracketWidth + k_widthMargin, m_operandHeight); +} + +KDPoint BracketLeftRightLayout::positionOfChild(ExpressionLayout * child) { + assert(false); + return KDPointZero; +} + +} diff --git a/poincare/src/layout/bracket_left_right_layout.h b/poincare/src/layout/bracket_left_right_layout.h new file mode 100644 index 000000000..e65a4d446 --- /dev/null +++ b/poincare/src/layout/bracket_left_right_layout.h @@ -0,0 +1,30 @@ +#ifndef POINCARE_BRACKET_LEFT_RIGHT_LAYOUT_H +#define POINCARE_BRACKET_LEFT_RIGHT_LAYOUT_H + +#include +#include + +namespace Poincare { + +class BracketLeftRightLayout : public ExpressionLayout { +public: + BracketLeftRightLayout(); + ~BracketLeftRightLayout() {} + BracketLeftRightLayout(const BracketLeftRightLayout& other) = delete; + BracketLeftRightLayout(BracketLeftRightLayout&& other) = delete; + BracketLeftRightLayout& operator=(const BracketLeftRightLayout& other) = delete; + BracketLeftRightLayout& operator=(BracketLeftRightLayout&& other) = delete; + bool moveLeft(ExpressionLayoutCursor * cursor) override; + constexpr static KDCoordinate k_bracketWidth = 5; + constexpr static KDCoordinate k_lineThickness = 1; + constexpr static KDCoordinate k_widthMargin = 5; + constexpr static KDCoordinate k_externWidthMargin = 2; +protected: + KDSize computeSize() override; + ExpressionLayout * child(uint16_t index) override { return nullptr; } + KDPoint positionOfChild(ExpressionLayout * child) override; + uint16_t m_operandHeight; +}; +} + +#endif diff --git a/poincare/src/layout/bracket_right_layout.cpp b/poincare/src/layout/bracket_right_layout.cpp new file mode 100644 index 000000000..3eac6ba5e --- /dev/null +++ b/poincare/src/layout/bracket_right_layout.cpp @@ -0,0 +1,19 @@ +#include "bracket_right_layout.h" + +namespace Poincare { + +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); +} + +} + + + + + + + diff --git a/poincare/src/layout/bracket_right_layout.h b/poincare/src/layout/bracket_right_layout.h new file mode 100644 index 000000000..a9d9c7c79 --- /dev/null +++ b/poincare/src/layout/bracket_right_layout.h @@ -0,0 +1,17 @@ +#ifndef POINCARE_BRACKET_RIGHT_LAYOUT_H +#define POINCARE_BRACKET_RIGHT_LAYOUT_H + +#include + +namespace Poincare { + +class BracketRightLayout : public BracketLeftRightLayout { +public: + using BracketLeftRightLayout::BracketLeftRightLayout; +protected: + void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; +}; + +} + +#endif