Blame view

Modif/epsilon-master/poincare/src/layout/condensed_sum_layout.cpp 1.71 KB
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
  #include "condensed_sum_layout.h"
  #include <poincare/expression_layout_cursor.h>
  #include <string.h>
  #include <assert.h>
  
  namespace Poincare {
  
  ExpressionLayout * CondensedSumLayout::clone() const {
    CondensedSumLayout * layout = new CondensedSumLayout(const_cast<CondensedSumLayout *>(this)->baseLayout(), const_cast<CondensedSumLayout *>(this)->subscriptLayout(), const_cast<CondensedSumLayout *>(this)->superscriptLayout(), true);
    return layout;
  }
  
  KDSize CondensedSumLayout::computeSize() {
    KDSize baseSize = baseLayout()->size();
    KDSize subscriptSize = subscriptLayout()->size();
    KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->size();
    return KDSize(baseSize.width() + max(subscriptSize.width(), superscriptSize.width()), max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height()));
  }
  
  void CondensedSumLayout::computeBaseline() {
    KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->size();
    m_baseline = baseLayout()->baseline() + max(0, superscriptSize.height() - baseLayout()->size().height()/2);
    m_baselined = true;
  }
  
  KDPoint CondensedSumLayout::positionOfChild(ExpressionLayout * child) {
    KDCoordinate x = 0;
    KDCoordinate y = 0;
    KDSize baseSize = baseLayout()->size();
    KDSize superscriptSize = superscriptLayout() == nullptr ? KDSizeZero : superscriptLayout()->size();
    if (child == baseLayout()) {
      y = max(0, superscriptSize.height() - baseSize.height()/2);
    }
    if (child == subscriptLayout()) {
      x = baseSize.width();
      y = max(baseSize.height()/2, superscriptSize.height());
    }
    if (child == superscriptLayout()) {
      x = baseSize.width();
    }
    return KDPoint(x,y);
  }
  
  }