Numworks Epsilon  1.4.1
Graphing Calculator Operating System
output_expressions_view.cpp
Go to the documentation of this file.
3 #include "../i18n.h"
4 #include <assert.h>
5 using namespace Poincare;
6 
7 namespace Calculation {
8 
9 OutputExpressionsView::OutputExpressionsView(Responder * parentResponder) :
10  Responder(parentResponder),
11  m_approximateExpressionView(),
12  m_approximateSign(KDText::FontSize::Large, I18n::Message::AlmostEqual, 0.5f, 0.5f, Palette::GreyVeryDark),
13  m_exactExpressionView(),
14  m_selectedSubviewType(OutputExpressionsView::SubviewType::ExactOutput)
15 {
16 }
17 
19  m_approximateExpressionView.setExpression(expressionsLayout[0]);
20  m_exactExpressionView.setExpression(expressionsLayout[1]);
21  layoutSubviews();
22 }
23 
24 void OutputExpressionsView::setEqualMessage(I18n::Message equalSignMessage) {
25  m_approximateSign.setMessage(equalSignMessage);
26 }
27 
29  // Do not call HighlightCell::setHighlighted to avoid marking all cell as dirty
30  m_highlighted = highlight;
31  m_exactExpressionView.setBackgroundColor(backgroundColor());
32  m_approximateExpressionView.setBackgroundColor(backgroundColor());
33  if (highlight) {
34  if (m_selectedSubviewType == SubviewType::ExactOutput) {
35  m_exactExpressionView.setBackgroundColor(Palette::Select);
36  } else {
37  m_approximateExpressionView.setBackgroundColor(Palette::Select);
38  }
39  }
40 }
41 
44  return background;
45 }
46 
49  m_approximateSign.setBackgroundColor(backgroundColor());
50  if (numberOfSubviews() == 1) {
51  m_approximateExpressionView.setTextColor(KDColorBlack);
52  } else {
53  m_approximateExpressionView.setTextColor(Palette::GreyVeryDark);
54  }
55  layoutSubviews();
56 }
57 
59  KDSize approximateExpressionSize = m_approximateExpressionView.minimalSizeForOptimalDisplay();
60  if (numberOfSubviews() == 1) {
61  return approximateExpressionSize;
62  }
63  KDSize exactExpressionSize = m_exactExpressionView.minimalSizeForOptimalDisplay();
64  KDCoordinate exactBaseline = m_exactExpressionView.expressionLayout()->baseline();
65  KDCoordinate approximateBaseline = m_approximateExpressionView.expressionLayout()->baseline();
66  KDCoordinate height = max(exactBaseline, approximateBaseline) + max(exactExpressionSize.height()-exactBaseline, approximateExpressionSize.height()-approximateBaseline);
67  KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay();
68  return KDSize(exactExpressionSize.width()+approximateSignSize.width()+approximateExpressionSize.width()+2*k_digitHorizontalMargin, height);
69 }
70 
72  if (numberOfSubviews() == 1) {
74  } else {
76  }
77 }
78 
80  if (numberOfSubviews() == 1) {
81  return false;
82  }
84  KDCoordinate offset = scrollResponder->manualScrollingOffset().x();
85  bool rightExpressionIsVisible = minimalSizeForOptimalDisplay().width() - m_approximateExpressionView.minimalSizeForOptimalDisplay().width() - offset < scrollResponder->bounds().width()
86 ;
87  bool leftExpressionIsVisible = m_exactExpressionView.minimalSizeForOptimalDisplay().width() - offset < scrollResponder->bounds().width();
88  if ((event == Ion::Events::Right && m_selectedSubviewType == SubviewType::ExactOutput && rightExpressionIsVisible) ||
89  (event == Ion::Events::Left && m_selectedSubviewType == SubviewType::ApproximativeOutput && leftExpressionIsVisible)) {
91  setSelectedSubviewType(otherSubviewType);
92  return true;
93  }
94  return false;
95 }
96 
98  return m_selectedSubviewType;
99 }
100 
102  m_selectedSubviewType = subviewType;
104 }
105 
106 int OutputExpressionsView::numberOfSubviews() const {
107  if (m_exactExpressionView.expressionLayout() != nullptr) {
108  return 3;
109  }
110  return 1;
111 }
112 
113 View * OutputExpressionsView::subviewAtIndex(int index) {
114  View * views[3] = {&m_approximateExpressionView, &m_approximateSign, &m_exactExpressionView};
115  return views[index];
116 }
117 
118 void OutputExpressionsView::layoutSubviews() {
119  KDCoordinate height = bounds().height();
120  KDSize approximateExpressionSize = m_approximateExpressionView.minimalSizeForOptimalDisplay();
121  if (numberOfSubviews() == 1) {
122  m_approximateExpressionView.setFrame(KDRect(0, 0, approximateExpressionSize.width(), height));
123  return;
124  }
125  KDCoordinate exactBaseline = m_exactExpressionView.expressionLayout()->baseline();
126  KDCoordinate approximateBaseline = m_approximateExpressionView.expressionLayout()->baseline();
127  KDCoordinate baseline = max(exactBaseline, approximateBaseline);
128  KDSize exactExpressionSize = m_exactExpressionView.minimalSizeForOptimalDisplay();
129  KDSize approximateSignSize = m_approximateSign.minimalSizeForOptimalDisplay();
130  m_exactExpressionView.setFrame(KDRect(0, baseline-exactBaseline, exactExpressionSize));
131  m_approximateExpressionView.setFrame(KDRect(2*k_digitHorizontalMargin+exactExpressionSize.width()+approximateSignSize.width(), baseline-approximateBaseline, approximateExpressionSize));
132  m_approximateSign.setFrame(KDRect(k_digitHorizontalMargin+exactExpressionSize.width(), baseline-approximateSignSize.height()/2, approximateSignSize));
133 }
134 
135 }
void setHighlighted(bool highlight) override
void setBackgroundColor(KDColor backgroundColor)
Definition: i18n.h:6
KDSize minimalSizeForOptimalDisplay() const override
void setFrame(KDRect frame)
Definition: view.cpp:125
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
void setExpression(Poincare::ExpressionLayout *expressionLayout)
void setSelectedSubviewType(SubviewType subviewType)
Responder * parentResponder() const
Definition: responder.cpp:12
KDSize minimalSizeForOptimalDisplay() const override
Definition: text.h:8
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor Select
Definition: palette.h:17
void setMessage(I18n::Message message)
Poincare::ExpressionLayout * expressionLayout() const
void setEqualMessage(I18n::Message equalSignMessage)
KDSize minimalSizeForOptimalDisplay() const override
constexpr KDColor KDColorBlack
Definition: color.h:41
void setTextColor(KDColor textColor)
bool isHighlighted() const
constexpr Event Left
Definition: events.h:61
bool handleEvent(Ion::Events::Event event) override
static constexpr KDColor WallScreen
Definition: palette.h:19
Definition: rect.h:26
Definition: color.h:6
static constexpr KDColor GreyVeryDark
Definition: palette.h:16
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
KDCoordinate width() const
Definition: rect.h:39
KDCoordinate x() const
Definition: point.h:10
void setExpressions(Poincare::ExpressionLayout **expressionsLayout)
void setBackgroundColor(KDColor backgroundColor)
Definition: text_view.cpp:14
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
constexpr KDCoordinate height() const
Definition: size.h:11
Definition: palette.h:6