Numworks Epsilon  1.4.1
Graphing Calculator Operating System
condensed_sum_layout.cpp
Go to the documentation of this file.
1 #include "condensed_sum_layout.h"
2 #include <string.h>
3 #include <assert.h>
4 
5 namespace Poincare {
6 
7 CondensedSumLayout::CondensedSumLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout) :
9  m_baseLayout(baseLayout),
10  m_subscriptLayout(subscriptLayout),
11  m_superscriptLayout(superscriptLayout)
12 {
13  m_baseLayout->setParent(this);
14  m_subscriptLayout->setParent(this);
15  if (m_superscriptLayout) {
16  m_superscriptLayout->setParent(this);
17  }
18  KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
19  m_baseline = m_baseLayout->baseline() + max(0, superscriptSize.height() - m_baseLayout->size().height()/2);
20 }
21 
23  delete m_baseLayout;
24  delete m_subscriptLayout;
25  if (m_superscriptLayout) {
26  delete m_superscriptLayout;
27  }
28 }
29 
30 void CondensedSumLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
31  // Nothing to draw
32 }
33 
35  KDSize baseSize = m_baseLayout->size();
36  KDSize subscriptSize = m_subscriptLayout->size();
37  KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
38  return KDSize(baseSize.width() + max(subscriptSize.width(), superscriptSize.width()), max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height()));
39 }
40 
42  switch (index) {
43  case 0:
44  return m_baseLayout;
45  case 1:
46  return m_subscriptLayout;
47  case 2:
48  return m_superscriptLayout;
49  default:
50  return nullptr;
51  }
52 }
53 
55  KDCoordinate x = 0;
56  KDCoordinate y = 0;
57  KDSize baseSize = m_baseLayout->size();
58  KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
59  if (child == m_baseLayout) {
60  y = max(0, superscriptSize.height() - baseSize.height()/2);
61  }
62  if (child == m_subscriptLayout) {
63  x = baseSize.width();
64  y = max(baseSize.height()/2, superscriptSize.height());
65  }
66  if (child == m_superscriptLayout) {
67  x = baseSize.width();
68  }
69  return KDPoint(x,y);
70 }
71 
72 }
73 
void render(KDContext *ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override
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
CondensedSumLayout(ExpressionLayout *baseLayout, ExpressionLayout *subscriptLayout, ExpressionLayout *superscriptLayout=nullptr)
Definition: color.h:6
constexpr KDSize KDSizeZero
Definition: size.h:17
ExpressionLayout * child(uint16_t index) override
void setParent(ExpressionLayout *parent)
constexpr KDCoordinate height() const
Definition: size.h:11