Numworks Epsilon  1.4.1
Graphing Calculator Operating System
button.cpp
Go to the documentation of this file.
1 #include <escher/button.h>
2 #include <escher/palette.h>
3 #include <assert.h>
4 
5 Button::Button(Responder * parentResponder, I18n::Message textBody, Invocation invocation, KDText::FontSize size, KDColor textColor) :
7  Responder(parentResponder),
8  m_messageTextView(size, textBody, 0.5f, 0.5f, textColor),
9  m_invocation(invocation),
10  m_size(size)
11 {
12 }
13 
14 int Button::numberOfSubviews() const {
15  return 1;
16 }
17 
18 View * Button::subviewAtIndex(int index) {
19  assert(index == 0);
20  return &m_messageTextView;
21 }
22 
23 void Button::layoutSubviews() {
25 }
26 
28  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
29  m_invocation.perform(this);
30  return true;
31  }
32  return false;
33 }
34 
35 void Button::setHighlighted(bool highlight) {
37  KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
38  m_messageTextView.setBackgroundColor(backgroundColor);
40 }
41 
44  return KDSize(textSize.width() + (m_size == KDText::FontSize::Small ? k_horizontalMarginSmall : k_horizontalMarginLarge), textSize.height() + k_verticalMargin);
45 }
void perform(void *sender)
Definition: invocation.cpp:9
#define assert(e)
Definition: assert.h:9
void setFrame(KDRect frame)
Definition: view.cpp:125
constexpr Event EXE
Definition: events.h:114
constexpr KDCoordinate width() const
Definition: size.h:10
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
KDSize minimalSizeForOptimalDisplay() const override
Definition: button.cpp:42
MessageTextView m_messageTextView
Definition: button.h:20
Definition: size.h:6
constexpr KDColor KDColorWhite
Definition: color.h:42
static constexpr KDColor Select
Definition: palette.h:17
bool handleEvent(Ion::Events::Event event) override
Definition: button.cpp:27
void setHighlighted(bool highlight) override
Definition: button.cpp:35
KDSize minimalSizeForOptimalDisplay() const override
Definition: color.h:6
Definition: view.h:23
Button(Responder *parentResponder, I18n::Message textBody, Invocation invocation, KDText::FontSize size=KDText::FontSize::Small, KDColor textColor=KDColorBlack)
Definition: button.cpp:5
constexpr Event OK
Definition: events.h:65
virtual void setHighlighted(bool highlight)
void setBackgroundColor(KDColor backgroundColor)
Definition: text_view.cpp:14
FontSize
Definition: text.h:10
KDRect bounds() const
Definition: view.cpp:157
constexpr KDCoordinate height() const
Definition: size.h:11