ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
TabViewItem.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "TabViewItem.h"

Go to the source code of this file.

Macros

#define _Class   _TabViewItem
 

Functions

Class * _TabViewItem (void)
 
static void dealloc (Object *self)
 
static void initialize (Class *clazz)
 
static TabViewIteminitWithIdentifier (TabViewItem *self, const char *identifier)
 
static TabViewIteminitWithView (TabViewItem *self, View *view)
 
static void setState (TabViewItem *self, int state)
 

Macro Definition Documentation

◆ _Class

#define _Class   _TabViewItem

Definition at line 30 of file TabViewItem.c.

Function Documentation

◆ _TabViewItem()

Class * _TabViewItem ( void  )

Definition at line 122 of file TabViewItem.c.

122 {
123 static Class *clazz;
124 static Once once;
125
126 do_once(&once, {
127 clazz = _initialize(&(const ClassDef) {
128 .name = "TabViewItem",
129 .superclass = _Object(),
130 .instanceSize = sizeof(TabViewItem),
131 .interfaceOffset = offsetof(TabViewItem, interface),
132 .interfaceSize = sizeof(TabViewItemInterface),
134 });
135 });
136
137 return clazz;
138}
static void initialize(Class *clazz)
TabViewItems embed Views in a TabView.
Definition TabViewItem.h:51

◆ dealloc()

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

Definition at line 37 of file TabViewItem.c.

37 {
38
39 TabViewItem *this = (TabViewItem *) self;
40
41 free(this->identifier);
42
43 release(this->label);
44 release(this->view);
45
46 super(Object, self, dealloc);
47}
static void dealloc(Object *self)
Definition TabViewItem.c:37

◆ initialize()

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

Definition at line 109 of file TabViewItem.c.

109 {
110
111 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
112
113 ((TabViewItemInterface *) clazz->interface)->initWithIdentifier = initWithIdentifier;
114 ((TabViewItemInterface *) clazz->interface)->initWithView = initWithView;
115 ((TabViewItemInterface *) clazz->interface)->setState = setState;
116}
static void setState(TabViewItem *self, int state)
Definition TabViewItem.c:93
static TabViewItem * initWithView(TabViewItem *self, View *view)
Definition TabViewItem.c:78
static TabViewItem * initWithIdentifier(TabViewItem *self, const char *identifier)
Definition TabViewItem.c:55
setState(TabViewItem *self, int state)
Sets this TabViewItem's state, which may alter its appearance.
Definition TabViewItem.c:93
TabViewItem * initWithView(TabViewItem *self, View *view)
Initializes this TabViewItem with the specified View.
Definition TabViewItem.c:78

◆ initWithIdentifier()

static TabViewItem * initWithIdentifier ( TabViewItem self,
const char *  identifier 
)
static

Definition at line 55 of file TabViewItem.c.

55 {
56
57 self = (TabViewItem *) super(Object, self, init);
58 if (self) {
59 self->identifier = strdup(identifier);
60 assert(self->identifier);
61
62 self->label = $(alloc(Label), initWithText, self->identifier, NULL);
63 assert(self->label);
64
65 self->view = $(alloc(View), initWithFrame, NULL);
66 assert(self->view);
67
68 $(self, setState, TabStateDefault);
69 }
70
71 return self;
72}
static View * init(View *self)
Definition Box.c:67
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
Definition Box.c:92
static Label * initWithText(Label *self, const char *text, Font *font)
Definition Label.c:97
@ TabStateDefault
Definition TabViewItem.h:40
Labels provide a configurable container for Text.
Definition Label.h:40
View * view
The View this TabViewItem embeds.
Definition TabViewItem.h:82
Label * label
The Label used to select this tab.
Definition TabViewItem.h:72
char * identifier
The identifier.
Definition TabViewItem.h:67
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134

◆ initWithView()

static TabViewItem * initWithView ( TabViewItem self,
View view 
)
static

Definition at line 78 of file TabViewItem.c.

78 {
79
80 self = $(self, initWithIdentifier, view->identifier ?: classnameof(self));
81 if (self) {
82 release(self->view);
83 self->view = retain(view);
84 }
85
86 return self;
87}
char * identifier
An optional identifier.
Definition View.h:202

◆ setState()

static void setState ( TabViewItem self,
int  state 
)
static

Definition at line 93 of file TabViewItem.c.

93 {
94
95 self->state = state;
96
97 if (self->state & TabStateSelected) {
98 $((View *) self->label, addClassName, "selected");
99 } else {
100 $((View *) self->label, removeClassName, "selected");
101 }
102}
@ TabStateSelected
Definition TabViewItem.h:41
static void removeClassName(View *self, const char *className)
Definition View.c:1344
static void addClassName(View *self, const char *className)
Definition View.c:159
int state
The bit mask of TabState.
Definition TabViewItem.h:77