Numworks Epsilon  1.4.1
Graphing Calculator Operating System
editable_text_cell.cpp
Go to the documentation of this file.
2 #include <escher/app.h>
3 #include <escher/palette.h>
4 #include <assert.h>
5 
6 EditableTextCell::EditableTextCell(Responder * parentResponder, TextFieldDelegate * delegate, char * draftTextBuffer,
7  KDText::FontSize size, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) :
9  Responder(parentResponder),
10  m_textField(this, m_textBody, draftTextBuffer, TextField::maxBufferSize(), delegate, true, size, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
11  m_topMargin(topMargin),
12  m_rightMargin(rightMargin),
13  m_bottomMargin(bottomMargin),
14  m_leftMargin(leftMargin)
15 {
16  m_textBody[0] = 0;
17 }
18 
19 void EditableTextCell::setMargins(KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) {
20  m_topMargin = topMargin;
21  m_rightMargin = rightMargin;
22  m_bottomMargin = bottomMargin;
23  m_leftMargin = leftMargin;
24 }
25 
27  return &m_textField;
28 }
29 
30 void EditableTextCell::setHighlighted(bool highlight) {
32  KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
33  m_textField.setBackgroundColor(backgroundColor);
34 }
35 
37  return 1;
38 }
39 
41  assert(index == 0);
42  return &m_textField;
43 }
44 
46  KDRect cellBounds = bounds();
47  m_textField.setFrame(KDRect(cellBounds.x() + m_leftMargin,
48  cellBounds.y() + m_topMargin,
49  cellBounds.width() - m_leftMargin - m_rightMargin,
50  cellBounds.height() - m_topMargin - m_bottomMargin));
51 }
52 
54  app()->setFirstResponder(&m_textField);
55 }
56 
58  return m_textField.minimalSizeForOptimalDisplay();
59 }
#define assert(e)
Definition: assert.h:9
int numberOfSubviews() const override
KDCoordinate x() const
Definition: rect.h:36
void setMargins(KDCoordinate topMargin=0, KDCoordinate rightMargin=0, KDCoordinate bottomMargin=0, KDCoordinate leftMargin=0)
void setFrame(KDRect frame)
Definition: view.cpp:125
int16_t KDCoordinate
Definition: coordinate.h:6
TextField * textField()
void setBackgroundColor(KDColor backgroundColor)
Definition: text_input.cpp:72
View * subviewAtIndex(int index) override
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor Select
Definition: palette.h:17
void didBecomeFirstResponder() override
KDSize minimalSizeForOptimalDisplay() const override
Definition: text_field.cpp:273
KDCoordinate y() const
Definition: rect.h:37
EditableTextCell(Responder *parentResponder=nullptr, TextFieldDelegate *delegate=nullptr, char *draftTextBuffer=nullptr, KDText::FontSize size=KDText::FontSize::Large, float horizontalAlignment=0.0f, float verticalAlignment=0.5f, KDColor textColor=KDColorBlack, KDColor=KDColorWhite, KDCoordinate topMargin=0, KDCoordinate rightMargin=0, KDCoordinate bottomMargin=0, KDCoordinate leftMargin=0)
Definition: rect.h:26
void layoutSubviews() override
Definition: color.h:6
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
KDCoordinate width() const
Definition: rect.h:39
void setHighlighted(bool highlight) override
App * app()
Definition: responder.cpp:77
virtual void setHighlighted(bool highlight)
KDSize minimalSizeForOptimalDisplay() const override
FontSize
Definition: text.h:10
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
#define true
Definition: stdbool.h:8