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
|
#include "condensed_sum_layout.h"
#include <string.h>
#include <assert.h>
namespace Poincare {
CondensedSumLayout::CondensedSumLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout) :
ExpressionLayout(),
m_baseLayout(baseLayout),
m_subscriptLayout(subscriptLayout),
m_superscriptLayout(superscriptLayout)
{
m_baseLayout->setParent(this);
m_subscriptLayout->setParent(this);
if (m_superscriptLayout) {
m_superscriptLayout->setParent(this);
}
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
m_baseline = m_baseLayout->baseline() + max(0, superscriptSize.height() - m_baseLayout->size().height()/2);
}
CondensedSumLayout::~CondensedSumLayout() {
delete m_baseLayout;
delete m_subscriptLayout;
if (m_superscriptLayout) {
delete m_superscriptLayout;
}
}
void CondensedSumLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
// Nothing to draw
}
KDSize CondensedSumLayout::computeSize() {
KDSize baseSize = m_baseLayout->size();
KDSize subscriptSize = m_subscriptLayout->size();
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
return KDSize(baseSize.width() + max(subscriptSize.width(), superscriptSize.width()), max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height()));
}
ExpressionLayout * CondensedSumLayout::child(uint16_t index) {
switch (index) {
case 0:
return m_baseLayout;
case 1:
return m_subscriptLayout;
case 2:
return m_superscriptLayout;
default:
return nullptr;
}
}
KDPoint CondensedSumLayout::positionOfChild(ExpressionLayout * child) {
KDCoordinate x = 0;
KDCoordinate y = 0;
KDSize baseSize = m_baseLayout->size();
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
if (child == m_baseLayout) {
y = max(0, superscriptSize.height() - baseSize.height()/2);
}
if (child == m_subscriptLayout) {
x = baseSize.width();
y = max(baseSize.height()/2, superscriptSize.height());
}
if (child == m_superscriptLayout) {
x = baseSize.width();
}
return KDPoint(x,y);
}
}
|