Numworks Epsilon  1.4.1
Graphing Calculator Operating System
tab_view_cell.cpp
Go to the documentation of this file.
1 #include <escher/tab_view_cell.h>
2 #include <escher/palette.h>
3 extern "C" {
4 #include <assert.h>
5 }
6 
8  View(),
9  m_active(false),
10  m_selected(false),
11  m_controller(nullptr)
12 {
13 }
14 
16  m_controller = controller;
18 }
19 
20 void TabViewCell::setActive(bool active) {
21  m_active = active;
23 }
24 
25 void TabViewCell::setSelected(bool selected) {
26  m_selected = selected;
28 }
29 
31  return KDText::stringSize(m_controller->title(), KDText::FontSize::Small);
32 }
33 
34 void TabViewCell::drawRect(KDContext * ctx, KDRect rect) const {
35  KDCoordinate height = bounds().height();
36  KDCoordinate width = bounds().width();
37  // choose the background color
38  KDColor text = m_active ? Palette::PurpleBright : KDColorWhite;
39  KDColor background = m_active ? KDColorWhite : Palette::PurpleBright;
40  KDColor selection = m_active ? Palette::Select : Palette::SelectDark;
41  background = m_selected ? selection : background;
42  // Color the background according to the state of the tab cell
43  if (m_active || m_selected) {
44  ctx->fillRect(KDRect(0, 0, width, 1), Palette::PurpleBright);
45  ctx->fillRect(KDRect(0, 1, width, height-1), background);
46  } else {
47  ctx->fillRect(KDRect(0, 0, width, height), background);
48  }
49  // Write title
50  KDSize textSize = KDText::stringSize(m_controller->title(), KDText::FontSize::Small);
51  KDPoint origin(0.5f*(m_frame.width() - textSize.width()),0.5f*(m_frame.height() - textSize.height()));
52  ctx->drawString(m_controller->title(), origin, KDText::FontSize::Small, text, background);
53 }
54 
55 #if ESCHER_VIEW_LOGGING
56 const char * TabViewCell::className() const {
57  return "TabViewCell";
58 }
59 
60 void TabViewCell::logAttributes(std::ostream &os) const {
61  View::logAttributes(os);
62  os << " active=\"" << m_active << "\"";
63  os << " name=\"" << m_controller->title() << "\"";
64 }
65 #endif
static constexpr KDColor SelectDark
Definition: palette.h:18
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
static constexpr KDColor PurpleBright
Definition: palette.h:10
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
Definition: size.h:6
void setSelected(bool selected)
KDRect m_frame
Definition: view.h:66
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor Select
Definition: palette.h:17
KDSize minimalSizeForOptimalDisplay() const override
#define false
Definition: stdbool.h:9
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
KDCoordinate width() const
Definition: rect.h:39
void setNamedController(ViewController *controller)
void drawRect(KDContext *ctx, KDRect rect) const override
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
void setActive(bool active)
constexpr KDCoordinate height() const
Definition: size.h:11