Numworks Epsilon  1.4.1
Graphing Calculator Operating System
calculation_cell.cpp
Go to the documentation of this file.
1 #include "calculation_cell.h"
2 #include "responder_image_cell.h"
3 #include "../i18n.h"
4 #include <assert.h>
5 
6 namespace Probability {
7 
8 CalculationCell::CalculationCell(Responder * parentResponder, char * draftTextBuffer, TextFieldDelegate * textFieldDelegate) :
9  m_text(KDText::FontSize::Large, I18n::Message::Default, 0.5f, 0.5f),
10  m_calculation(parentResponder, textFieldDelegate, draftTextBuffer),
11  m_isResponder(true)
12 {
13 }
14 
16  if (m_isResponder) {
17  return &m_calculation;
18  }
19  return nullptr;
20 }
21 
22 void CalculationCell::setResponder(bool shouldBeResponder) {
23  m_isResponder = shouldBeResponder;
24 }
25 
26 void CalculationCell::setHighlighted(bool highlight) {
28  m_calculation.setHighlighted(highlight);
29 }
30 
32  KDSize textSize = m_text.minimalSizeForOptimalDisplay();
33  return KDSize(2*k_margin+textSize.width()+calculationCellWidth()+2*ResponderImageCell::k_outline, KDText::charSize().height());
34 }
35 
36 void CalculationCell::drawRect(KDContext * ctx, KDRect rect) const {
37  ctx->fillRect(bounds(), KDColorWhite);
38  if (m_isResponder) {
39  KDSize textSize = m_text.minimalSizeForOptimalDisplay();
41  }
42 }
43 
45  return &m_calculation;
46 }
47 
49  return &m_text;
50 }
51 
52 int CalculationCell::numberOfSubviews() const {
53  return 2;
54 }
55 
56 View * CalculationCell::subviewAtIndex(int index) {
57  assert(index >= 0 && index < 2);
58  if (index == 0) {
59  return &m_text;
60  }
61  return &m_calculation;
62 }
63 
64 void CalculationCell::layoutSubviews() {
65  KDSize textSize = m_text.minimalSizeForOptimalDisplay();
66  m_text.setFrame(KDRect(k_margin, 0, textSize.width(), bounds().height()));
67  m_calculation.setFrame(KDRect(2*k_margin+textSize.width()+ResponderImageCell::k_outline, ResponderImageCell::k_outline, calculationCellWidth(), ImageCell::k_height));
68 }
69 
70 KDCoordinate CalculationCell::calculationCellWidth() const {
71  KDCoordinate calculationCellWidth = m_calculation.minimalSizeForOptimalDisplay().width();
72  return min(k_maxTextFieldWidth, max(k_minTextFieldWidth, calculationCellWidth));
73 }
74 
75 }
Responder * responder() override
void strokeRect(KDRect rect, KDColor color)
CalculationCell(Responder *parentResponder=nullptr, char *draftTextBuffer=nullptr, TextFieldDelegate *textFieldDelegate=nullptr)
Definition: i18n.h:6
EditableTextCell * editableTextCell()
#define assert(e)
Definition: assert.h:9
void setFrame(KDRect frame)
Definition: view.cpp:125
static constexpr KDCoordinate k_height
Definition: image_cell.h:14
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
KDSize minimalSizeForOptimalDisplay() const override
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: text.h:8
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
KDSize minimalSizeForOptimalDisplay() const override
static constexpr KDColor GreyMiddle
Definition: palette.h:14
void setResponder(bool shouldbeResponder)
MessageTextView * messageTextView()
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
void setHighlighted(bool highlight) override
Definition: view.h:23
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
void setHighlighted(bool highlight) override
virtual void setHighlighted(bool highlight)
KDSize minimalSizeForOptimalDisplay() const override
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
#define true
Definition: stdbool.h:8
static constexpr KDCoordinate k_outline
constexpr KDCoordinate height() const
Definition: size.h:11