horizontal_layout.h
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef POINCARE_HORIZONTAL_LAYOUT_H
#define POINCARE_HORIZONTAL_LAYOUT_H
#include <poincare/dynamic_layout_hierarchy.h>
#include <poincare/layout_engine.h>
#include <poincare/expression_layout_cursor.h>
namespace Poincare {
/* WARNING: A Horizontal Layout should never have a Horizontal Layout child.
* For instance, use addOrMergeChildAtIndex to add an ExpressionLayout safely. */
class HorizontalLayout : public DynamicLayoutHierarchy {
friend class BinomialCoefficientLayout;
friend class IntegralLayout;
friend class MatrixLayout;
friend class SequenceLayout;
public:
using DynamicLayoutHierarchy::DynamicLayoutHierarchy;
ExpressionLayout * clone() const override;
void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override;
// Replace
void replaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild) override;
void replaceChildAndMoveCursor(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild, ExpressionLayoutCursor * cursor) override;
void addOrMergeChildAtIndex(ExpressionLayout * eL, int index, bool removeEmptyChildren);
// Tree navigation
ExpressionLayoutCursor cursorLeftOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
// Dynamic layout
void addChildrenAtIndex(const ExpressionLayout * const * operands, int numberOfOperands, int indexForInsertion, bool removeEmptyChildren) override;
bool addChildAtIndex(ExpressionLayout * operand, int index) override;
void removeChildAtIndex(int index, bool deleteAfterRemoval) override;
void mergeChildrenAtIndex(DynamicLayoutHierarchy * eL, int index, bool removeEmptyChildren) override;
// Serialization
int writeTextInBuffer(char * buffer, int bufferSize) const override;
// Cursor
ExpressionLayoutCursor equivalentCursor(ExpressionLayoutCursor cursor) override;
// Other
bool isHorizontal() const override { return true; }
bool isEmpty() const override { return m_numberOfChildren == 1 && child(0)->isEmpty(); }
bool isCollapsable(int * numberOfOpenParenthesis, bool goingLeft) const override { return m_numberOfChildren != 0; }
protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override {}
KDSize computeSize() override;
void computeBaseline() override;
KDPoint positionOfChild(ExpressionLayout * child) override;
void privateAddSibling(ExpressionLayoutCursor * cursor, ExpressionLayout * sibling, bool moveCursor) override;
private:
void privateReplaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild, ExpressionLayoutCursor * cursor);
void privateRemoveChildAtIndex(int index, bool deleteAfterRemoval, bool forceRemove);
int removeEmptyChildBeforeInsertionAtIndex(int index, bool shouldRemoveOnLeft);
};
}
#endif