mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 11:39:58 +02:00
[poincare] Clean matrix layout
Change-Id: I86fce3e0915d1cab21b2b429525e31c9fdd993da
This commit is contained in:
@@ -50,13 +50,14 @@ objs += $(addprefix poincare/src/,\
|
||||
objs += $(addprefix poincare/src/layout/,\
|
||||
absolute_value_layout.o\
|
||||
baseline_relative_layout.o\
|
||||
bracket_layout.o\
|
||||
condensed_sum_layout.o\
|
||||
conjugate_layout.o\
|
||||
expression_layout.o\
|
||||
fraction_layout.o\
|
||||
grid_layout.o\
|
||||
horizontal_layout.o\
|
||||
integral_layout.o\
|
||||
matrix_layout.o\
|
||||
nth_root_layout.o\
|
||||
parenthesis_layout.o\
|
||||
product_layout.o\
|
||||
|
||||
49
poincare/src/layout/bracket_layout.cpp
Normal file
49
poincare/src/layout/bracket_layout.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "bracket_layout.h"
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
BracketLayout::BracketLayout(ExpressionLayout * operandLayout) :
|
||||
ExpressionLayout(),
|
||||
m_operandLayout(operandLayout)
|
||||
{
|
||||
m_operandLayout->setParent(this);
|
||||
m_baseline = m_operandLayout->baseline();
|
||||
}
|
||||
|
||||
BracketLayout::~BracketLayout() {
|
||||
delete m_operandLayout;
|
||||
}
|
||||
|
||||
void BracketLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
KDSize BracketLayout::computeSize() {
|
||||
KDSize operandSize = m_operandLayout->size();
|
||||
return KDSize(operandSize.width() + 2*k_widthMargin + 2*k_lineThickness, operandSize.height());
|
||||
}
|
||||
|
||||
ExpressionLayout * BracketLayout::child(uint16_t index) {
|
||||
if (index == 0) {
|
||||
return m_operandLayout;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KDPoint BracketLayout::positionOfChild(ExpressionLayout * child) {
|
||||
return KDPoint(k_widthMargin+k_lineThickness, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
28
poincare/src/layout/bracket_layout.h
Normal file
28
poincare/src/layout/bracket_layout.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef POINCARE_BRACKET_LAYOUT_H
|
||||
#define POINCARE_BRACKET_LAYOUT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class BracketLayout : public ExpressionLayout {
|
||||
public:
|
||||
BracketLayout(ExpressionLayout * operandLayout);
|
||||
~BracketLayout();
|
||||
protected:
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "matrix_layout.h"
|
||||
#include "grid_layout.h"
|
||||
extern "C" {
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
@@ -6,7 +6,7 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
MatrixLayout::MatrixLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int numberOfColumns) :
|
||||
GridLayout::GridLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int numberOfColumns) :
|
||||
ExpressionLayout(),
|
||||
m_entryLayouts(entryLayouts),
|
||||
m_numberOfRows(numberOfRows),
|
||||
@@ -18,14 +18,14 @@ MatrixLayout::MatrixLayout(ExpressionLayout ** entryLayouts, int numberOfRows, i
|
||||
m_baseline = height()/2 + KDText::stringSize(" ").height()/2;
|
||||
}
|
||||
|
||||
MatrixLayout::~MatrixLayout() {
|
||||
GridLayout::~GridLayout() {
|
||||
for (int i=0; i<m_numberOfColumns*m_numberOfRows; i++) {
|
||||
delete m_entryLayouts[i];
|
||||
}
|
||||
free(m_entryLayouts);
|
||||
}
|
||||
|
||||
KDCoordinate MatrixLayout::rowBaseline(int i) {
|
||||
KDCoordinate GridLayout::rowBaseline(int i) {
|
||||
KDCoordinate rowBaseline = 0;
|
||||
for (int j = 0; j < m_numberOfColumns; j++) {
|
||||
rowBaseline = max(rowBaseline, m_entryLayouts[i*m_numberOfColumns+j]->baseline());
|
||||
@@ -34,7 +34,7 @@ KDCoordinate MatrixLayout::rowBaseline(int i) {
|
||||
}
|
||||
|
||||
|
||||
KDCoordinate MatrixLayout::rowHeight(int i) {
|
||||
KDCoordinate GridLayout::rowHeight(int i) {
|
||||
KDCoordinate rowHeight = 0;
|
||||
KDCoordinate baseline = rowBaseline(i);
|
||||
for (int j = 0; j < m_numberOfColumns; j++) {
|
||||
@@ -43,16 +43,16 @@ KDCoordinate MatrixLayout::rowHeight(int i) {
|
||||
return baseline+rowHeight;
|
||||
}
|
||||
|
||||
KDCoordinate MatrixLayout::height() {
|
||||
KDCoordinate GridLayout::height() {
|
||||
KDCoordinate totalHeight = 0;
|
||||
for (int i = 0; i < m_numberOfRows; i++) {
|
||||
totalHeight += rowHeight(i);
|
||||
}
|
||||
totalHeight += (m_numberOfRows-1)*k_matrixEntryMargin;
|
||||
totalHeight += (m_numberOfRows-1)*k_gridEntryMargin;
|
||||
return totalHeight;
|
||||
}
|
||||
|
||||
KDCoordinate MatrixLayout::columnWidth(int j) {
|
||||
KDCoordinate GridLayout::columnWidth(int j) {
|
||||
KDCoordinate columnWidth = 0;
|
||||
for (int i = 0; i < m_numberOfRows; i++) {
|
||||
columnWidth = max(columnWidth, m_entryLayouts[i*m_numberOfColumns+j]->size().width());
|
||||
@@ -60,32 +60,31 @@ KDCoordinate MatrixLayout::columnWidth(int j) {
|
||||
return columnWidth;
|
||||
}
|
||||
|
||||
KDCoordinate MatrixLayout::width() {
|
||||
KDCoordinate GridLayout::width() {
|
||||
KDCoordinate totalWidth = 0;
|
||||
for (int j = 0; j < m_numberOfColumns; j++) {
|
||||
totalWidth += columnWidth(j);
|
||||
}
|
||||
totalWidth += (m_numberOfColumns-1)*k_matrixEntryMargin;
|
||||
return totalWidth + 2*k_matrixBracketWidth + 2*k_matrixBracketMargin;
|
||||
totalWidth += (m_numberOfColumns-1)*k_gridEntryMargin;
|
||||
return totalWidth;
|
||||
}
|
||||
|
||||
void MatrixLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
ctx->fillRect(KDRect(p.x(), p.y(), k_matrixBracketWidth, height()), expressionColor);
|
||||
ctx->fillRect(KDRect(p.x() + width() - k_matrixBracketWidth, p.y(), k_matrixBracketWidth, height()), expressionColor);
|
||||
void GridLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
// Nothing to do for a simple grid
|
||||
}
|
||||
|
||||
KDSize MatrixLayout::computeSize() {
|
||||
KDSize GridLayout::computeSize() {
|
||||
return KDSize(width(), height());
|
||||
}
|
||||
|
||||
ExpressionLayout * MatrixLayout::child(uint16_t index) {
|
||||
ExpressionLayout * GridLayout::child(uint16_t index) {
|
||||
if (index >= 0 && index < m_numberOfColumns*m_numberOfRows) {
|
||||
return m_entryLayouts[index];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
KDPoint MatrixLayout::positionOfChild(ExpressionLayout * child) {
|
||||
KDPoint GridLayout::positionOfChild(ExpressionLayout * child) {
|
||||
int rowIndex = 0;
|
||||
int columnIndex = 0;
|
||||
for (int i = 0; i < m_numberOfRows; i++) {
|
||||
@@ -101,12 +100,12 @@ KDPoint MatrixLayout::positionOfChild(ExpressionLayout * child) {
|
||||
for (int j = 0; j < columnIndex; j++) {
|
||||
x += columnWidth(j);
|
||||
}
|
||||
x += (columnWidth(columnIndex) - child->size().width())/2+ columnIndex * k_matrixEntryMargin + k_matrixBracketMargin + k_matrixBracketWidth;
|
||||
x += (columnWidth(columnIndex) - child->size().width())/2+ columnIndex * k_gridEntryMargin;
|
||||
KDCoordinate y = 0;
|
||||
for (int i = 0; i < rowIndex; i++) {
|
||||
y += rowHeight(i);
|
||||
}
|
||||
y += rowBaseline(rowIndex) - child->baseline() + rowIndex * k_matrixEntryMargin;
|
||||
y += rowBaseline(rowIndex) - child->baseline() + rowIndex * k_gridEntryMargin;
|
||||
return KDPoint(x, y);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
#ifndef POINCARE_MATRIX_LAYOUT_H
|
||||
#define POINCARE_MATRIX_LAYOUT_H
|
||||
#ifndef POINCARE_GRID_LAYOUT_H
|
||||
#define POINCARE_GRID_LAYOUT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class MatrixLayout : public ExpressionLayout {
|
||||
class GridLayout : public ExpressionLayout {
|
||||
public:
|
||||
MatrixLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int numberOfColumns);
|
||||
~MatrixLayout();
|
||||
GridLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int numberOfColumns);
|
||||
~GridLayout();
|
||||
protected:
|
||||
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_matrixEntryMargin = 4;
|
||||
constexpr static KDCoordinate k_matrixBracketMargin = 2;
|
||||
constexpr static KDCoordinate k_matrixBracketWidth = 2;
|
||||
constexpr static KDCoordinate k_gridEntryMargin = 6;
|
||||
KDCoordinate rowBaseline(int i);
|
||||
KDCoordinate rowHeight(int i);
|
||||
KDCoordinate height();
|
||||
@@ -4,7 +4,8 @@ extern "C" {
|
||||
}
|
||||
#include <poincare/matrix.h>
|
||||
#include <poincare/complex.h>
|
||||
#include "layout/matrix_layout.h"
|
||||
#include "layout/grid_layout.h"
|
||||
#include "layout/bracket_layout.h"
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
@@ -51,7 +52,7 @@ ExpressionLayout * Matrix::privateCreateLayout(FloatDisplayMode floatDisplayMode
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
childrenLayouts[i] = operand(i)->createLayout(floatDisplayMode, complexFormat);
|
||||
}
|
||||
return new MatrixLayout(childrenLayouts, numberOfRows(), numberOfColumns());
|
||||
return new BracketLayout(new GridLayout(childrenLayouts, numberOfRows(), numberOfColumns()));
|
||||
}
|
||||
|
||||
float Matrix::privateApproximate(Context& context, AngleUnit angleUnit) const {
|
||||
|
||||
Reference in New Issue
Block a user