Numworks Epsilon  1.4.1
Graphing Calculator Operating System
cell.cpp
Go to the documentation of this file.
1 #include "cell.h"
2 #include <assert.h>
3 
4 namespace Probability {
5 
8  m_labelView(KDText::FontSize::Large, (I18n::Message)0, 0, 0.5, KDColorBlack, KDColorWhite),
9  m_icon(nullptr),
10  m_focusedIcon(nullptr)
11 {
12 }
13 
14 int Cell::numberOfSubviews() const {
15  return 3;
16 }
17 
18 View * Cell::subviewAtIndex(int index) {
19  assert(index >= 0 && index < 3);
20  if (index == 0) {
21  return &m_labelView;
22  }
23  if (index == 1) {
24  return &m_iconView;
25  }
26  return &m_chevronView;
27 }
28 
29 void Cell::layoutSubviews() {
30  KDCoordinate width = bounds().width();
31  KDCoordinate height = bounds().height();
32  m_labelView.setFrame(KDRect(1+k_iconWidth+2*k_iconMargin, 1, width-2-k_iconWidth-2*k_iconMargin - k_chevronWidth, height-2));
33  m_iconView.setFrame(KDRect(1+k_iconMargin, (height - k_iconHeight)/2, k_iconWidth, k_iconHeight));
34  m_chevronView.setFrame(KDRect(width-1-k_chevronWidth-k_chevronMargin, 1, k_chevronWidth, height - 2));
35 }
36 
39  KDColor backgroundColor = isHighlighted()? Palette::Select : KDColorWhite;
40  m_labelView.setBackgroundColor(backgroundColor);
41  if (isHighlighted()) {
42  m_iconView.setImage(m_focusedIcon);
43  } else {
44  m_iconView.setImage(m_icon);
45  }
46 }
47 
48 void Cell::setLabel(I18n::Message message) {
49  m_labelView.setMessage(message);
50 }
51 
52 void Cell::setImage(const Image * image, const Image * focusedImage) {
53  m_icon = image;
54  m_focusedIcon = focusedImage;
55 }
56 
57 void Cell::drawRect(KDContext * ctx, KDRect rect) const {
58  KDCoordinate width = bounds().width();
59  KDCoordinate height = bounds().height();
60  KDColor backgroundColor = isHighlighted() ? Palette::Select : KDColorWhite;
61  ctx->fillRect(KDRect(1, 1, width-2, height-1), backgroundColor);
62  ctx->fillRect(KDRect(0, 0, width, 1), Palette::GreyBright);
63  ctx->fillRect(KDRect(0, 1, 1, height-1), Palette::GreyBright);
64  ctx->fillRect(KDRect(width-1, 1, 1, height-1), Palette::GreyBright);
65  ctx->fillRect(KDRect(0, height-1, width, 1), Palette::GreyBright);
66  }
67 
68 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
void setFrame(KDRect frame)
Definition: view.cpp:125
int16_t KDCoordinate
Definition: coordinate.h:6
Definition: image.h:6
Definition: text.h:8
void reloadCell() override
Definition: cell.cpp:37
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor Select
Definition: palette.h:17
void setMessage(I18n::Message message)
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: cell.cpp:57
void setImage(const Image *image, const Image *focusedImage)
Definition: cell.cpp:52
constexpr KDColor KDColorBlack
Definition: color.h:41
bool isHighlighted() const
void setLabel(I18n::Message message)
Definition: cell.cpp:48
void setImage(const Image *image)
Definition: image_view.cpp:21
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
Definition: view.h:23
KDCoordinate width() const
Definition: rect.h:39
virtual void reloadCell()
void setBackgroundColor(KDColor backgroundColor)
Definition: text_view.cpp:14
static constexpr KDColor GreyBright
Definition: palette.h:13
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157