ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
NavigationViewController.c
Go to the documentation of this file.
1/*
2 * ObjectivelyMVC: Object oriented MVC framework for OpenGL, SDL2 and GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include <assert.h>
25
27
28#define _Class _NavigationViewController
29
30#pragma mark - Object
31
32#pragma mark - NavigationViewController
33
39
40 return (NavigationViewController *) super(ViewController, self, init);
41}
42
47static void pushViewController(NavigationViewController *self, ViewController *viewController) {
48
49 assert(viewController);
50
51 ViewController *this = (ViewController *) self;
52
55
57 $(this->view, removeSubview, topViewController->view);
59 }
60
61 $(this, addChildViewController, viewController);
62}
63
69
73 }
74}
75
80static void popToViewController(NavigationViewController *self, const ViewController *viewController) {
81
83 while ((topViewController = $(self, topViewController))) {
84
85 if (topViewController == viewController) {
86 break;
87 }
88
89 $(self, popViewController);
90 }
91}
92
98
100 if (topViewController) {
102 }
103
104 ViewController *this = (ViewController *) self;
105 ViewController *that = $(self, topViewController);
106
107 if (that) {
108 $(that, viewWillAppear);
109 $(this->view, addSubview, that->view);
110 $(that, viewDidAppear);
111 }
112}
113
119 return (ViewController *) $((Array *) self->viewController.childViewControllers, firstObject);
120}
121
127 return (ViewController *) $((Array *) self->viewController.childViewControllers, lastObject);
128}
129
130#pragma mark - Class lifecycle
131
135static void initialize(Class *clazz) {
136
137 ((NavigationViewControllerInterface *) clazz->interface)->init = init;
138 ((NavigationViewControllerInterface *) clazz->interface)->pushViewController = pushViewController;
139 ((NavigationViewControllerInterface *) clazz->interface)->popToRootViewController = popToRootViewController;
140 ((NavigationViewControllerInterface *) clazz->interface)->popToViewController = popToViewController;
141 ((NavigationViewControllerInterface *) clazz->interface)->popViewController = popViewController;
142 ((NavigationViewControllerInterface *) clazz->interface)->rootViewController = rootViewController;
143 ((NavigationViewControllerInterface *) clazz->interface)->topViewController = topViewController;
144}
145
151 static Class *clazz;
152 static Once once;
153
154 do_once(&once, {
155 clazz = _initialize(&(const ClassDef) {
156 .name = "NavigationViewController",
157 .superclass = _ViewController(),
158 .instanceSize = sizeof(NavigationViewController),
159 .interfaceOffset = offsetof(NavigationViewController, interface),
160 .interfaceSize = sizeof(NavigationViewControllerInterface),
162 });
163 });
164
165 return clazz;
166}
167
168#undef _Class
169
static void initialize(Class *clazz)
Navigation controllers arrange their child controllers as a stack to facilitate navigation between th...
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Navigation controllers arrange their child controllers as a stack to facilitate navigation between th...
void pushViewController(NavigationViewController *self, ViewController *viewController)
Pushes the specified ViewController to the top of the stack.
Class * _NavigationViewController(void)
The NavigationViewController archetype.
void popToRootViewController(NavigationViewController *self)
Pops all ViewControllers on the stack except for the root ViewController.
void popToViewController(NavigationViewController *self, const ViewController *viewController)
Pops the top ViewController from the stack until the specified ViewController is visible.
ViewController rootViewController(const NavigationViewController *self)
void popViewController(NavigationViewController *self)
Pops the top ViewController from the stack.
ViewController viewController
The superclass.
ViewController topViewController(const NavigationViewController *self)
A ViewController manages a View and its descendants.
View * view
The main view.
Class * _ViewController(void)
The ViewController archetype.
void addChildViewController(ViewController *self, ViewController *childViewController)
Adds the specified child ViewController to this ViewController.
void viewWillAppear(ViewController *self)
This method is invoked before this ViewController's View is added to the View hierarchy.
MutableArray * childViewControllers
The child view controllers.
void viewDidDisappear(ViewController *self)
This method is invoked after this ViewController's View is removed to the View hierarchy.
void viewWillDisappear(ViewController *self)
This method is invoked before this ViewController's View is removed from the View hierarchy.
void removeChildViewController(ViewController *self, ViewController *childViewController)
Removes the specified child ViewController from this ViewController.
void viewDidAppear(ViewController *self)
This method is invoked after this ViewController's View is added to the View hierarchy.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58