ObjectivelyMVC 0.1.0
Object oriented MVC framework for OpenGL, SDL2 and GNU C
Macros | Functions | Variables
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 Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static InputinitWithFrame (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 212 of file Input.c.

212 {
213 static Class *clazz;
214 static Once once;
215
216 do_once(&once, {
217 clazz = _initialize(&(const ClassDef) {
218 .name = "Input",
219 .superclass = _StackView(),
220 .instanceSize = sizeof(Input),
221 .interfaceOffset = offsetof(Input, interface),
222 .interfaceSize = sizeof(InputInterface),
224 });
225 });
226
227 return clazz;
228}
static void initialize(Class *clazz)
Definition: Input.c:195
An Input stacks a Label with a Control.
Definition: Input.h:57
Class * _StackView(void)
The StackView archetype.
Definition: StackView.c:262

◆ 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}
const EnumName InputOrientationNames[]
Definition: Input.c:28
@ InletTypeEnum
Definition: View+JSON.h:75
@ InletTypeView
Definition: View+JSON.h:139
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
Definition: View+JSON.h:221
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Definition: View+JSON.h:216
Inlets enable inbound data binding of View attributes through JSON.
Definition: View+JSON.h:155
void setOrientation(Input *self, InputOrientation orientation)
Sets this Input's orientation.
Definition: Input.c:147
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
Definition: View.h:133
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
Definition: Box.c:50

◆ 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}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92

◆ initialize()

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

Definition at line 195 of file Input.c.

195 {
196
197 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
198
199 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
200 ((ViewInterface *) clazz->interface)->init = init;
201
202 ((InputInterface *) clazz->interface)->initWithFrame = initWithFrame;
203 ((InputInterface *) clazz->interface)->setControl = setControl;
204 ((InputInterface *) clazz->interface)->setLabel = setLabel;
205 ((InputInterface *) clazz->interface)->setOrientation = setOrientation;
206}
CollectionView * initWithFrame(CollectionView *self, const SDL_Rect *frame)
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
void setLabel(Input *self, Label *label)
Sets this Input's Label.
Definition: Input.c:130
void setControl(Input *self, Control *control)
Sets this Input's Control.
Definition: Input.c:113

◆ 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
Controls are Views which capture events and dispatch Actions.
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
Label * initWithText(Label *self, const char *text, Font *font)
Initializes this Label with the given text and Font.
Definition: Label.c:96
StackViews are containers that manage the arrangement of their subviews.
Definition: StackView.h:68
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
Definition: PageView.c:35
void addClassName(View *self, const char *className)
Adds the given class name to this View.
Definition: View.c:120

◆ 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}
void removeSubview(View *self, View *subview)
Removes the given subview from this View.
Definition: PageView.c:58

◆ 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 *) self->control, removeFromSuperview);
152 $((View *) self->label, removeFromSuperview);
153
154 switch (self->orientation) {
157 $((View *) self, addSubview, (View *) self->label);
158 $((View *) self, addSubview, (View *) self->control);
159 break;
160
163 $((View *) self, addSubview, (View *) self->control);
164 $((View *) self, addSubview, (View *) self->label);
165 break;
166 }
167
168 switch (self->orientation) {
170 self->stackView.axis = StackViewAxisHorizontal;
171 self->label->view.alignment = ViewAlignmentMiddleLeft;
172 self->control->view.alignment = ViewAlignmentMiddleRight;
173 break;
174
176 self->stackView.axis = StackViewAxisHorizontal;
177 self->label->view.alignment = ViewAlignmentMiddleRight;
178 self->control->view.alignment = ViewAlignmentMiddleLeft;
179 break;
180
183 self->stackView.axis = StackViewAxisVertical;
184 self->label->view.alignment = ViewAlignmentMiddleCenter;
185 self->control->view.alignment = ViewAlignmentMiddleCenter;
186 break;
187 }
188}
@ InputOrientationRight
Definition: Input.h:40
@ InputOrientationAbove
Definition: Input.h:41
@ InputOrientationBelow
Definition: Input.h:42
@ StackViewAxisHorizontal
Definition: StackView.h:44
@ StackViewAxisVertical
Definition: StackView.h:43
@ ViewAlignmentMiddleCenter
Definition: View.h:72
@ ViewAlignmentMiddleRight
Definition: View.h:73
@ ViewAlignmentMiddleLeft
Definition: View.h:71
InputOrientation orientation
The Label orientation.
Definition: Input.h:83
ViewAlignment alignment
The alignment.
Definition: View.h:149
void removeFromSuperview(View *self)
Removes this View from its superview.
Definition: View.c:1175

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.