6663b6c9
adorian
projet complet av...
|
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
extern "C" {
#include <assert.h>
#include <kandinsky.h>
#include <stdlib.h>
}
#include "horizontal_layout.h"
#include "string_layout.h"
namespace Poincare {
HorizontalLayout::HorizontalLayout(ExpressionLayout ** children_layouts, int number_of_children) :
ExpressionLayout(), m_number_of_children(number_of_children) {
assert(number_of_children > 0);
m_children_layouts = new ExpressionLayout *[number_of_children];
for (int i=0; i<m_number_of_children; i++) {
m_children_layouts[i] = children_layouts[i];
m_children_layouts[i]->setParent(this);
if (m_children_layouts[i]->baseline() > m_baseline) {
m_baseline = m_children_layouts[i]->baseline();
}
}
}
HorizontalLayout::~HorizontalLayout() {
for (int i=0; i<m_number_of_children; i++) {
delete m_children_layouts[i];
}
delete[] m_children_layouts;
}
void HorizontalLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
}
KDSize HorizontalLayout::computeSize() {
KDCoordinate totalWidth = 0;
int i = 0;
KDCoordinate max_under_baseline = 0;
KDCoordinate max_above_baseline = 0;
while (ExpressionLayout * c = child(i++)) {
KDSize childSize = c->size();
totalWidth += childSize.width();
if (childSize.height() - c->baseline() > max_under_baseline) {
max_under_baseline = childSize.height() - c->baseline() ;
}
if (c->baseline() > max_above_baseline) {
max_above_baseline = c->baseline();
}
}
return KDSize(totalWidth, max_under_baseline + max_above_baseline);
}
ExpressionLayout * HorizontalLayout::child(uint16_t index) {
assert(index <= (unsigned int) m_number_of_children);
if (index < (unsigned int) m_number_of_children) {
return m_children_layouts[index];
} else {
return nullptr;
}
}
KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) {
KDCoordinate x = 0;
KDCoordinate y = 0;
uint16_t index = 0;
for (int i=0;i<m_number_of_children;i++) {
if (m_children_layouts[i] == child) {
index = i;
break;
}
}
if (index > 0) {
ExpressionLayout * previousChild = m_children_layouts[index-1];
assert(previousChild != nullptr);
x = previousChild->origin().x() + previousChild->size().width();
}
y = m_baseline - child->baseline();
return KDPoint(x, y);
}
}
|