mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 18:20:14 +01:00
[poincare] Matrix, Ceiling, Empty, CondensedSum and Conjugate Layouts
This commit is contained in:
@@ -9,7 +9,11 @@ objs += $(addprefix poincare/src/,\
|
||||
bracket_pair_layout_node.o\
|
||||
ceiling_layout_node.o\
|
||||
char_layout_node.o\
|
||||
condensed_sum_layout_node.o\
|
||||
conjugate_layout_node.o\
|
||||
empty_layout_node.o\
|
||||
floor_layout_node.o\
|
||||
matrix_layout_node.o\
|
||||
)
|
||||
|
||||
objs += $(addprefix poincare/src/,\
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <poincare/layout_node.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/layout_reference.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -26,6 +27,8 @@ public:
|
||||
}
|
||||
|
||||
// TreeNode
|
||||
static CondensedSumLayoutNode * FailedAllocationStaticNode();
|
||||
CondensedSumLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(CondensedSumLayoutNode); }
|
||||
int numberOfChildren() const override { return 3; }
|
||||
#if TREE_LOG
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
bool shouldCollapseSiblingsOnRight() const override { return true; }
|
||||
|
||||
// TreeNode
|
||||
static ConjugateLayoutNode * FailedAllocationStaticNode();
|
||||
ConjugateLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(ConjugateLayoutNode); }
|
||||
int numberOfChildren() const override { return 1; }
|
||||
#if TREE_LOG
|
||||
|
||||
@@ -74,32 +74,24 @@ private:
|
||||
|
||||
class EmptyLayoutRef : public LayoutReference {
|
||||
public:
|
||||
EmptyLayoutRef(const EmptyLayoutNode * n) : LayoutReference(n) {}
|
||||
EmptyLayoutRef(EmptyLayoutNode::Color color = EmptyLayoutNode::Color::Yellow, bool visible = true, KDText::FontSize fontSize = KDText::FontSize::Large, bool margins = true) :
|
||||
LayoutReference(TreePool::sharedPool()->createTreeNode<EmptyLayoutNode>())
|
||||
{
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
typedNode()->setColor(color);
|
||||
typedNode()->setVisible(visible);
|
||||
typedNode()->setFontSize(fontSize);
|
||||
typedNode()->setMargins(margins);
|
||||
}
|
||||
node()->setColor(color);
|
||||
node()->setVisible(visible);
|
||||
node()->setFontSize(fontSize);
|
||||
node()->setMargins(margins);
|
||||
}
|
||||
void setVisible(bool visible) {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
typedNode()->setVisible(visible);
|
||||
}
|
||||
node()->setVisible(visible);
|
||||
}
|
||||
|
||||
void setColor(EmptyLayoutNode::Color color) {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
typedNode()->setColor(color);
|
||||
}
|
||||
node()->setColor(color);
|
||||
}
|
||||
private:
|
||||
EmptyLayoutNode * typedNode() {
|
||||
assert(!isAllocationFailure());
|
||||
return static_cast<EmptyLayoutNode *>(node());
|
||||
}
|
||||
EmptyLayoutNode * node() { return static_cast<EmptyLayoutNode *>(LayoutReference::node()); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
m_numberOfColumns(0)
|
||||
{}
|
||||
|
||||
void setNumberOfRows(int numberOfRows) { m_numberOfRows = numberOfRows; }
|
||||
void setNumberOfColumns(int numberOfColumns) { m_numberOfColumns = numberOfColumns; }
|
||||
virtual void setNumberOfRows(int numberOfRows) { m_numberOfRows = numberOfRows; }
|
||||
virtual void setNumberOfColumns(int numberOfColumns) { m_numberOfColumns = numberOfColumns; }
|
||||
KDSize gridSize() const { return KDSize(width(), height()); }
|
||||
|
||||
// LayoutNode
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
using TreeByReference::operator==;
|
||||
using TreeByReference::operator!=;
|
||||
|
||||
LayoutReference(LayoutNode * node = nullptr) :
|
||||
LayoutReference(const LayoutNode * node = nullptr) :
|
||||
TreeByReference(node) {}
|
||||
|
||||
LayoutReference clone() const {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef POINCARE_MATRIX_LAYOUT_NODE_H
|
||||
#define POINCARE_MATRIX_LAYOUT_NODE_H
|
||||
|
||||
#include "layout_reference.h"
|
||||
#include "grid_layout_node.h"
|
||||
#include "layout_cursor.h"
|
||||
#include <poincare/allocation_failure_layout_node.h>
|
||||
#include <poincare/grid_layout_node.h>
|
||||
#include <poincare/layout_cursor.h>
|
||||
#include <poincare/layout_reference.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -29,6 +30,8 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
// TreeNode
|
||||
static MatrixLayoutNode * FailedAllocationStaticNode();
|
||||
MatrixLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(MatrixLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "MatrixLayout"; }
|
||||
@@ -52,57 +55,40 @@ private:
|
||||
void didReplaceChildAtIndex(int index, LayoutCursor * cursor, bool force) override;
|
||||
};
|
||||
|
||||
class AllocationFailureMatrixLayoutNode : public AllocationFailureLayoutNode<MatrixLayoutNode> {
|
||||
void setNumberOfRows(int numberOfRows) override {}
|
||||
void setNumberOfColumns(int numberOfColumns) override {}
|
||||
};
|
||||
|
||||
class MatrixLayoutRef : public LayoutReference {
|
||||
friend class MatrixLayoutNode;
|
||||
public:
|
||||
MatrixLayoutRef(const MatrixLayoutNode * n) : LayoutReference(n) {}
|
||||
MatrixLayoutRef() : LayoutReference(TreePool::sharedPool()->createTreeNode<MatrixLayoutNode>()) {}
|
||||
|
||||
MatrixLayoutRef(LayoutRef l1, LayoutRef l2, LayoutRef l3, LayoutRef l4) :
|
||||
MatrixLayoutRef()
|
||||
{
|
||||
addChildTreeAtIndex(l1, 0, 0);
|
||||
addChildTreeAtIndex(l2, 1, 1);
|
||||
addChildTreeAtIndex(l3, 2, 2);
|
||||
addChildTreeAtIndex(l4, 3, 3);
|
||||
addChildAtIndexInPlace(l1, 0, 0);
|
||||
addChildAtIndexInPlace(l2, 1, 1);
|
||||
addChildAtIndexInPlace(l3, 2, 2);
|
||||
addChildAtIndexInPlace(l4, 3, 3);
|
||||
setDimensions(2, 2);
|
||||
}
|
||||
|
||||
void setNumberOfRows(int count) {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
typedNode()->setNumberOfRows(count);
|
||||
}
|
||||
}
|
||||
void setNumberOfColumns(int count) {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
typedNode()->setNumberOfColumns(count);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasGreySquares() const {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
return typedNode()->hasGreySquares();
|
||||
}
|
||||
assert(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void addGreySquares() {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
return typedNode()->addGreySquares();
|
||||
}
|
||||
}
|
||||
|
||||
void removeGreySquares() {
|
||||
if (!(node()->isAllocationFailure())) {
|
||||
return typedNode()->removeGreySquares();
|
||||
}
|
||||
}
|
||||
bool hasGreySquares() const { node()->hasGreySquares(); }
|
||||
void addGreySquares() { node()->addGreySquares(); }
|
||||
void removeGreySquares() { node()->removeGreySquares(); }
|
||||
void setDimensions(int rows, int columns);
|
||||
void addChildTreeAtIndex(TreeReference t, int index, int currentNumberOfChildren) override;
|
||||
void addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) override;
|
||||
private:
|
||||
MatrixLayoutNode * typedNode() const { assert(!isAllocationFailure()); return static_cast<MatrixLayotuNode *>(node()); }
|
||||
void setNumberOfRows(int rows);
|
||||
void setNumberOfColumns(int columns);
|
||||
MatrixLayoutNode * node() const { return static_cast<MatrixLayoutNode *>(LayoutReference::node()); }
|
||||
void setNumberOfRows(int rows) {
|
||||
assert(rows >= 0);
|
||||
node()->setNumberOfRows(rows);
|
||||
}
|
||||
void setNumberOfColumns(int columns) {
|
||||
assert(columns >= 0);
|
||||
node()->setNumberOfColumns(columns);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
12
poincare/src/ceiling_layout_node.cpp
Normal file
12
poincare/src/ceiling_layout_node.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <poincare/ceiling_layout_node.h>
|
||||
#include <poincare/allocation_failure_layout_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
CeilingLayoutNode * CeilingLayoutNode::FailedAllocationStaticNode() {
|
||||
static AllocationFailureLayoutNode<CeilingLayoutNode> failure;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&failure);
|
||||
return &failure;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <poincare/condensed_sum_layout_node.h>
|
||||
#include <poincare/allocation_failure_layout_node.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -6,6 +7,12 @@ namespace Poincare {
|
||||
|
||||
static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; }
|
||||
|
||||
CondensedSumLayoutNode * CondensedSumLayoutNode::FailedAllocationStaticNode() {
|
||||
static AllocationFailureLayoutNode<CondensedSumLayoutNode> failure;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&failure);
|
||||
return &failure;
|
||||
}
|
||||
|
||||
KDCoordinate CondensedSumLayoutNode::computeBaseline() {
|
||||
KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->layoutSize();
|
||||
return baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->layoutSize().height()/2);
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
#include <poincare/conjugate_layout_node.h>
|
||||
#include <poincare/allocation_failure_layout_node.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <escher/metric.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
ConjugateLayoutNode * ConjugateLayoutNode::FailedAllocationStaticNode() {
|
||||
static AllocationFailureLayoutNode<ConjugateLayoutNode> failure;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&failure);
|
||||
return &failure;
|
||||
}
|
||||
|
||||
void ConjugateLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) {
|
||||
if (childLayout()
|
||||
&& cursor->layoutNode() == childLayout()
|
||||
|
||||
@@ -59,7 +59,7 @@ KDCoordinate EmptyLayoutNode::computeBaseline() {
|
||||
void EmptyLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor * cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) {
|
||||
/* The two cursor positions around an EmptyLayoutNode are equivalent, so both
|
||||
* should be checked. */
|
||||
assert(cursor->layoutReference() == this);
|
||||
assert(cursor->layoutNode() == this);
|
||||
LayoutCursor cursorResult = cursor->clone();
|
||||
LayoutNode::moveCursorVertically(direction, &cursorResult, shouldRecomputeLayout, equivalentPositionVisited);
|
||||
if (cursorResult.isDefined()) {
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
#include <poincare/matrix_layout_node.h>
|
||||
#include <poincare/bracket_pair_layout_node.h>
|
||||
#include <poincare/empty_layout_node.h>
|
||||
#include <poincare/square_bracket_layout_node.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <poincare/square_bracket_layout_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
MatrixLayoutNode * MatrixLayoutNode::FailedAllocationStaticNode() {
|
||||
static AllocationFailureMatrixLayoutNode failure;
|
||||
TreePool::sharedPool()->registerStaticNodeIfRequired(&failure);
|
||||
return &failure;
|
||||
}
|
||||
|
||||
// MatrixLayoutNode
|
||||
|
||||
void MatrixLayoutNode::addGreySquares() {
|
||||
@@ -126,7 +133,7 @@ int MatrixLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Prin
|
||||
buffer[numberOfChar++] = '[';
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1;}
|
||||
|
||||
numberOfChar += SerializationHelper::Infix(SerializableRef(this), buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfSignificantDigits, ",", i*m_numberOfColumns, i* m_numberOfColumns + maxColumnIndex);
|
||||
numberOfChar += SerializationHelper::Infix(this, buffer+numberOfChar, bufferSize-numberOfChar, floatDisplayMode, numberOfSignificantDigits, ",", i*m_numberOfColumns, i* m_numberOfColumns + maxColumnIndex);
|
||||
if (numberOfChar >= bufferSize-1) { return bufferSize-1; }
|
||||
|
||||
buffer[numberOfChar++] = ']';
|
||||
@@ -288,37 +295,15 @@ void MatrixLayoutNode::didReplaceChildAtIndex(int index, LayoutCursor * cursor,
|
||||
|
||||
// Matrix Layout Reference
|
||||
void MatrixLayoutRef::setDimensions(int rows, int columns) {
|
||||
if (isAllocationFailure()) {
|
||||
return;
|
||||
}
|
||||
assert(rows * columns = numberOfChildren());
|
||||
assert(rows * columns == numberOfChildren());
|
||||
setNumberOfRows(rows);
|
||||
setNumberOfColumns(columns);
|
||||
}
|
||||
|
||||
void MatrixLayoutRef::addChildAtIndexInPlace(TreeReference t, int index, int currentNumberOfChildren) {
|
||||
void MatrixLayoutRef::addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) {
|
||||
TreeByReference::addChildAtIndexInPlace(t, index, currentNumberOfChildren);
|
||||
if (isAllocationFailure()) {
|
||||
return;
|
||||
}
|
||||
setNumberOfRows(1);
|
||||
setNumberOfColumns(currentNumberOfChildren + 1);
|
||||
}
|
||||
|
||||
void MatrixLayoutRef::setNumberOfRows(int rows) {
|
||||
if (isAllocationFailure()) {
|
||||
return;
|
||||
}
|
||||
assert(rows >= 0);
|
||||
typedNode()->setNumberOfRows(rows);
|
||||
}
|
||||
|
||||
void MatrixLayoutRef::setNumberOfColumns(int columns) {
|
||||
if (isAllocationFailure()) {
|
||||
return;
|
||||
}
|
||||
assert(columns >= 0);
|
||||
typedNode()->setNumberOfColumns(columns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user