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

Go to the source code of this file.

Macros

#define _Class   _Option
 

Functions

Class * _Option (void)
 
static _Bool acceptsFirstResponder (const View *self)
 
static void dealloc (Object *self)
 
static String * description (const Object *self)
 
static void initialize (Class *clazz)
 
static OptioninitWithTitle (Option *self, const char *title, ident value)
 
static _Bool matchesSelector (const View *self, const SimpleSelector *simpleSelector)
 
static void setSelected (Option *self, _Bool isSelected)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Option

Definition at line 28 of file Option.c.

Function Documentation

◆ _Option()

Class * _Option ( void  )

Definition at line 151 of file Option.c.

151 {
152 static Class *clazz;
153 static Once once;
154
155 do_once(&once, {
156 clazz = _initialize(&(const ClassDef) {
157 .name = "Option",
158 .superclass = _View(),
159 .instanceSize = sizeof(Option),
160 .interfaceOffset = offsetof(Option, interface),
161 .interfaceSize = sizeof(OptionInterface),
163 });
164 });
165
166 return clazz;
167}
static void initialize(Class *clazz)
Definition: Option.c:134
Select Options.
Definition: Option.h:41
Class * _View(void)
The View archetype.
Definition: View.c:1769

◆ acceptsFirstResponder()

static _Bool acceptsFirstResponder ( const View self)
static
See also
View::acceptsFirstResponder(const View *)

Definition at line 68 of file Option.c.

68 {
69 return true;
70}

◆ dealloc()

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

Definition at line 35 of file Option.c.

35 {
36
37 Option *this = (Option *) self;
38
39 release(this->title);
40
41 super(Object, self, dealloc);
42}
static void dealloc(Object *self)
Definition: Option.c:35

◆ description()

static String * description ( const Object *  self)
static
See also
Object::description(const Object *)

Definition at line 47 of file Option.c.

47 {
48
49 View *this = (View *) self;
50
51 String *classNames = $((Object *) this->classNames, description);
52 String *description = str("%s@%p \"%s\" %s [%d, %d, %d, %d]",
53 this->identifier ?: classnameof(self),
54 self,
55 ((Option *) self)->title->text,
56 classNames->chars,
57 this->frame.x, this->frame.y, this->frame.w, this->frame.h);
58
59 release(classNames);
60 return description;
61}
static String * description(const Object *self)
Definition: Option.c:47
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133

◆ initialize()

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

Definition at line 134 of file Option.c.

134 {
135
136 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
137 ((ObjectInterface *) clazz->interface)->description = description;
138
139 ((ViewInterface *) clazz->interface)->acceptsFirstResponder = acceptsFirstResponder;
140 ((ViewInterface *) clazz->interface)->matchesSelector = matchesSelector;
141
142 ((OptionInterface *) clazz->interface)->initWithTitle = initWithTitle;
143 ((OptionInterface *) clazz->interface)->setSelected = setSelected;
144
145}
Button * initWithTitle(Button *self, const char *title)
Initializes this Button with the specified title.
Definition: Button.c:135
void setSelected(CollectionItemView *self, _Bool isSelected)
Sets the selected state of this item.
_Bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
_Bool acceptsFirstResponder(const View *self)
Definition: Control.c:68

◆ initWithTitle()

static Option * initWithTitle ( Option self,
const char *  title,
ident  value 
)
static

Definition at line 100 of file Option.c.

100 {
101
102 self = (Option *) super(View, self, initWithFrame, NULL);
103 if (self) {
104
105 self->title = $(alloc(Text), initWithText, title, NULL);
106 assert(self->title);
107
108 self->value = value;
109
110 $((View *) self, addSubview, (View *) self->title);
111 }
112
113 return self;
114}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
Label * initWithText(Label *self, const char *text, Font *font)
Initializes this Label with the given text and Font.
Definition: Label.c:96
Text * title
The title.
Definition: Option.h:62
ident value
The value.
Definition: Option.h:67
Text rendered with TrueType fonts.
Definition: Text.h:41
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35

◆ matchesSelector()

static _Bool matchesSelector ( const View self,
const SimpleSelector simpleSelector 
)
static
See also
View::matchesSelector(const View *, const SimpleSelector *)

Definition at line 75 of file Option.c.

75 {
76
77 assert(simpleSelector);
78
79 const Option *this = (Option *) self;
80
81 switch (simpleSelector->type) {
83 if (strcmp("selected", simpleSelector->pattern) == 0) {
84 return this->isSelected;
85 }
86 break;
87 default:
88 break;
89 }
90
91 return super(View, self, matchesSelector, simpleSelector);
92}
@ SimpleSelectorTypePseudo
_Bool isSelected(const Control *self)
Definition: Control.c:325
SimpleSelectorType type
The SimpleSelectorType.
char * pattern
The pattern, as provided by the user.

◆ setSelected()

static void setSelected ( Option self,
_Bool  isSelected 
)
static

Definition at line 120 of file Option.c.

120 {
121
122 if (self->isSelected != isSelected) {
123 self->isSelected = isSelected;
124
125 self->view.needsLayout = true;
126 }
127}
_Bool isSelected
True if this Option is selected, false otherwise.
Definition: Option.h:57
View view
The superclass.
Definition: Option.h:46
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221