mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] Add a BankViewController
This commit is contained in:
@@ -3,6 +3,7 @@ SFLAGS += -Iescher/include
|
||||
objs += $(addprefix escher/src/,\
|
||||
alternate_empty_view_controller.o\
|
||||
app.o\
|
||||
bank_view_controller.o\
|
||||
buffer_text_view.o\
|
||||
button.o\
|
||||
button_row_controller.o\
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <escher/alternate_empty_view_controller.h>
|
||||
#include <escher/alternate_empty_view_delegate.h>
|
||||
#include <escher/app.h>
|
||||
#include <escher/bank_view_controller.h>
|
||||
#include <escher/buffer_text_view.h>
|
||||
#include <escher/button.h>
|
||||
#include <escher/button_row_controller.h>
|
||||
|
||||
46
escher/include/escher/bank_view_controller.h
Normal file
46
escher/include/escher/bank_view_controller.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef ESCHER_BANK_VIEW_CONTROLLER_H
|
||||
#define ESCHER_BANK_VIEW_CONTROLLER_H
|
||||
|
||||
#include <escher/view_controller.h>
|
||||
|
||||
class BankViewController : public ViewController {
|
||||
public:
|
||||
BankViewController(Responder * parentViewController);
|
||||
|
||||
virtual ViewController * childAtIndex(int i) = 0;
|
||||
virtual int numberOfChildren() = 0;
|
||||
|
||||
void setActiveIndex(int i);
|
||||
int activeIndex() const { return m_activeIndex; }
|
||||
|
||||
View * view() override { return &m_view; }
|
||||
void didEnterResponderChain(Responder * previousResponder) override;
|
||||
void viewWillAppear() override;
|
||||
void viewDidDisappear() override;
|
||||
private:
|
||||
class ContentView : public View {
|
||||
public:
|
||||
ContentView(): View(), m_subview(nullptr) {}
|
||||
void setSubview(View * view);
|
||||
private:
|
||||
int numberOfSubviews() const override {
|
||||
return m_subview == nullptr ? 0 : 1;
|
||||
}
|
||||
View * subviewAtIndex(int index) override {
|
||||
assert(index == 0);
|
||||
return m_subview;
|
||||
}
|
||||
void layoutSubviews() override {
|
||||
m_subview->setFrame(bounds());
|
||||
}
|
||||
View * m_subview;
|
||||
};
|
||||
ViewController * activeViewController() {
|
||||
assert(m_activeIndex >= 0 && m_activeIndex < numberOfChildren());
|
||||
return childAtIndex(m_activeIndex);
|
||||
}
|
||||
ContentView m_view;
|
||||
int m_activeIndex;
|
||||
};
|
||||
|
||||
#endif
|
||||
40
escher/src/bank_view_controller.cpp
Normal file
40
escher/src/bank_view_controller.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <escher/bank_view_controller.h>
|
||||
#include <escher/app.h>
|
||||
|
||||
BankViewController::BankViewController(Responder * parentViewController) :
|
||||
ViewController(parentViewController),
|
||||
m_activeIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
void BankViewController::setActiveIndex(int i) {
|
||||
assert(i >= 0 && i < numberOfChildren());
|
||||
if (i == m_activeIndex) {
|
||||
return;
|
||||
}
|
||||
ViewController * upcomingVC = childAtIndex(i);
|
||||
upcomingVC->viewWillAppear();
|
||||
app()->setFirstResponder(upcomingVC);
|
||||
childAtIndex(m_activeIndex)->viewDidDisappear();
|
||||
m_activeIndex = i;
|
||||
m_view.setSubview(upcomingVC->view());
|
||||
}
|
||||
|
||||
void BankViewController::didEnterResponderChain(Responder * previousResponder) {
|
||||
app()->setFirstResponder(activeViewController());
|
||||
}
|
||||
|
||||
void BankViewController::viewWillAppear() {
|
||||
m_view.setSubview(activeViewController()->view());
|
||||
activeViewController()->viewWillAppear();
|
||||
}
|
||||
|
||||
void BankViewController::viewDidDisappear() {
|
||||
activeViewController()->viewDidDisappear();
|
||||
}
|
||||
|
||||
void BankViewController::ContentView::setSubview(View * view) {
|
||||
m_subview = view;
|
||||
layoutSubviews();
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
Reference in New Issue
Block a user