ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
TabViewController.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
26#include "TabViewController.h"
27
28#define _Class _TabViewController
29
30#pragma mark - Object
31
35static void dealloc(Object *self) {
36
37 TabViewController *this = (TabViewController *) self;
38
39 release(this->tabView);
40
41 super(Object, self, dealloc);
42}
43
44#pragma mark - ViewController
45
49static void loadView(ViewController *self) {
50
51 super(ViewController, self, loadView);
52
54
55 TabViewController *this = (TabViewController *) self;
56
57 this->tabView = $(alloc(TabView), initWithFrame, NULL);
58 assert(this->tabView);
59
60 this->tabView->delegate.self = this;
61
62 $(self->view, addSubview, (View *) this->tabView);
63}
64
68static void addChildViewController(ViewController *self, ViewController *childViewController) {
69
70 super(ViewController, self, addChildViewController, childViewController);
71
72 TabViewController *this = (TabViewController *) self;
73
74 TabViewItem *tab = $(alloc(TabViewItem), initWithView, childViewController->view);
75
76 $(this->tabView, addTab, tab);
77
78 release(tab);
79}
80
84static void removeChildViewController(ViewController *self, ViewController *childViewController) {
85
86 super(ViewController, self, removeChildViewController, childViewController);
87
88 TabViewController *this = (TabViewController *) self;
89
90 TabViewItem *tab = $(this, tabForViewController, childViewController);
91
92 $(this->tabView, removeTab, tab);
93}
94
95#pragma mark - TabViewController
96
102 return (TabViewController *) super(ViewController, self, init);
103}
104
108static _Bool tabForViewController_predicate(const ident obj, ident data) {
109 return ((TabViewItem *) obj)->view == data;
110}
111
116static TabViewItem *tabForViewController(const TabViewController *self, const ViewController *viewController) {
117
118 assert(viewController);
119
120 if (viewController->view) {
121 return $((Array *) self->tabView->tabs, findObject, tabForViewController_predicate, (ident) viewController->view);
122 }
123
124 return NULL;
125}
126
127#pragma mark - Class lifecycle
128
132static void initialize(Class *clazz) {
133
134 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
135
136 ((ViewControllerInterface *) clazz->interface)->loadView = loadView;
137 ((ViewControllerInterface *) clazz->interface)->addChildViewController = addChildViewController;
138 ((ViewControllerInterface *) clazz->interface)->removeChildViewController = removeChildViewController;
139
140 ((TabViewControllerInterface *) clazz->interface)->init = init;
141 ((TabViewControllerInterface *) clazz->interface)->tabForViewController = tabForViewController;
142}
143
148Class *_TabViewController(void) {
149 static Class *clazz;
150 static Once once;
151
152 do_once(&once, {
153 clazz = _initialize(&(const ClassDef) {
154 .name = "TabViewController",
155 .superclass = _ViewController(),
156 .instanceSize = sizeof(TabViewController),
157 .interfaceOffset = offsetof(TabViewController, interface),
158 .interfaceSize = sizeof(TabViewControllerInterface),
160 });
161 });
162
163 return clazz;
164}
165
166#undef _Class
static void dealloc(Object *self)
static void initialize(Class *clazz)
static _Bool tabForViewController_predicate(const ident obj, ident data)
Predicate for tabViewItemFor.
TabViewControllers arrange and manage their child ViewControllers in a tab view interface.
@ ViewAutoresizingContain
Definition: View.h:91
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
TabViewControllers arrange and manage their child ViewControllers in a tab view interface.
TabViewItem * tabForViewController(const TabViewController *self, const ViewController *viewController)
Returns the TabViewItem for the specified child ViewController, or NULL.
TabView * tabView
The TabView.
Class * _TabViewController(void)
The TabViewController archetype.
TabViews allow for the display of multiple pages of information within a single view.
Definition: TabView.h:79
void addTab(TabView *self, TabViewItem *tab)
Adds the specified TabViewItem to this TabView.
Definition: TabView.c:131
void removeTab(TabView *self, TabViewItem *tab)
Removes the specified TabViewItem from this TabView.
Definition: TabView.c:181
MutableArray * tabs
The TabViewItems.
Definition: TabView.h:115
TabViewItems embed Views in a TabView.
Definition: TabViewItem.h:51
TabViewItem * initWithView(TabViewItem *self, View *view)
Initializes this TabViewItem with the specified View.
Definition: TabViewItem.c:77
A ViewController manages a View and its descendants.
View * view
The main view.
Class * _ViewController(void)
The ViewController archetype.
void loadView(ViewController *self)
Loads this ViewController's View.
void addChildViewController(ViewController *self, ViewController *childViewController)
Adds the specified child ViewController to this ViewController.
void removeChildViewController(ViewController *self, ViewController *childViewController)
Removes the specified child ViewController from this ViewController.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
int autoresizingMask
The ViewAutoresizing bitmask.
Definition: View.h:154