Numworks Epsilon  1.4.1
Graphing Calculator Operating System
message_table_cell_with_editable_text.cpp
Go to the documentation of this file.
2 #include <escher/palette.h>
3 #include <escher/app.h>
4 
5 MessageTableCellWithEditableText::MessageTableCellWithEditableText(Responder * parentResponder, TextFieldDelegate * textFieldDelegate, char * draftTextBuffer, I18n::Message message) :
6  Responder(parentResponder),
7  MessageTableCell(message),
8  m_textField(this, m_textBody, draftTextBuffer, TextField::maxBufferSize(), textFieldDelegate, true, KDText::FontSize::Large, 1.0f, 0.5f)
9 {
10  m_textBody[0] = '\0';
11 }
12 
14  return (View *)&m_textField;
15 }
16 
18  return m_textField.text();
19 }
20 
22  app()->setFirstResponder(&m_textField);
23 }
24 
26  return m_textField.isEditing();
27 }
28 
30  m_textField.setEditing(isEditing);
31 }
32 
35  KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
36  m_textField.setBackgroundColor(backgroundColor);
37 }
38 
40  m_textField.setText(text);
41  layoutSubviews();
42 }
43 
45  m_textField.setTextColor(color);
47 }
48 
49 void MessageTableCellWithEditableText::layoutSubviews() {
51  KDSize textFieldSize = m_textField.minimalSizeForOptimalDisplay();
53  /* Handle textfield that has no defined width (as their width evolves with
54  * the length of edited text */
55  textFieldSize = KDSize(bounds().width() - 2*k_separatorThickness - labelSize.width()-2*k_labelMargin-k_accessoryMargin, textFieldSize.height());
56  m_textField.setFrame(KDRect(bounds().width() - textFieldSize.width() - k_separatorThickness-k_accessoryMargin, (bounds().height()-textFieldSize.height()-k_accessoryMargin)/2, textFieldSize.width(), textFieldSize.height()+k_accessoryMargin));
57 }
bool isEditing() const
Definition: text_field.cpp:175
void setTextColor(KDColor textColor)
Definition: text_input.cpp:76
void setText(const char *text)
Definition: text_field.cpp:184
void setFrame(KDRect frame)
Definition: view.cpp:125
constexpr KDCoordinate width() const
Definition: size.h:10
static constexpr KDCoordinate k_separatorThickness
Definition: table_cell.h:21
View * labelView() const override
Definition: text.h:8
void setBackgroundColor(KDColor backgroundColor)
Definition: text_input.cpp:72
virtual void setEditing(bool isEditing, bool reinitDraftBuffer=true)
Definition: text_field.cpp:196
Definition: size.h:6
virtual void setTextColor(KDColor color)
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDCoordinate k_labelMargin
Definition: table_cell.h:22
static constexpr KDColor Select
Definition: palette.h:17
virtual void setHighlighted(bool highlight) override
KDSize minimalSizeForOptimalDisplay() const override
Definition: text_field.cpp:273
const char * text() const
Definition: text_input.h:14
virtual KDSize minimalSizeForOptimalDisplay() const
Definition: view.cpp:183
void layoutSubviews() override
Definition: table_cell.cpp:37
Definition: rect.h:26
Definition: color.h:6
MessageTableCellWithEditableText(Responder *parentResponder, TextFieldDelegate *textFieldDelegate, char *draftTextBuffer, I18n::Message message=(I18n::Message) 0)
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
App * app()
Definition: responder.cpp:77
static constexpr KDCoordinate k_accessoryMargin
Definition: table_cell.h:23
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
#define true
Definition: stdbool.h:8
constexpr KDCoordinate height() const
Definition: size.h:11