Numworks Epsilon  1.4.1
Graphing Calculator Operating System
baseline_relative_layout.cpp
Go to the documentation of this file.
2 #include <string.h>
3 #include <assert.h>
4 
5 namespace Poincare {
6 
9  m_baseLayout(baseLayout),
10  m_indiceLayout(indiceLayout),
11  m_type(type)
12 {
13  m_baseLayout->setParent(this);
14  m_indiceLayout->setParent(this);
15  m_baseline = type == Type::Subscript ? m_baseLayout->baseline() :
16  m_indiceLayout->size().height() + m_baseLayout->baseline() - k_indiceHeight;
17 }
18 
20  delete m_baseLayout;
21  delete m_indiceLayout;
22 }
23 
25  return m_baseLayout;
26 }
27 
29  return m_indiceLayout;
30 }
31 
32 void BaselineRelativeLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
33  // There is nothing to draw for a subscript/superscript, only the position of the children matters
34 }
35 
37  KDSize baseSize = m_baseLayout->size();
38  KDSize indiceSize = m_indiceLayout->size();
39  return KDSize(baseSize.width() + indiceSize.width(), baseSize.height() + indiceSize.height() - k_indiceHeight);
40 }
41 
43  switch (index) {
44  case 0:
45  return m_baseLayout;
46  case 1:
47  return m_indiceLayout;
48  default:
49  return nullptr;
50  }
51 }
52 
54  KDCoordinate x = 0;
55  KDCoordinate y = 0;
56  if (child == m_baseLayout && m_type == Type::Superscript) {
57  x = 0;
58  y = m_indiceLayout->size().height() - k_indiceHeight;
59  }
60  if (child == m_indiceLayout) {
61  x = m_baseLayout->size().width();
62  y = m_type == Type::Superscript ? 0 : m_baseLayout->size().height() - k_indiceHeight;
63  }
64  return KDPoint(x,y);
65 }
66 
67 }
68 
KDPoint positionOfChild(ExpressionLayout *child) override
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
unsigned short uint16_t
Definition: stdint.h:5
Definition: point.h:6
Definition: size.h:6
BaselineRelativeLayout(ExpressionLayout *baseLayout, ExpressionLayout *indiceLayout, Type type)
ExpressionLayout * child(uint16_t index) override
Definition: color.h:6
void render(KDContext *ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override
void setParent(ExpressionLayout *parent)
constexpr KDCoordinate height() const
Definition: size.h:11