ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
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 void dealloc (Object *self)
 
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.
 
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 177 of file PageView.c.

177 {
178 static Class *clazz;
179 static Once once;
180
181 do_once(&once, {
182 clazz = _initialize(&(const ClassDef) {
183 .name = "PageView",
184 .superclass = _View(),
185 .instanceSize = sizeof(PageView),
186 .interfaceOffset = offsetof(PageView, interface),
187 .interfaceSize = sizeof(PageViewInterface),
189 });
190 });
191
192 return clazz;
193}
static void initialize(Class *clazz)
Definition PageView.c:160
Class * _View(void)
Definition View.c:2067
PageViews manage their subviews as pages in a book.
Definition PageView.h:60

◆ addSubview()

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

Definition at line 49 of file PageView.c.

49 {
50
51 super(View, self, addSubview, subview);
52
53 PageView *this = (PageView *) self;
54
55 subview->hidden = true;
56
57 if (this->currentPage == NULL) {
58 $(this, setCurrentPage, subview);
59 }
60}
static void setCurrentPage(PageView *self, View *currentPage)
Definition PageView.c:130
static void addSubview(View *self, View *subview)
Definition PageView.c:49
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134
bool hidden
If true, this View is not drawn.
Definition View.h:196

◆ dealloc()

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

Definition at line 35 of file PageView.c.

35 {
36
37 PageView *this = (PageView *) self;
38
39 memset(&this->delegate, 0, sizeof(this->delegate));
40
41 super(Object, self, dealloc);
42}
static void dealloc(Object *self)
Definition PageView.c:35

◆ init()

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

Definition at line 65 of file PageView.c.

65 {
66 return (View *) $((PageView *) self, initWithFrame, NULL);
67}
static PageView * initWithFrame(PageView *self, const SDL_Rect *frame)
Definition PageView.c:102

◆ initialize()

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

Definition at line 160 of file PageView.c.

160 {
161
162 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
163
164 ((ViewInterface *) clazz->interface)->addSubview = addSubview;
165 ((ViewInterface *) clazz->interface)->init = init;
166 ((ViewInterface *) clazz->interface)->removeSubview = removeSubview;
167 ((ViewInterface *) clazz->interface)->visibleSubviews = visibleSubviews;
168
169 ((PageViewInterface *) clazz->interface)->initWithFrame = initWithFrame;
170 ((PageViewInterface *) clazz->interface)->setCurrentPage = setCurrentPage;
171}
static View * init(View *self)
Definition PageView.c:65
static void removeSubview(View *self, View *subview)
Definition PageView.c:72
static Array * visibleSubviews(const View *self)
Definition PageView.c:92
void setCurrentPage(PageView *self, View *currentPage)
Presents the specified subview as the current page of this PageView.
Definition PageView.c:130
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition PageView.c:72

◆ initWithFrame()

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

Definition at line 102 of file PageView.c.

102 {
103
104 self = (PageView *) super(View, self, initWithFrame, frame);
105 if (self) {
106 $((View *) self, addClassName, "container");
107 }
108
109 return self;
110}
static void addClassName(View *self, const char *className)
Definition View.c:159

◆ removeSubview()

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

Definition at line 72 of file PageView.c.

72 {
73
74 PageView *this = (PageView *) self;
75
76 retain(subview);
77
78 super(View, self, removeSubview, subview);
79
80 subview->hidden = false;
81
82 if (subview == this->currentPage) {
83 $(this, setCurrentPage, NULL);
84 }
85
86 release(subview);
87}

◆ setCurrentPage()

static void setCurrentPage ( PageView self,
View currentPage 
)
static

Definition at line 130 of file PageView.c.

130 {
131
132 if (currentPage != self->currentPage) {
133
134 const Array *subviews = (Array *) self->view.subviews;
135
136 if (currentPage) {
137 self->currentPage = currentPage;
138 } else {
139 self->currentPage = $(subviews, firstObject);
140 }
141
142 $(subviews, enumerate, setCurrentPage_enumerate, self);
143
144 if (self->currentPage) {
145
146 if (self->delegate.didSetCurrentPage) {
147 self->delegate.didSetCurrentPage(self);
148 }
149 }
150
151 self->view.needsLayout = true;
152 }
153}
static void setCurrentPage_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for setCurrentPage.
Definition PageView.c:115
static void enumerate(View *self, ViewEnumerator enumerator, ident data)
Definition View.c:749
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
Array * subviews
The immediate subviews.
Definition View.h:253
bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition View.h:222

◆ setCurrentPage_enumerate()

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

ArrayEnumerator for setCurrentPage.

Definition at line 115 of file PageView.c.

115 {
116
117 View *subview = obj;
118
119 if (subview == ((PageView *) data)->currentPage) {
120 subview->hidden = false;
121 } else {
122 subview->hidden = true;
123 }
124}

◆ visibleSubviews()

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

Definition at line 92 of file PageView.c.

92 {
93 return $$(Array, arrayWithArray, (Array *) self->subviews);
94}