Numworks Epsilon  1.4.1
Graphing Calculator Operating System
console_line_cell.cpp
Go to the documentation of this file.
1 #include "console_line_cell.h"
2 #include "console_controller.h"
3 #include <kandinsky/point.h>
4 #include <kandinsky/coordinate.h>
5 #include <apps/i18n.h>
6 
7 namespace Code {
8 
10  HighlightCell(),
11  m_line(nullptr)
12 {
13 }
14 
16  m_line = line;
17 }
18 
20  ctx->fillRect(bounds(), KDColorWhite);
21  ctx->drawString(m_line->text(), KDPointZero, ConsoleController::k_fontSize, textColor(m_line), isHighlighted()? Palette::Select : KDColorWhite);
22 }
23 
25  return KDText::stringSize(m_line->text(), ConsoleController::k_fontSize);
26 }
27 
28 ConsoleLineCell::ScrollableConsoleLineView::ScrollableConsoleLineView(Responder * parentResponder) :
29  ScrollableView(parentResponder, &m_consoleLineView, this),
30  m_consoleLineView()
31 {
32 }
33 
34 KDSize ConsoleLineCell::ScrollableConsoleLineView::minimalSizeForOptimalDisplay() const {
35  return m_consoleLineView.minimalSizeForOptimalDisplay();
36 }
37 
39  HighlightCell(),
41  m_promptView(ConsoleController::k_fontSize, I18n::Message::ConsolePrompt, 0, 0.5),
42  m_scrollableView(this),
43  m_line()
44 {
45 }
46 
48  m_line = line;
49  m_scrollableView.consoleLineView()->setLine(&m_line);
50  m_promptView.setTextColor(textColor(&m_line));
51  reloadCell();
52 }
53 
54 void ConsoleLineCell::setHighlighted(bool highlight) {
56  m_scrollableView.consoleLineView()->setHighlighted(highlight);
57 }
58 
62  m_scrollableView.reloadScroll();
63 }
64 
66  if (m_line.isCommand()) {
67  return 2;
68  }
69  assert(m_line.isResult());
70  return 1;
71 }
72 
74  if (m_line.isCommand()) {
75  assert(index >= 0 && index < 2);
76  View * views[] = {&m_promptView, &m_scrollableView};
77  return views[index];
78  }
79  assert(m_line.isResult());
80  assert(index == 0);
81  return &m_scrollableView;
82 }
83 
85  if (m_line.isCommand()) {
86  KDSize promptSize = KDText::stringSize(I18n::translate(I18n::Message::ConsolePrompt), ConsoleController::k_fontSize);
87  m_promptView.setFrame(KDRect(KDPointZero, promptSize.width(), bounds().height()));
88  m_scrollableView.setFrame(KDRect(KDPoint(promptSize.width(), 0), bounds().width() - promptSize.width(), bounds().height()));
89  return;
90  }
91  assert(m_line.isResult());
92  m_promptView.setFrame(KDRectZero);
93  m_scrollableView.setFrame(bounds());
94 }
95 
97  app()->setFirstResponder(&m_scrollableView);
98 }
99 
100 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
KDPoint drawString(const char *text, KDPoint p, KDText::FontSize size=KDText::FontSize::Large, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite, int maxLength=-1)
Definition: context_text.cpp:9
void setFrame(KDRect frame)
Definition: view.cpp:125
void layoutSubviews() override
void drawRect(KDContext *ctx, KDRect rect) const override
constexpr KDCoordinate width() const
Definition: size.h:10
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
Definition: text.cpp:6
Responder * parentResponder() const
Definition: responder.cpp:12
constexpr KDPoint KDPointZero
Definition: point.h:25
void setLine(ConsoleLine line)
void didBecomeFirstResponder() override
ConsoleLineCell(Responder *parentResponder=nullptr)
void setHighlighted(bool highlight) override
Definition: point.h:6
Definition: size.h:6
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
Definition: app.cpp:7
constexpr KDColor KDColorWhite
Definition: color.h:42
int numberOfSubviews() const override
static constexpr KDColor Select
Definition: palette.h:17
bool isResult() const
Definition: console_line.h:22
bool isHighlighted() const
bool isCommand() const
Definition: console_line.h:21
constexpr KDRect KDRectZero
Definition: rect.h:70
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
View * subviewAtIndex(int index) override
static constexpr KDText::FontSize k_fontSize
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
KDCoordinate width() const
Definition: rect.h:39
void setTextColor(KDColor textColor)
Definition: text_view.cpp:19
App * app()
Definition: responder.cpp:77
virtual void setHighlighted(bool highlight)
virtual void reloadCell()
void reloadCell() override
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157