ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
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 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 145 of file Option.c.

145 {
146 static Class *clazz;
147 static Once once;
148
149 do_once(&once, {
150 clazz = _initialize(&(const ClassDef) {
151 .name = "Option",
152 .superclass = _View(),
153 .instanceSize = sizeof(Option),
154 .interfaceOffset = offsetof(Option, interface),
155 .interfaceSize = sizeof(OptionInterface),
157 });
158 });
159
160 return clazz;
161}
static void initialize(Class *clazz)
Definition Option.c:130
Class * _View(void)
Definition View.c:2067
Select Options.
Definition Option.h:41

◆ 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 const SDL_Rect bounds = $(this, bounds);
51
52 String *classNames = $((Object *) this->classNames, description);
53 String *description = str("%s@%p \"%s\" %s [%d, %d, %d, %d]",
54 this->identifier ?: classnameof(self),
55 self,
56 ((Option *) self)->title->text,
57 classNames->chars,
58 bounds.x, bounds.y, bounds.w, bounds.h);
59
60 release(classNames);
61 return description;
62}
static String * description(const Object *self)
Definition Option.c:47
static SDL_Rect bounds(const View *self)
Definition View.c:492
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:134

◆ initialize()

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

Definition at line 130 of file Option.c.

130 {
131
132 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
133 ((ObjectInterface *) clazz->interface)->description = description;
134
135 ((ViewInterface *) clazz->interface)->matchesSelector = matchesSelector;
136
137 ((OptionInterface *) clazz->interface)->initWithTitle = initWithTitle;
138 ((OptionInterface *) clazz->interface)->setSelected = setSelected;
139}
static void setSelected(Option *self, bool isSelected)
Definition Option.c:114
static bool matchesSelector(const View *self, const SimpleSelector *simpleSelector)
Definition Option.c:69
static Option * initWithTitle(Option *self, const char *title, ident value)
Definition Option.c:94
void setSelected(Option *self, bool isSelected)
Sets this Option's selected state.
Definition Option.c:114

◆ initWithTitle()

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

Definition at line 94 of file Option.c.

94 {
95
96 self = (Option *) super(View, self, initWithFrame, NULL);
97 if (self) {
98
99 self->title = $(alloc(Text), initWithText, title, NULL);
100 assert(self->title);
101
102 self->value = value;
103
104 $((View *) self, addSubview, (View *) self->title);
105 }
106
107 return self;
108}
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
static void addSubview(View *self, View *subview)
Definition PageView.c:49
Text * title
The title.
Definition Option.h:62
ident value
The value.
Definition Option.h:67
Text rendered with TrueType fonts.
Definition Text.h:69

◆ matchesSelector()

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

Definition at line 69 of file Option.c.

69 {
70
71 assert(simpleSelector);
72
73 const Option *this = (Option *) self;
74
75 switch (simpleSelector->type) {
77 if (strcmp("selected", simpleSelector->pattern) == 0) {
78 return this->isSelected;
79 }
80 break;
81 default:
82 break;
83 }
84
85 return super(View, self, matchesSelector, simpleSelector);
86}
static bool isSelected(const Control *self)
Definition Control.c:335
@ SimpleSelectorTypePseudo
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 114 of file Option.c.

114 {
115
116 if (self->isSelected != isSelected) {
117 self->isSelected = isSelected;
118
119 $((View *) self, invalidateStyle);
120
121 self->view.needsLayout = true;
122 }
123}
static void invalidateStyle(View *self)
Definition View.c:1033
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:222