ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Functions
TabView.c File Reference
#include <assert.h>
#include <string.h>
#include <Objectively/String.h>
#include "TabView.h"

Go to the source code of this file.

Macros

#define _Class   _TabView
 

Functions

Class * _TabView (void)
 
static void addTab (TabView *self, TabViewItem *tab)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void awakeWithDictionary_tabs (const Array *array, ident obj, ident data)
 ArrayEnumerator for awaking TabViewItems. More...
 
static void dealloc (Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static TabViewinitWithFrame (TabView *self, const SDL_Rect *frame)
 
static void removeTab (TabView *self, TabViewItem *tab)
 
static void respondToEvent (View *self, const SDL_Event *event)
 
static void selectTab (TabView *self, TabViewItem *tab)
 
static void selectTab_enumerate (const Array *array, ident obj, ident data)
 ArrayEnumerator for selectTab. More...
 
static TabViewItemtabWithIdentifier (const TabView *self, const char *identifier)
 
static _Bool tabWithIdentifier_predicate (const ident obj, ident data)
 NULL-safe Predicate for tabWithIdentifier. More...
 

Macro Definition Documentation

◆ _Class

#define _Class   _TabView

Definition at line 31 of file TabView.c.

Function Documentation

◆ _TabView()

Class * _TabView ( void  )

Definition at line 301 of file TabView.c.

301 {
302 static Class *clazz;
303 static Once once;
304
305 do_once(&once, {
306 clazz = _initialize(&(const ClassDef) {
307 .name = "TabView",
308 .superclass = _StackView(),
309 .instanceSize = sizeof(TabView),
310 .interfaceOffset = offsetof(TabView, interface),
311 .interfaceSize = sizeof(TabViewInterface),
313 });
314 });
315
316 return clazz;
317}
static void initialize(Class *clazz)
Definition: TabView.c:282
Class * _StackView(void)
The StackView archetype.
Definition: StackView.c:262
TabViews allow for the display of multiple pages of information within a single view.
Definition: TabView.h:79

◆ addTab()

static void addTab ( TabView self,
TabViewItem tab 
)
static

Definition at line 131 of file TabView.c.

131 {
132
133 assert(tab);
134
135 $(self->tabs, addObject, tab);
136
137 $((View *) self->tabSelectionView, addSubview, (View *) tab->label);
138 $((View *) self->tabPageView, addSubview, tab->view);
139
140 if (self->delegate.didAddTab) {
141 self->delegate.didAddTab(self, tab);
142 }
143
144 if (self->selectedTab == NULL) {
145 $(self, selectTab, tab);
146 }
147}
void(* didAddTab)(TabView *tabView, TabViewItem *tab)
Called when a tab is added.
Definition: TabView.h:57
PageView * tabPageView
The tab content container.
Definition: TabView.h:105
TabViewItem * selectedTab
The selected TabViewItem.
Definition: TabView.h:100
MutableArray * tabs
The TabViewItems.
Definition: TabView.h:115
StackView * tabSelectionView
The tab selection container.
Definition: TabView.h:110
TabViewDelegate delegate
The TabViewDelegate.
Definition: TabView.h:95
void selectTab(TabView *self, TabViewItem *tab)
Selects the specified TabViewItem.
Definition: TabView.c:225
View * view
The View this TabViewItem embeds.
Definition: TabViewItem.h:82
Label * label
The Label used to select this tab.
Definition: TabViewItem.h:72
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

◆ awakeWithDictionary()

static void awakeWithDictionary ( View self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 76 of file TabView.c.

76 {
77
78 super(View, self, awakeWithDictionary, dictionary);
79
80 TabView *this = (TabView *) self;
81
82 const Inlet inlets[] = MakeInlets(
83 MakeInlet("tabPageView", InletTypeView, &this->tabPageView, NULL),
84 MakeInlet("tabSelectionView", InletTypeView, &this->tabSelectionView, NULL)
85 );
86
87 $(self, bind, inlets, dictionary);
88
89 const Array *tabs = $(dictionary, objectForKeyPath, "tabs");
90 if (tabs) {
91 $(tabs, enumerateObjects, awakeWithDictionary_tabs, self);
92 }
93}
static void awakeWithDictionary_tabs(const Array *array, ident obj, ident data)
ArrayEnumerator for awaking TabViewItems.
Definition: TabView.c:54
@ InletTypeView
Definition: View+JSON.h:139
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition: View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition: View+JSON.h:216
Inlets enable inbound data binding of View attributes through JSON.
Definition: View+JSON.h:155
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
Definition: Box.c:50

◆ awakeWithDictionary_tabs()

static void awakeWithDictionary_tabs ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator for awaking TabViewItems.

Definition at line 54 of file TabView.c.

54 {
55
56 const String *identifier = $((Dictionary *) obj, objectForKeyPath, "identifier");
57 assert(identifier);
58
59 TabViewItem *tab = $(alloc(TabViewItem), initWithIdentifier, identifier->chars);
60 assert(tab);
61
62 const Inlet inlets[] = MakeInlets(
63 MakeInlet("label", InletTypeView, &tab->label, NULL),
64 MakeInlet("view", InletTypeView, &tab->view, NULL)
65 );
66
67 $((View *) data, bind, inlets, obj);
68 $((TabView *) data, addTab, tab);
69
70 release(tab);
71}
void addTab(TabView *self, TabViewItem *tab)
Adds the specified TabViewItem to this TabView.
Definition: TabView.c:131
TabViewItems embed Views in a TabView.
Definition: TabViewItem.h:51
TableColumn * initWithIdentifier(TableColumn *self, const char *identifier)
Initializes this TableColumn with the given identifier.
Definition: TableColumn.c:56

◆ dealloc()

static void dealloc ( Object *  self)
static
See also
Object::dealloc(Object *)

Definition at line 38 of file TabView.c.

38 {
39
40 TabView *this = (TabView *) self;
41
42 release(this->tabPageView);
43 release(this->tabSelectionView);
44 release(this->tabs);
45
46 super(Object, self, dealloc);
47}
static void dealloc(Object *self)
Definition: TabView.c:38

◆ init()

static View * init ( View self)
static
See also
View::init(View *)

Definition at line 98 of file TabView.c.

98 {
99 return (View *) $((TabView *) self, initWithFrame, NULL);
100}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92

◆ initialize()

static void initialize ( Class *  clazz)
static
See also
Class::initialize(Class *)

Definition at line 282 of file TabView.c.

282 {
283
284 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
285
286 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
287 ((ViewInterface *) clazz->interface)->init = init;
288 ((ViewInterface *) clazz->interface)->respondToEvent = respondToEvent;
289
290 ((TabViewInterface *) clazz->interface)->addTab = addTab;
291 ((TabViewInterface *) clazz->interface)->initWithFrame = initWithFrame;
292 ((TabViewInterface *) clazz->interface)->removeTab = removeTab;
293 ((TabViewInterface *) clazz->interface)->selectTab = selectTab;
294 ((TabViewInterface *) clazz->interface)->tabWithIdentifier = tabWithIdentifier;
295}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void removeTab(TabView *self, TabViewItem *tab)
Removes the specified TabViewItem from this TabView.
Definition: TabView.c:181
TabViewItem * tabWithIdentifier(const TabView *self, const char *identifier)
Definition: TabView.c:273
void respondToEvent(View *self, const SDL_Event *event)
Responds to the specified event.
Definition: Control.c:213

◆ initWithFrame()

static TabView * initWithFrame ( TabView self,
const SDL_Rect *  frame 
)
static

Definition at line 153 of file TabView.c.

153 {
154
155 self = (TabView *) super(StackView, self, initWithFrame, frame);
156 if (self) {
157
158 self->tabPageView = $(alloc(PageView), initWithFrame, NULL);
159 assert(self->tabPageView);
160
161 self->tabs = $$(MutableArray, array);
162 assert(self->tabs);
163
164 self->tabSelectionView = $(alloc(StackView), initWithFrame, NULL);
165 assert(self->tabSelectionView);
166
167 $((View *) self->tabSelectionView, addClassName, "tabSelectionView");
168 $((View *) self, addSubview, (View *) self->tabSelectionView);
169
170 $((View *) self->tabPageView, addClassName, "tabPageView");
171 $((View *) self, addSubview, (View *) self->tabPageView);
172 }
173
174 return self;
175}
PageViews manage their subviews as pages in a book.
Definition: PageView.h:60
StackViews are containers that manage the arrangement of their subviews.
Definition: StackView.h:68
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition: View.c:120

◆ removeTab()

static void removeTab ( TabView self,
TabViewItem tab 
)
static

Definition at line 181 of file TabView.c.

181 {
182
183 assert(tab);
184
185 if (self->delegate.willRemoveTab) {
186 self->delegate.willRemoveTab(self, tab);
187 }
188
189 retain(tab);
190
191 $(self->tabs, removeObject, tab);
192
193 $((View *) self->tabSelectionView, removeSubview, (View *) tab->label);
194 $((View *) self->tabPageView, removeSubview, tab->view);
195
196 if (self->selectedTab == tab) {
197 $(self, selectTab, NULL);
198 }
199
200 release(tab);
201}
void(* willRemoveTab)(TabView *tabView, TabViewItem *tab)
Called when a tab is to be removed.
Definition: TabView.h:71
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58

◆ respondToEvent()

static void respondToEvent ( View self,
const SDL_Event *  event 
)
static
See also
View::respondToEvent(View *, const SDL_Event *)

Definition at line 105 of file TabView.c.

105 {
106
107 if (event->type == SDL_MOUSEBUTTONUP) {
108
109 TabView *this = (TabView *) self;
110
111 const Array *tabs = (Array *) this->tabs;
112 for (size_t i = 0; i < tabs->count; i++) {
113
114 TabViewItem *tab = $(tabs, objectAtIndex, i);
115
116 if ($((View *) tab->label, didReceiveEvent, event)) {
117 $(this, selectTab, tab);
118 }
119 }
120 }
121
122 super(View, self, respondToEvent, event);
123}
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
Definition: View.c:546

◆ selectTab()

static void selectTab ( TabView self,
TabViewItem tab 
)
static

Definition at line 225 of file TabView.c.

225 {
226
227 if (self->selectedTab != tab) {
228
229 const Array *tabs = (Array *) self->tabs;
230
231 if (tab) {
232 self->selectedTab = tab;
233 } else {
234 self->selectedTab = $(tabs, firstObject);
235 }
236
237 $(tabs, enumerateObjects, selectTab_enumerate, self);
238
239 if (self->selectedTab) {
240 $(self->tabPageView, setCurrentPage, self->selectedTab->view);
241
242 if (self->delegate.didSelectTab) {
243 self->delegate.didSelectTab(self, self->selectedTab);
244 }
245 }
246
247 self->stackView.view.needsLayout = true;
248 }
249}
static void selectTab_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for selectTab.
Definition: TabView.c:206
void setCurrentPage(PageView *self, View *currentPage)
Presents the specified subview as the current page of this PageView.
Definition: PageView.c:116
View view
The superclass.
Definition: StackView.h:73
void(* didSelectTab)(TabView *tabView, TabViewItem *tab)
Called when a tab is selected.
Definition: TabView.h:64
StackView stackView
The superclass.
Definition: TabView.h:84
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221

◆ selectTab_enumerate()

static void selectTab_enumerate ( const Array *  array,
ident  obj,
ident  data 
)
static

ArrayEnumerator for selectTab.

Definition at line 206 of file TabView.c.

206 {
207
208 TabViewItem *tab = obj;
209
210 int state = tab->state;
211
212 if (tab == ((TabView *) data)->selectedTab) {
213 state |= TabStateSelected;
214 } else {
215 state &= ~TabStateSelected;
216 }
217
218 $(tab, setState, state);
219}
@ TabStateSelected
Definition: TabViewItem.h:41
setState(TabViewItem *self, int state)
Sets this TabViewItem's state, which may alter its appearance.
Definition: TabViewItem.c:92
int state
The bit mask of TabState.
Definition: TabViewItem.h:77

◆ tabWithIdentifier()

static TabViewItem * tabWithIdentifier ( const TabView self,
const char *  identifier 
)
static

Definition at line 273 of file TabView.c.

273 {
274 return $((Array *) self->tabs, findObject, tabWithIdentifier_predicate, (ident) identifier);
275}
static _Bool tabWithIdentifier_predicate(const ident obj, ident data)
NULL-safe Predicate for tabWithIdentifier.
Definition: TabView.c:254

◆ tabWithIdentifier_predicate()

static _Bool tabWithIdentifier_predicate ( const ident  obj,
ident  data 
)
static

NULL-safe Predicate for tabWithIdentifier.

Definition at line 254 of file TabView.c.

254 {
255
256 const TabViewItem *tab = obj;
257
258 if (tab->identifier) {
259 if (data) {
260 return !strcmp(tab->identifier, data);
261 } else {
262 return false;
263 }
264 } else {
265 return data == NULL;
266 }
267}
char * identifier
The identifier.
Definition: TabViewItem.h:67