Numworks Epsilon  1.4.1
Graphing Calculator Operating System
history_view_cell.cpp
Go to the documentation of this file.
1 #include "history_view_cell.h"
2 #include "app.h"
3 #include "../constant.h"
5 #include <assert.h>
6 #include <string.h>
7 
8 namespace Calculation {
9 
11  Responder(parentResponder),
12  m_inputView(this),
13  m_scrollableOutputView(this),
14  m_selectedSubviewType(HistoryViewCell::SubviewType::Output)
15 {
16 }
17 
19  return m_scrollableOutputView.outputView();
20 
21 }
22 void HistoryViewCell::setEven(bool even) {
24  m_inputView.setBackgroundColor(backgroundColor());
25  m_scrollableOutputView.outputView()->setEven(even);
26 }
27 
28 void HistoryViewCell::setHighlighted(bool highlight) {
29  m_highlighted = highlight;
30  m_inputView.setBackgroundColor(backgroundColor());
31  m_scrollableOutputView.outputView()->setHighlighted(false);
32  if (isHighlighted()) {
33  if (m_selectedSubviewType == SubviewType::Input) {
35  } else {
36  m_scrollableOutputView.outputView()->setHighlighted(true);
37  }
38  }
39  reloadScroll();
40 }
41 
43  m_scrollableOutputView.outputView()->reloadCell();
45  reloadScroll();
46 }
47 
49  m_inputView.reloadScroll();
50  m_scrollableOutputView.reloadScroll();
51 }
52 
55  return background;
56 }
57 
58 
60  return 2;
61 }
62 
64  View * views[2] = {&m_inputView, &m_scrollableOutputView};
65  return views[index];
66 }
67 
69  KDCoordinate width = bounds().width();
70  KDCoordinate height = bounds().height();
71  KDSize inputSize = m_inputView.minimalSizeForOptimalDisplay();
72  if (inputSize.width() + Metric::HistoryHorizontalMargin > width) {
74  } else {
75  m_inputView.setFrame(KDRect(Metric::HistoryHorizontalMargin, k_digitVerticalMargin, inputSize.width(), inputSize.height()));
76  }
77  KDSize outputSize = m_scrollableOutputView.minimalSizeForOptimalDisplay();
78  if (outputSize.width() + Metric::HistoryHorizontalMargin > width) {
79  m_scrollableOutputView.setFrame(KDRect(Metric::HistoryHorizontalMargin, inputSize.height() + 2*k_digitVerticalMargin, width - Metric::HistoryHorizontalMargin, height - inputSize.height() - 3*k_digitVerticalMargin));
80  } else {
81  m_scrollableOutputView.setFrame(KDRect(width - outputSize.width() - Metric::HistoryHorizontalMargin, inputSize.height() + 2*k_digitVerticalMargin, outputSize.width(), height - inputSize.height() - 3*k_digitVerticalMargin));
82  }
83 }
84 
86  m_inputView.setExpression(calculation->inputLayout());
87  App * calculationApp = (App *)app();
88  /* Both output expressions have to be updated at the same time. The
89  * outputView points to deleted layouts and a call to
90  * outputView()->layoutSubviews() is going to fail. */
91  Poincare::ExpressionLayout * outputExpressions[2] = {calculation->approximateOutputLayout(calculationApp->localContext()), calculation->shouldDisplayApproximateOutput(calculationApp->localContext()) ? nullptr : calculation->exactOutputLayout(calculationApp->localContext())};
92  m_scrollableOutputView.outputView()->setExpressions(outputExpressions);
93  I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(calculationApp->localContext()) ? I18n::Message::Equal : I18n::Message::AlmostEqual;
94  m_scrollableOutputView.outputView()->setEqualMessage(equalMessage);
95 }
96 
98  if (m_selectedSubviewType == SubviewType::Input) {
99  app()->setFirstResponder(&m_inputView);
100  } else {
101  app()->setFirstResponder(&m_scrollableOutputView);
102  }
103 }
104 
106  return m_selectedSubviewType;
107 }
108 
110  m_selectedSubviewType = subviewType;
112 }
113 
115  if ((event == Ion::Events::Down && m_selectedSubviewType == SubviewType::Input) ||
116  (event == Ion::Events::Up && m_selectedSubviewType == SubviewType::Output)) {
117  SubviewType otherSubviewType = m_selectedSubviewType == SubviewType::Input ? SubviewType::Output : SubviewType::Input;
119  tableView->scrollToSubviewOfTypeOfCellAtLocation(otherSubviewType, tableView->selectedColumn(), tableView->selectedRow());
120  HistoryViewCell * selectedCell = (HistoryViewCell *)(tableView->selectedCell());
121  selectedCell->setSelectedSubviewType(otherSubviewType);
122  app()->setFirstResponder(selectedCell);
123  return true;
124  }
125  return false;
126 }
127 
128 }
void setHighlighted(bool highlight) override
void setCalculation(Calculation *calculation)
void setExpression(Poincare::ExpressionLayout *expressionLayout)
void reloadScroll(bool forceRelayout=false)
void scrollToSubviewOfTypeOfCellAtLocation(HistoryViewCell::SubviewType subviewType, int i, int j)
HighlightCell * selectedCell()
virtual void setEven(bool even)
void setFrame(KDRect frame)
Definition: view.cpp:125
static constexpr KDCoordinate HistoryHorizontalMargin
Definition: metric.h:12
void setBackgroundColor(KDColor backgroundColor)
int16_t KDCoordinate
Definition: coordinate.h:6
KDColor backgroundColor() const override
constexpr KDCoordinate width() const
Definition: size.h:10
void setHighlighted(bool highlight) override
Responder * parentResponder() const
Definition: responder.cpp:12
void setSelectedSubviewType(HistoryViewCell::SubviewType subviewType)
constexpr Event Up
Definition: events.h:62
constexpr Event Down
Definition: events.h:63
virtual Poincare::Context * localContext()
HistoryViewCell(Responder *parentResponder)
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDCoordinate k_digitVerticalMargin
static constexpr KDColor Select
Definition: palette.h:17
bool handleEvent(Ion::Events::Event event) override
void setEqualMessage(I18n::Message equalSignMessage)
bool isHighlighted() const
constexpr Event Equal
Definition: events.h:137
static constexpr KDColor WallScreen
Definition: palette.h:19
Definition: rect.h:26
Definition: color.h:6
View * subviewAtIndex(int index) override
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
KDCoordinate width() const
Definition: rect.h:39
OutputExpressionsView * outputView()
int numberOfSubviews() const override
App * app()
Definition: responder.cpp:77
void setExpressions(Poincare::ExpressionLayout **expressionsLayout)
void setEven(bool even) override
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
constexpr KDCoordinate height() const
Definition: size.h:11