baseline_relative_layout.cpp
1.9 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
63
64
65
66
67
68
#include "baseline_relative_layout.h"
#include <string.h>
#include <assert.h>
namespace Poincare {
BaselineRelativeLayout::BaselineRelativeLayout(ExpressionLayout * baseLayout, ExpressionLayout * indiceLayout, Type type) :
ExpressionLayout(),
m_baseLayout(baseLayout),
m_indiceLayout(indiceLayout),
m_type(type)
{
m_baseLayout->setParent(this);
m_indiceLayout->setParent(this);
m_baseline = type == Type::Subscript ? m_baseLayout->baseline() :
m_indiceLayout->size().height() + m_baseLayout->baseline() - k_indiceHeight;
}
BaselineRelativeLayout::~BaselineRelativeLayout() {
delete m_baseLayout;
delete m_indiceLayout;
}
ExpressionLayout * BaselineRelativeLayout::baseLayout() {
return m_baseLayout;
}
ExpressionLayout * BaselineRelativeLayout::indiceLayout() {
return m_indiceLayout;
}
void BaselineRelativeLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
// There is nothing to draw for a subscript/superscript, only the position of the children matters
}
KDSize BaselineRelativeLayout::computeSize() {
KDSize baseSize = m_baseLayout->size();
KDSize indiceSize = m_indiceLayout->size();
return KDSize(baseSize.width() + indiceSize.width(), baseSize.height() + indiceSize.height() - k_indiceHeight);
}
ExpressionLayout * BaselineRelativeLayout::child(uint16_t index) {
switch (index) {
case 0:
return m_baseLayout;
case 1:
return m_indiceLayout;
default:
return nullptr;
}
}
KDPoint BaselineRelativeLayout::positionOfChild(ExpressionLayout * child) {
KDCoordinate x = 0;
KDCoordinate y = 0;
if (child == m_baseLayout && m_type == Type::Superscript) {
x = 0;
y = m_indiceLayout->size().height() - k_indiceHeight;
}
if (child == m_indiceLayout) {
x = m_baseLayout->size().width();
y = m_type == Type::Superscript ? 0 : m_baseLayout->size().height() - k_indiceHeight;
}
return KDPoint(x,y);
}
}