Display floor and ceiling symbols.

This commit is contained in:
Jacob Young
2017-09-16 07:45:41 -04:00
committed by EmilieNumworks
parent 2a2112396e
commit d5320280aa
8 changed files with 72 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ private:
return templatedComputeComplex(c);
}
template<typename T> Complex<T> templatedComputeComplex(const Complex<T> c) const;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
};
}

View File

@@ -19,6 +19,7 @@ private:
return templatedComputeComplex(c);
}
template<typename T> Complex<T> templatedComputeComplex(const Complex<T> c) const;
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override;
};
}

View File

@@ -1,4 +1,5 @@
#include <poincare/ceiling.h>
#include "layout/ceiling_layout.h"
extern "C" {
#include <assert.h>
@@ -32,6 +33,10 @@ Complex<T> Ceiling::templatedComputeComplex(const Complex<T> c) const {
return Complex<T>::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));
}
}

View File

@@ -1,4 +1,5 @@
#include <poincare/floor.h>
#include "layout/floor_layout.h"
extern "C" {
#include <assert.h>
@@ -32,6 +33,10 @@ Complex<T> Floor::templatedComputeComplex(const Complex<T> c) const {
return Complex<T>::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));
}
}

View File

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

View File

@@ -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;
};

View File

@@ -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

View File

@@ -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