empty_layout.h
2.14 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_empty_layout_H
#define POINCARE_empty_layout_H
#include <poincare/static_layout_hierarchy.h>
#include <kandinsky/text.h>
#include <assert.h>
namespace Poincare {
class EmptyLayout : public StaticLayoutHierarchy<0> {
public:
enum class Color {
Yellow,
Grey
};
EmptyLayout(Color color = Color::Yellow, bool visible = true, KDText::FontSize size = KDText::FontSize::Large, bool margins = true);
ExpressionLayout * clone() const override;
// EmptyLayout
Color color() const { return m_color; }
void setColor(Color color) { m_color = color; }
bool isVisible() const { return m_isVisible; }
void setVisible(bool visible) { m_isVisible = visible; }
// User input
void deleteBeforeCursor(ExpressionLayoutCursor * cursor) override;
// Tree navigation
ExpressionLayoutCursor cursorLeftOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
ExpressionLayoutCursor cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) override;
// Serialization
int writeTextInBuffer(char * buffer, int bufferSize) const override;
// Other
bool isEmpty() const override { return true; }
protected:
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
KDSize computeSize() override;
void computeBaseline() override;
KDPoint positionOfChild(ExpressionLayout * child) override {
assert(false);
return KDPointZero;
}
void privateAddSibling(ExpressionLayoutCursor * cursor, ExpressionLayout * sibling, bool moveCursor) override;
private:
constexpr static KDCoordinate k_marginWidth = 1;
constexpr static KDCoordinate k_marginHeight = 3;
constexpr static KDCoordinate k_lineThickness = 1;
ExpressionLayoutCursor cursorVerticalOf(VerticalDirection direction, ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout, bool equivalentPositionVisited) override;
KDCoordinate height() const { return KDText::charSize(m_size).height() - 2*k_marginHeight; }
KDCoordinate width() const { return KDText::charSize(m_size).width() - 2*k_marginWidth; }
bool m_isVisible;
Color m_color;
KDText::FontSize m_size;
bool m_margins;
};
}
#endif