Blame view

build6/epsilon-master/escher/src/dynamic_view_controller.cpp 803 Bytes
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  #include <escher/dynamic_view_controller.h>
  #include <escher/app.h>
  #include <assert.h>
  
  DynamicViewController::DynamicViewController(Responder * parentResponder) :
    ViewController(parentResponder),
    m_view(nullptr)
  {
  }
  
  DynamicViewController::~DynamicViewController() {
    assert(m_view == nullptr);
  }
  
  View * DynamicViewController::view() {
    loadViewIfNeeded();
    return m_view;
  }
  
  void DynamicViewController::viewWillAppear() {
    loadViewIfNeeded();
  }
  
  void DynamicViewController::viewDidDisappear() {
    unloadViewIfNeeded();
  }
  
  void DynamicViewController::loadViewIfNeeded() {
    if (m_view == nullptr) {
      m_view = loadView();
      assert(m_view != nullptr);
    }
  }
  
  void DynamicViewController::unloadViewIfNeeded() {
    if (m_view != nullptr) {
      unloadView(m_view);
      m_view = nullptr;
    }
  }