Numworks Epsilon  1.4.1
Graphing Calculator Operating System
console_edit_cell.cpp
Go to the documentation of this file.
1 #include "console_edit_cell.h"
2 #include "console_controller.h"
3 #include <escher/app.h>
4 #include <apps/i18n.h>
5 #include <assert.h>
6 
7 namespace Code {
8 
10  HighlightCell(),
11  Responder(parentResponder),
12  m_textBuffer{0},
13  m_promptView(ConsoleController::k_fontSize, nullptr, 0, 0.5),
14  m_textField(this, m_textBuffer, m_textBuffer, TextField::maxBufferSize(), delegate, false, ConsoleController::k_fontSize)
15 {
16 }
17 
19  return 2;
20 }
21 
23  assert(index == 0 || index ==1);
24  if (index == 0) {
25  return &m_promptView;
26  } else {
27  return &m_textField;
28  }
29 }
30 
32  KDSize promptSize = m_promptView.minimalSizeForOptimalDisplay();
33  m_promptView.setFrame(KDRect(KDPointZero, promptSize.width(), bounds().height()));
34  m_textField.setFrame(KDRect(KDPoint(promptSize.width(), KDCoordinate(0)), bounds().width() - promptSize.width(), bounds().height()));
35 }
36 
38  app()->setFirstResponder(&m_textField);
39 }
40 
41 void ConsoleEditCell::setEditing(bool isEditing, bool reinitDraftBuffer) {
42  m_textField.setEditing(isEditing, reinitDraftBuffer);
43 }
44 
45 void ConsoleEditCell::setText(const char * text) {
46  m_textField.setText(text);
47 }
48 
49 void ConsoleEditCell::setPrompt(const char * prompt) {
50  m_promptView.setText(prompt);
52 }
53 
54 bool ConsoleEditCell::insertText(const char * text) {
55  return m_textField.handleEventWithText(text);
56 }
57 
58 }
void setText(const char *text)
void setText(const char *text) override
int numberOfSubviews() const override
void didBecomeFirstResponder() override
bool insertText(const char *text)
#define assert(e)
Definition: assert.h:9
static constexpr int maxBufferSize()
Definition: text_field.h:23
void setText(const char *text)
Definition: text_field.cpp:184
void setFrame(KDRect frame)
Definition: view.cpp:125
void setPrompt(const char *prompt)
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
View * subviewAtIndex(int index) override
constexpr KDPoint KDPointZero
Definition: point.h:25
virtual void setEditing(bool isEditing, bool reinitDraftBuffer=true)
Definition: text_field.cpp:196
Definition: point.h:6
Definition: size.h:6
void layoutSubviews() override
Definition: app.cpp:7
KDSize minimalSizeForOptimalDisplay() const override
Definition: rect.h:26
bool handleEventWithText(const char *text, bool indenting=false) override
Definition: text_field.cpp:303
static constexpr KDText::FontSize k_fontSize
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
void setEditing(bool isEditing, bool reinitDraftBuffer=false)
KDCoordinate width() const
Definition: rect.h:39
App * app()
Definition: responder.cpp:77
ConsoleEditCell(Responder *parentResponder=nullptr, TextFieldDelegate *delegate=nullptr)
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
const char * text() const