5 ModalViewController::ContentView::ContentView() :
7 m_regularView(nullptr),
8 m_currentModalView(nullptr),
9 m_isDisplayingModal(
false),
10 m_verticalAlignment(0.0f),
11 m_horizontalAlignment(0.0f),
19 void ModalViewController::ContentView::setMainView(
View * regularView) {
20 if (m_regularView != regularView) {
21 m_regularView = regularView;
25 int ModalViewController::ContentView::numberOfSubviews()
const {
26 KDRect regularFrame = bounds();
27 KDRect modalFrame = frame();
29 return 1 + (m_isDisplayingModal && shouldDrawTheRegularViewBehind);
32 View * ModalViewController::ContentView::subviewAtIndex(
int index) {
35 if (m_isDisplayingModal && numberOfSubviews() == 1) {
36 return m_currentModalView;
40 if (numberOfSubviews() == 2) {
41 return m_currentModalView;
52 KDRect ModalViewController::ContentView::frame()
const {
53 KDSize modalSize = m_isDisplayingModal ? m_currentModalView->minimalSizeForOptimalDisplay() :
KDSize(0,0);
55 modalHeight = modalHeight == 0 ? bounds().height()-m_topMargin-m_bottomMargin : modalHeight;
57 modalWidth = modalWidth == 0 ? bounds().width()-m_leftMargin-m_rightMargin : modalWidth;
58 KDRect modalViewFrame(m_leftMargin + m_horizontalAlignment*(bounds().width()-m_leftMargin-m_rightMargin-modalWidth),
59 m_topMargin+m_verticalAlignment*(bounds().height()-m_topMargin-m_bottomMargin-modalHeight), modalWidth, modalHeight);
60 return modalViewFrame;
63 void ModalViewController::ContentView::layoutSubviews() {
64 assert(m_regularView !=
nullptr);
65 m_regularView->setFrame(bounds());
66 if (m_isDisplayingModal) {
67 assert(m_currentModalView !=
nullptr);
68 m_currentModalView->setFrame(frame());
72 void ModalViewController::ContentView::presentModalView(
View * modalView,
float verticalAlignment,
float horizontalAlignment,
74 m_isDisplayingModal =
true;
75 m_currentModalView = modalView;
76 m_horizontalAlignment = horizontalAlignment;
77 m_verticalAlignment = verticalAlignment;
78 m_topMargin = topMargin;
79 m_leftMargin = leftMargin;
80 m_bottomMargin = bottomMargin;
81 m_rightMargin = rightMargin;
82 markRectAsDirty(frame());
86 void ModalViewController::ContentView::dismissModalView() {
87 m_isDisplayingModal =
false;
88 markRectAsDirty(frame());
89 m_currentModalView->resetSuperview();
90 m_currentModalView =
nullptr;
94 bool ModalViewController::ContentView::isDisplayingModal()
const {
95 return m_isDisplayingModal;
101 m_previousResponder(child),
102 m_currentModalViewController(nullptr),
103 m_regularViewController(child)
108 return &m_contentView;
112 return m_contentView.isDisplayingModal();
117 m_currentModalViewController = vc;
120 m_contentView.presentModalView(vc->
view(), verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin);
128 m_contentView.dismissModalView();
129 m_currentModalViewController =
nullptr;
133 if (m_contentView.isDisplayingModal()) {
140 if (!m_contentView.isDisplayingModal()) {
151 m_contentView.setMainView(m_regularViewController->
view());
152 m_contentView.layoutSubviews();
153 if (m_contentView.isDisplayingModal()) {
160 if (m_contentView.isDisplayingModal()) {
void viewWillAppear() override
bool handleEvent(Ion::Events::Event event) override
bool contains(KDPoint p) const
KDPoint bottomRight() const
constexpr KDCoordinate width() const
void viewDidDisappear() override
ModalViewController(Responder *parentResponder, ViewController *child)
void didBecomeFirstResponder() override
void setParentResponder(Responder *responder)
void dismissModalViewController()
virtual void viewWillAppear()
Responder * firstResponder()
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
void setFirstResponder(Responder *responder)
virtual void viewDidDisappear()
constexpr KDCoordinate height() const