Numworks Epsilon  1.4.1
Graphing Calculator Operating System
stack_view.cpp
Go to the documentation of this file.
1 #include <escher/stack_view.h>
2 extern "C" {
3 #include <assert.h>
4 }
5 
7  View(),
8  m_controller(nullptr)
9 {
10 }
11 
13  m_textColor = textColor;
15 }
16 
17 void StackView::setBackgroundColor(KDColor backgroundColor) {
18  m_backgroundColor = backgroundColor;
20 }
21 
22 void StackView::setSeparatorColor(KDColor separatorColor) {
23  m_separatorColor = separatorColor;
25 }
26 
28  m_controller = controller;
30 }
31 
32 void StackView::drawRect(KDContext * ctx, KDRect rect) const {
33  KDCoordinate height = bounds().height();
34  KDCoordinate width = bounds().width();
35  ctx->fillRect(KDRect(0, 0, width, 1), m_separatorColor);
36  ctx->fillRect(KDRect(0, 1, width, height-2), m_backgroundColor);
37  ctx->fillRect(KDRect(0, height-1, width, 1), m_separatorColor);
38  // Write title
39  KDSize textSize = KDText::stringSize(m_controller->title(), KDText::FontSize::Small);
40  KDPoint origin(0.5f*(m_frame.width() - textSize.width()),0.5f*(m_frame.height() - textSize.height()));
41  ctx->drawString(m_controller->title(), origin, KDText::FontSize::Small, m_textColor, m_backgroundColor);
42 }
43 
44 #if ESCHER_VIEW_LOGGING
45 const char * StackView::className() const {
46  return "StackView";
47 }
48 
49 void StackView::logAttributes(std::ostream &os) const {
50  View::logAttributes(os);
51  os << " name=\"" << m_name << "\"";
52 }
53 #endif
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 setSeparatorColor(KDColor separatorColor)
Definition: stack_view.cpp:22
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
Definition: text.cpp:6
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
Definition: point.h:6
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: stack_view.cpp:32
Definition: size.h:6
KDRect m_frame
Definition: view.h:66
void setNamedController(ViewController *controller)
Definition: stack_view.cpp:27
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
virtual const char * title()
Definition: view.h:23
void setBackgroundColor(KDColor backgroundColor)
Definition: stack_view.cpp:17
KDCoordinate width() const
Definition: rect.h:39
void setTextColor(KDColor textColor)
Definition: stack_view.cpp:12
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
constexpr KDCoordinate height() const
Definition: size.h:11