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

Go to the source code of this file.

Macros

#define _Class   _Label
 

Functions

Class * _Label (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void dealloc (Object *self)
 
static String * description (const Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static LabelinitWithText (Label *self, const char *text, Font *font)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Label

Definition at line 28 of file Label.c.

Function Documentation

◆ _Label()

Class * _Label ( void  )

Definition at line 130 of file Label.c.

130 {
131 static Class *clazz;
132 static Once once;
133
134 do_once(&once, {
135 clazz = _initialize(&(const ClassDef) {
136 .name = "Label",
137 .superclass = _View(),
138 .instanceSize = sizeof(Label),
139 .interfaceOffset = offsetof(Label, interface),
140 .interfaceSize = sizeof(LabelInterface),
142 });
143 });
144
145 return clazz;
146}
static void initialize(Class *clazz)
Definition: Label.c:115
Labels provide a configurable container for Text.
Definition: Label.h:40
Class * _View(void)
The View archetype.
Definition: View.c:1769

◆ awakeWithDictionary()

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

Definition at line 68 of file Label.c.

68 {
69
70 super(View, self, awakeWithDictionary, dictionary);
71
72 Label *this = (Label *) self;
73
74 const Inlet inlets[] = MakeInlets(
75 MakeInlet("text", InletTypeView, &this->text, NULL)
76 );
77
78 $(self, bind, inlets, dictionary);
79
80 self->needsLayout = true;
81}
@ 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
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.
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
Definition: View.h:221
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 35 of file Label.c.

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

◆ description()

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

Definition at line 47 of file Label.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 ((Label *) self)->text->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: Label.c:47

◆ init()

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

Definition at line 86 of file Label.c.

86 {
87 return (View *) $((Label *) self, initWithText, NULL, NULL);
88}
Label * initWithText(Label *self, const char *text, Font *font)
Initializes this Label with the given text and Font.
Definition: Label.c:96

◆ initialize()

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

Definition at line 115 of file Label.c.

115 {
116
117 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
118 ((ObjectInterface *) clazz->interface)->description = description;
119
120 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
121 ((ViewInterface *) clazz->interface)->init = init;
122
123 ((LabelInterface *) clazz->interface)->initWithText = initWithText;
124}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.

◆ initWithText()

static Label * initWithText ( Label self,
const char *  text,
Font font 
)
static

Definition at line 96 of file Label.c.

96 {
97
98 self = (Label *) super(View, self, initWithFrame, NULL);
99 if (self) {
100
101 self->text = $(alloc(Text), initWithText, text, font);
102 assert(self->text);
103
104 $((View *) self, addSubview, (View *) self->text);
105 }
106
107 return self;
108}
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Definition: Box.c:92
Text * text
The Label Text.
Definition: Label.h:56
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