Numworks Epsilon  1.4.1
Graphing Calculator Operating System
alternate_empty_view_controller.cpp
Go to the documentation of this file.
2 #include <escher/app.h>
3 #include <escher/palette.h>
4 #include <assert.h>
5 
6 /* ContentView */
7 
8 AlternateEmptyViewController::ContentView::ContentView(ViewController * mainViewController, AlternateEmptyViewDelegate * delegate) :
9  m_message(KDText::FontSize::Small, (I18n::Message)0, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen),
10  m_mainViewController(mainViewController),
11  m_delegate(delegate)
12 {
13 }
14 
15 int AlternateEmptyViewController::ContentView::numberOfSubviews() const {
16  return 1;
17 }
18 
19 View * AlternateEmptyViewController::ContentView::subviewAtIndex(int index) {
20  assert(index == 0);
21  if (m_delegate->isEmpty()) {
22  m_message.setMessage(m_delegate->emptyMessage());
23  return &m_message;
24  }
25  return m_mainViewController->view();
26 }
27 
28 void AlternateEmptyViewController::ContentView::layoutSubviews() {
29  if (alternateEmptyViewDelegate()->isEmpty()) {
30  m_message.setFrame(bounds());
31  } else {
32  m_mainViewController->view()->setFrame(bounds());
33  }
34 }
35 
36 ViewController * AlternateEmptyViewController::ContentView::mainViewController() const {
37  return m_mainViewController;
38 }
39 
40 AlternateEmptyViewDelegate * AlternateEmptyViewController::ContentView::alternateEmptyViewDelegate() const {
41  return m_delegate;
42 }
43 
44 /* AlternateEmptyViewController */
45 
47  ViewController(parentResponder),
48  m_contentView(mainViewController, delegate)
49 {
50 }
51 
53  return &m_contentView;
54 }
55 
57  return m_contentView.mainViewController()->title();
58 }
59 
61  if (m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
62  if (event != Ion::Events::Home && event != Ion::Events::OnOff) {
63  app()->setFirstResponder(m_contentView.alternateEmptyViewDelegate()->defaultController());
64  return true;
65  }
66  return false;
67  }
68  return false;
69 }
70 
72  if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
73  app()->setFirstResponder(m_contentView.mainViewController());
74  }
75 }
76 
78  m_contentView.layoutSubviews();
79  if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
80  m_contentView.mainViewController()->viewWillAppear();
81  }
82 }
83 
85  if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
86  m_contentView.mainViewController()->viewDidDisappear();
87  }
88 }
Definition: i18n.h:6
#define assert(e)
Definition: assert.h:9
constexpr Event Home
Definition: events.h:68
Definition: text.h:8
constexpr KDColor KDColorBlack
Definition: color.h:41
bool handleEvent(Ion::Events::Event event) override
AlternateEmptyViewController(Responder *parentResponder, ViewController *mainViewController, AlternateEmptyViewDelegate *delegate)
constexpr Event OnOff
Definition: events.h:69
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
App * app()
Definition: responder.cpp:77
Definition: palette.h:6