diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index 22e32d06a..a5f865abc 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -19,6 +19,7 @@ private: return templatedComputeComplex(c); } template Complex templatedComputeComplex(const Complex c) const; + ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override; }; } diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index dda7ebeac..0ecbf9f6d 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -19,6 +19,7 @@ private: return templatedComputeComplex(c); } template Complex templatedComputeComplex(const Complex c) const; + ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override; }; } diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index 885a61c21..b77508094 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -1,4 +1,5 @@ #include +#include "layout/ceiling_layout.h" extern "C" { #include @@ -32,6 +33,10 @@ Complex Ceiling::templatedComputeComplex(const Complex c) const { return Complex::Float(std::ceil(c.a())); } +ExpressionLayout * Ceiling::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const { + assert(floatDisplayMode != FloatDisplayMode::Default); + assert(complexFormat != ComplexFormat::Default); + return new CeilingLayout(m_args[0]->createLayout(floatDisplayMode, complexFormat)); } - +} diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index f0378e74a..b82b247e5 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -1,4 +1,5 @@ #include +#include "layout/floor_layout.h" extern "C" { #include @@ -32,6 +33,10 @@ Complex Floor::templatedComputeComplex(const Complex c) const { return Complex::Float(std::floor(c.a())); } +ExpressionLayout * Floor::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const { + assert(floatDisplayMode != FloatDisplayMode::Default); + assert(complexFormat != ComplexFormat::Default); + return new FloorLayout(m_args[0]->createLayout(floatDisplayMode, complexFormat)); } - +} diff --git a/poincare/src/layout/bracket_layout.cpp b/poincare/src/layout/bracket_layout.cpp index 3f8d3620d..ab94719cf 100644 --- a/poincare/src/layout/bracket_layout.cpp +++ b/poincare/src/layout/bracket_layout.cpp @@ -19,17 +19,22 @@ BracketLayout::~BracketLayout() { } void BracketLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) { + const KDCoordinate k_widthMargin = widthMargin(); KDSize operandSize = m_operandLayout->size(); ctx->fillRect(KDRect(p.x(), p.y(), k_lineThickness, m_operandLayout->size().height()), expressionColor); ctx->fillRect(KDRect(p.x()+operandSize.width()+2*k_widthMargin+k_lineThickness, p.y(), k_lineThickness, m_operandLayout->size().height()), expressionColor); - ctx->fillRect(KDRect(p.x(), p.y(), k_bracketWidth, k_lineThickness), expressionColor); - ctx->fillRect(KDRect(p.x()+k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y(), k_bracketWidth, k_lineThickness), expressionColor); - ctx->fillRect(KDRect(p.x(), p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor); - ctx->fillRect(KDRect(p.x()+k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor); - + if (renderTopBar()) { + ctx->fillRect(KDRect(p.x(), p.y(), k_bracketWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x()+k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y(), k_bracketWidth, k_lineThickness), expressionColor); + } + if (renderBottomBar()) { + ctx->fillRect(KDRect(p.x(), p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor); + ctx->fillRect(KDRect(p.x()+k_lineThickness+operandSize.width()+2*k_widthMargin-k_bracketWidth, p.y()+operandSize.height()-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor); + } } KDSize BracketLayout::computeSize() { + const KDCoordinate k_widthMargin = widthMargin(); KDSize operandSize = m_operandLayout->size(); return KDSize(operandSize.width() + 2*k_widthMargin + 2*k_lineThickness, operandSize.height()); } @@ -42,8 +47,8 @@ ExpressionLayout * BracketLayout::child(uint16_t index) { } KDPoint BracketLayout::positionOfChild(ExpressionLayout * child) { + const KDCoordinate k_widthMargin = widthMargin(); return KDPoint(k_widthMargin+k_lineThickness, 0); } } - diff --git a/poincare/src/layout/bracket_layout.h b/poincare/src/layout/bracket_layout.h index 095ca82d2..4fca30e92 100644 --- a/poincare/src/layout/bracket_layout.h +++ b/poincare/src/layout/bracket_layout.h @@ -15,13 +15,15 @@ public: BracketLayout& operator=(const BracketLayout& other) = delete; BracketLayout& operator=(BracketLayout&& other) = delete; protected: + virtual KDCoordinate widthMargin() const { return 5; } + virtual bool renderTopBar() const { return true; } + virtual bool renderBottomBar() const { return true; } void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; KDSize computeSize() override; ExpressionLayout * child(uint16_t index) override; KDPoint positionOfChild(ExpressionLayout * child) override; private: constexpr static KDCoordinate k_bracketWidth = 5; - constexpr static KDCoordinate k_widthMargin = 5; constexpr static KDCoordinate k_lineThickness = 1; ExpressionLayout * m_operandLayout; }; diff --git a/poincare/src/layout/ceiling_layout.h b/poincare/src/layout/ceiling_layout.h new file mode 100644 index 000000000..6fe8d60a8 --- /dev/null +++ b/poincare/src/layout/ceiling_layout.h @@ -0,0 +1,22 @@ +#ifndef POINCARE_CEILING_LAYOUT_H +#define POINCARE_CEILING_LAYOUT_H + +#include "bracket_layout.h" + +namespace Poincare { + +class CeilingLayout : public BracketLayout { +public: + CeilingLayout(ExpressionLayout * operandLayout) : BracketLayout(operandLayout) {} + ~CeilingLayout() {} + CeilingLayout(const CeilingLayout& other) = delete; + CeilingLayout(CeilingLayout&& other) = delete; + CeilingLayout& operator=(const CeilingLayout& other) = delete; + CeilingLayout& operator=(CeilingLayout&& other) = delete; +protected: + bool renderBottomBar() const override { return false; } +}; + +} + +#endif diff --git a/poincare/src/layout/floor_layout.h b/poincare/src/layout/floor_layout.h new file mode 100644 index 000000000..17c994eb5 --- /dev/null +++ b/poincare/src/layout/floor_layout.h @@ -0,0 +1,22 @@ +#ifndef POINCARE_FLOOR_LAYOUT_H +#define POINCARE_FLOOR_LAYOUT_H + +#include "bracket_layout.h" + +namespace Poincare { + +class FloorLayout : public BracketLayout { +public: + FloorLayout(ExpressionLayout * operandLayout) : BracketLayout(operandLayout) {} + ~FloorLayout() {} + FloorLayout(const FloorLayout& other) = delete; + FloorLayout(FloorLayout&& other) = delete; + FloorLayout& operator=(const FloorLayout& other) = delete; + FloorLayout& operator=(FloorLayout&& other) = delete; +protected: + bool renderTopBar() const override { return false; } +}; + +} + +#endif