ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions
PageView.c File Reference
#include <assert.h>
#include "PageView.h"

Go to the source code of this file.

Macros

#define _Class   _PageView
 

Functions

Class * _PageView (void)
 
static void addSubview (View *self, View *subview)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static PageViewinitWithFrame (PageView *self, const SDL_Rect *frame)
 
static void removeSubview (View *self, View *subview)
 
static void setCurrentPage (PageView *self, View *currentPage)
 
static void setCurrentPage_enumerate (const Array *array, ident obj, ident data)
 ArrayEnumerator for setCurrentPage. More...
 
static Array * visibleSubviews (const View *self)
 

Macro Definition Documentation

◆ _Class

#define _Class   _PageView

Definition at line 28 of file PageView.c.

Function Documentation

◆ _PageView()

Class * _PageView ( void  )

Definition at line 161 of file PageView.c.

161 {
162 static Class *clazz;
163 static Once once;
164
165 do_once(&once, {
166 clazz = _initialize(&(const ClassDef) {
167 .name = "PageView",
168 .superclass = _View(),
169 .instanceSize = sizeof(PageView),
170 .interfaceOffset = offsetof(PageView, interface),
171 .interfaceSize = sizeof(PageViewInterface),
173 });
174 });
175
176 return clazz;
177}
static void initialize(Class *clazz)
Definition: PageView.c:146
PageViews manage their subviews as pages in a book.
Definition: PageView.h:60
Class * _View(void)
The View archetype.
Definition: View.c:1769

◆ addSubview()

static void addSubview ( View self,
View subview 
)
static
See also
View::addSubview(View *, View *)

Definition at line 35 of file PageView.c.

35 {
36
37 super(View, self, addSubview, subview);
38
39 PageView *this = (PageView *) self;
40
41 subview->hidden = true;
42
43 if (this->currentPage == NULL) {
44 $(this, setCurrentPage, subview);
45 }
46}
void setCurrentPage(PageView *self, View *currentPage)
Presents the specified subview as the current page of this PageView.
Definition: PageView.c:116
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
_Bool hidden
If true, this View is not drawn.
Definition: View.h:195
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35

◆ init()

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

Definition at line 51 of file PageView.c.

51 {
52 return (View *) $((PageView *) self, initWithFrame, NULL);
53}
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 146 of file PageView.c.

146 {
147
148 ((ViewInterface *) clazz->interface)->addSubview = addSubview;
149 ((ViewInterface *) clazz->interface)->init = init;
150 ((ViewInterface *) clazz->interface)->removeSubview = removeSubview;
151 ((ViewInterface *) clazz->interface)->visibleSubviews = visibleSubviews;
152
153 ((PageViewInterface *) clazz->interface)->initWithFrame = initWithFrame;
154 ((PageViewInterface *) clazz->interface)->setCurrentPage = setCurrentPage;
155}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Array * visibleSubviews(const View *self)
Definition: PageView.c:78
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58

◆ initWithFrame()

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

Definition at line 88 of file PageView.c.

88 {
89
90 self = (PageView *) super(View, self, initWithFrame, frame);
91 if (self) {
92 $((View *) self, addClassName, "container");
93 }
94
95 return self;
96}
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition: View.c:120

◆ removeSubview()

static void removeSubview ( View self,
View subview 
)
static
See also
View::removeSubview(View *, View *)

Definition at line 58 of file PageView.c.

58 {
59
60 PageView *this = (PageView *) self;
61
62 retain(subview);
63
64 super(View, self, removeSubview, subview);
65
66 subview->hidden = false;
67
68 if (subview == this->currentPage) {
69 $(this, setCurrentPage, NULL);
70 }
71
72 release(subview);
73}

◆ setCurrentPage()

static void setCurrentPage ( PageView self,
View currentPage 
)
static

Definition at line 116 of file PageView.c.

116 {
117
118 if (currentPage != self->currentPage) {
119
120 const Array *subviews = (Array *) self->view.subviews;
121
122 if (currentPage) {
123 self->currentPage = currentPage;
124 } else {
125 self->currentPage = $(subviews, firstObject);
126 }
127
128 $(subviews, enumerateObjects, setCurrentPage_enumerate, self);
129
130 if (self->currentPage) {
131
132 if (self->delegate.didSetCurrentPage) {
133 self->delegate.didSetCurrentPage(self);
134 }
135 }
136
137 self->view.needsLayout = true;
138 }
139}
static void setCurrentPage_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for setCurrentPage.
Definition: PageView.c:101
void(* didSetCurrentPage)(PageView *pageView)
Called when the current page is set.
Definition: PageView.h:52
View view
The superclass.
Definition: PageView.h:65
View * currentPage
The index of the current page.
Definition: PageView.h:76
PageViewDelegate delegate
The delegate.
Definition: PageView.h:81
MutableArray * subviews
The immediate subviews.
Definition: View.h:252
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221

◆ setCurrentPage_enumerate()

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

ArrayEnumerator for setCurrentPage.

Definition at line 101 of file PageView.c.

101 {
102
103 View *subview = obj;
104
105 if (subview == ((PageView *) data)->currentPage) {
106 subview->hidden = false;
107 } else {
108 subview->hidden = true;
109 }
110}

◆ visibleSubviews()

static Array * visibleSubviews ( const View self)
static
See also
View::visibleSubviews(const View *)

Definition at line 78 of file PageView.c.

78 {
79 return $$(Array, arrayWithArray, (Array *) self->subviews);
80}