[poincare] Bracket Left and Right layouts.

Change-Id: I05987e837324628b5141b31d01f59c88ae5ff3ce
This commit is contained in:
Léa Saviot
2017-12-15 12:04:19 +01:00
parent 8237bab64f
commit ab81f74bbf
7 changed files with 141 additions and 0 deletions

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
#ifndef POINCARE_BRACKET_LEFT_LAYOUT_H
#define POINCARE_BRACKET_LEFT_LAYOUT_H
#include <poincare/src/layout/bracket_left_right_layout.h>
namespace Poincare {
class BracketLeftLayout : public BracketLeftRightLayout {
public:
using BracketLeftRightLayout::BracketLeftRightLayout;
protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
};
}
#endif

View File

@@ -0,0 +1,43 @@
#include "bracket_left_right_layout.h"
#include <poincare/expression_layout_cursor.h>
extern "C" {
#include <assert.h>
#include <stdlib.h>
}
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;
}
}

View File

@@ -0,0 +1,30 @@
#ifndef POINCARE_BRACKET_LEFT_RIGHT_LAYOUT_H
#define POINCARE_BRACKET_LEFT_RIGHT_LAYOUT_H
#include <poincare/expression.h>
#include <poincare/expression_layout.h>
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

View File

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

View File

@@ -0,0 +1,17 @@
#ifndef POINCARE_BRACKET_RIGHT_LAYOUT_H
#define POINCARE_BRACKET_RIGHT_LAYOUT_H
#include <poincare/src/layout/bracket_left_right_layout.h>
namespace Poincare {
class BracketRightLayout : public BracketLeftRightLayout {
public:
using BracketLeftRightLayout::BracketLeftRightLayout;
protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
};
}
#endif