Numworks Epsilon  1.4.1
Graphing Calculator Operating System
sequence_layout.cpp
Go to the documentation of this file.
1 #include "sequence_layout.h"
2 #include <string.h>
3 #include <assert.h>
4 
5 namespace Poincare {
6 
7 SequenceLayout::SequenceLayout(ExpressionLayout * lowerBoundLayout, ExpressionLayout * upperBoundLayout, ExpressionLayout * argumentLayout) :
9  m_lowerBoundLayout(lowerBoundLayout),
10  m_upperBoundLayout(upperBoundLayout),
11  m_argumentLayout(argumentLayout)
12 {
17 }
18 
20  delete m_lowerBoundLayout;
21  delete m_upperBoundLayout;
22  delete m_argumentLayout;
23 }
24 
25 KDSize SequenceLayout::computeSize() {
26  KDSize argumentSize = m_argumentLayout->size();
27  KDSize lowerBoundSize = m_lowerBoundLayout->size();
28  KDSize upperBoundSize = m_upperBoundLayout->size();
29  return KDSize(
30  max(max(k_symbolWidth, lowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin+argumentSize.width(),
31  m_baseline + max(k_symbolHeight/2+k_boundHeightMargin+lowerBoundSize.height(), argumentSize.height() - m_argumentLayout->baseline())
32  );
33 }
34 
35 ExpressionLayout * SequenceLayout::child(uint16_t index) {
36  switch (index) {
37  case 0:
38  return m_upperBoundLayout;
39  case 1:
40  return m_lowerBoundLayout;
41  case 2:
42  return m_argumentLayout;
43  default:
44  return nullptr;
45  }
46 }
47 
48 KDPoint SequenceLayout::positionOfChild(ExpressionLayout * child) {
49  KDSize lowerBoundSize = m_lowerBoundLayout->size();
50  KDSize upperBoundSize = m_upperBoundLayout->size();
51  KDCoordinate x = 0;
52  KDCoordinate y = 0;
53  if (child == m_lowerBoundLayout) {
54  x = max(max(0, (k_symbolWidth-lowerBoundSize.width())/2), (upperBoundSize.width()-lowerBoundSize.width())/2);
56  } else if (child == m_upperBoundLayout) {
57  x = max(max(0, (k_symbolWidth-upperBoundSize.width())/2), (lowerBoundSize.width()-upperBoundSize.width())/2);
58  y = m_baseline - (k_symbolHeight+1)/2- k_boundHeightMargin-upperBoundSize.height();
59  } else if (child == m_argumentLayout) {
60  x = max(max(k_symbolWidth, lowerBoundSize.width()), upperBoundSize.width())+k_argumentWidthMargin;
62  } else {
63  assert(false);
64  }
65  return KDPoint(x,y);
66 }
67 
68 }
static constexpr KDCoordinate k_symbolWidth
#define assert(e)
Definition: assert.h:9
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
static constexpr KDCoordinate k_boundHeightMargin
unsigned short uint16_t
Definition: stdint.h:5
SequenceLayout(ExpressionLayout *lowerBoundLayout, ExpressionLayout *upperBoundLayout, ExpressionLayout *argumentLayout)
Definition: point.h:6
Definition: size.h:6
ExpressionLayout * m_lowerBoundLayout
ExpressionLayout * m_upperBoundLayout
static constexpr KDCoordinate k_symbolHeight
void setParent(ExpressionLayout *parent)
constexpr KDCoordinate height() const
Definition: size.h:11
ExpressionLayout * m_argumentLayout