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

Go to the source code of this file.

Macros

#define _Class   _Input
 

Functions

Class * _Input (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void dealloc (Object *self)
 
static View * init (View *self)
 
static void initialize (Class *clazz)
 
static Input * initWithFrame (Input *self, const SDL_Rect *frame)
 
static void setControl (Input *self, Control *control)
 
static void setLabel (Input *self, Label *label)
 
static void setOrientation (Input *self, InputOrientation orientation)
 

Variables

const EnumName InputOrientationNames []
 

Macro Definition Documentation

◆ _Class

#define _Class   _Input

Definition at line 35 of file Input.c.

Function Documentation

◆ _Input()

Class * _Input ( void  )

Definition at line 218 of file Input.c.

218 {
219 static Class *clazz;
220 static Once once;
221
222 do_once(&once, {
223 clazz = _initialize(&(const ClassDef) {
224 .name = "Input",
225 .superclass = _StackView(),
226 .instanceSize = sizeof(Input),
227 .interfaceSize = sizeof(InputInterface),
228 .initialize = initialize,
229 });
230 });
231
232 return clazz;
233}
static void initialize(Class *clazz)
Definition Input.c:201
Class * _StackView(void)
Definition StackView.c:358
An Input stacks a Label with a Control.
Definition Input.h:57

◆ awakeWithDictionary()

static void awakeWithDictionary ( View *  self,
const Dictionary *  dictionary 
)
static
See also
View::awakeWithDictionary(View *, const Dictionary *)

Definition at line 57 of file Input.c.

57 {
58
59 super(View, self, awakeWithDictionary, dictionary);
60
61 Input *this = (Input *) self;
62
63 const Inlet inlets[] = MakeInlets(
64 MakeInlet("control", InletTypeView, &this->control, NULL),
65 MakeInlet("label", InletTypeView, &this->label, NULL),
66 MakeInlet("orientation", InletTypeEnum, &this->orientation, (ident) InputOrientationNames)
67 );
68
69 $(self, bind, inlets, dictionary);
70
71 $(this, setOrientation, this->orientation);
72}
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
Definition Input.c:57
const EnumName InputOrientationNames[]
Definition Input.c:28
static void setOrientation(Input *self, InputOrientation orientation)
Definition Input.c:147
@ InletTypeEnum
Definition View+JSON.h:75
@ InletTypeView
Definition View+JSON.h:133
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition View+JSON.h:215
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition View+JSON.h:210
Inlets enable inbound data binding of View attributes through JSON.
Definition View+JSON.h:149
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition View.h:225

◆ dealloc()

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

Definition at line 42 of file Input.c.

42 {
43
44 Input *this = (Input *) self;
45
46 release(this->control);
47 release(this->label);
48
49 super(Object, self, dealloc);
50}
static void dealloc(Object *self)
Definition Input.c:42

◆ init()

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

Definition at line 77 of file Input.c.

77 {
78 return (View *) $((Input *) self, initWithFrame, NULL);
79}
static Input * initWithFrame(Input *self, const SDL_Rect *frame)
Definition Input.c:87

◆ initialize()

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

Definition at line 201 of file Input.c.

201 {
202
203 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
204
205 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
206 ((ViewInterface *) clazz->interface)->init = init;
207
208 ((InputInterface *) clazz->interface)->initWithFrame = initWithFrame;
209 ((InputInterface *) clazz->interface)->setControl = setControl;
210 ((InputInterface *) clazz->interface)->setLabel = setLabel;
211 ((InputInterface *) clazz->interface)->setOrientation = setOrientation;
212}
static View * init(View *self)
Definition Input.c:77
static void setControl(Input *self, Control *control)
Definition Input.c:113
static void setLabel(Input *self, Label *label)
Definition Input.c:130
void setControl(Input *self, Control *control)
Sets this Input's Control.
Definition Input.c:113
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.
Definition View.c:1047

◆ initWithFrame()

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

Definition at line 87 of file Input.c.

87 {
88
89 self = (Input *) super(StackView, self, initWithFrame, frame);
90 if (self) {
91
92 self->control = $(alloc(Control), initWithFrame, NULL);
93 assert(self->control);
94
95 self->label = $(alloc(Label), initWithText, NULL, NULL);
96 assert(self->label);
97
98 $((View *) self, addSubview, (View *) self->control);
99 $((View *) self, addSubview, (View *) self->label);
100
101 $((View *) self, addClassName, "container");
102
104 }
105
106 return self;
107}
@ InputOrientationLeft
Definition Input.h:39
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
static void addClassName(View *self, const char *className)
Definition View.c:183
Controls are Views which capture and respond to events.
Definition Control.h:83
Label * label
The Label.
Definition Input.h:78
Control * control
The Control.
Definition Input.h:73
Labels provide a configurable container for Text.
Definition Label.h:40
StackViews are containers that manage the arrangement of their subviews.
Definition StackView.h:68

◆ setControl()

static void setControl ( Input *  self,
Control *  control 
)
static

Definition at line 113 of file Input.c.

113 {
114
115 assert(control);
116
117 $((View *) self, removeSubview, (View *) self->control);
118 release(self->control);
119
120 self->control = retain(control);
121 $((View *) self, addSubview, (View *) self->control);
122
123 $(self, setOrientation, self->orientation);
124}
static void removeSubview(View *self, View *subview)
Definition PageView.c:72

◆ setLabel()

static void setLabel ( Input *  self,
Label *  label 
)
static

Definition at line 130 of file Input.c.

130 {
131
132 assert(label);
133
134 $((View *) self, removeSubview, (View *) self->label);
135 release(self->label);
136
137 self->label = retain(label);
138 $((View *) self, addSubview, (View *) self->label);
139
140 $(self, setOrientation, self->orientation);
141}

◆ setOrientation()

static void setOrientation ( Input *  self,
InputOrientation  orientation 
)
static

Definition at line 147 of file Input.c.

147 {
148
149 self->orientation = orientation;
150
151 View *this = (View *) self, *label = (View *) self->label, *control = (View *) self->control;
152
153 $(control, removeFromSuperview);
154 $(label, removeFromSuperview);
155
156 switch (self->orientation) {
159 $(this, addSubview, label);
160 $(this, addSubview, control);
161 break;
162
165 $(this, addSubview, control);
166 $(this, addSubview, label);
167 break;
168 }
169
170 switch (self->orientation) {
173 $(label->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleLeft);
174 $(control->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleRight);
175 break;
176
179 $(label->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleRight);
180 $(control->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleLeft);
181 break;
182
186 $(label->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleCenter);
187 $(control->style, addEnumAttribute, "alignment", ViewAlignmentNames, ViewAlignmentMiddleCenter);
188 break;
189 }
190
191 $(this, invalidateStyle);
192 $(label, invalidateStyle);
193 $(control, invalidateStyle);
194}
@ InputOrientationRight
Definition Input.h:40
@ InputOrientationAbove
Definition Input.h:41
@ InputOrientationBelow
Definition Input.h:42
const EnumName StackViewAxisNames[]
Definition StackView.c:28
@ StackViewAxisHorizontal
Definition StackView.h:44
@ StackViewAxisVertical
Definition StackView.h:43
static void addEnumAttribute(Style *self, const char *attr, const EnumName *names, int value)
Definition Style.c:288
const EnumName ViewAlignmentNames[]
Definition View.c:63
static void invalidateStyle(View *self)
Definition View.c:1092
static void removeFromSuperview(View *self)
Definition View.c:1462
@ ViewAlignmentMiddleCenter
Definition View.h:76
@ ViewAlignmentMiddleRight
Definition View.h:77
@ ViewAlignmentMiddleLeft
Definition View.h:75
InputOrientation orientation
The Label orientation.
Definition Input.h:83

Variable Documentation

◆ InputOrientationNames

const EnumName InputOrientationNames[]
Initial value:
= MakeEnumNames(
MakeEnumName(InputOrientationLeft),
MakeEnumName(InputOrientationRight),
MakeEnumName(InputOrientationAbove),
MakeEnumName(InputOrientationBelow)
)

Definition at line 28 of file Input.c.