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

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

◆ awakeWithDictionary()

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

Definition at line 69 of file Label.c.

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

◆ 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 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 ((Label *) self)->text->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 Label.c:47
static SDL_Rect bounds(const View *self)
Definition View.c:492

◆ init()

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

Definition at line 87 of file Label.c.

87 {
88 return (View *) $((Label *) self, initWithText, NULL, NULL);
89}
static Label * initWithText(Label *self, const char *text, Font *font)
Definition Label.c:97

◆ initialize()

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

Definition at line 116 of file Label.c.

116 {
117
118 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
119 ((ObjectInterface *) clazz->interface)->description = description;
120
121 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
122 ((ViewInterface *) clazz->interface)->init = init;
123
124 ((LabelInterface *) clazz->interface)->initWithText = initWithText;
125}
static View * init(View *self)
Definition Label.c:87

◆ initWithText()

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

Definition at line 97 of file Label.c.

97 {
98
99 self = (Label *) super(View, self, initWithFrame, NULL);
100 if (self) {
101
102 self->text = $(alloc(Text), initWithText, text, font);
103 assert(self->text);
104
105 $((View *) self, addSubview, (View *) self->text);
106 }
107
108 return self;
109}
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
Definition Box.c:92
static void addSubview(View *self, View *subview)
Definition PageView.c:49
Text * text
The Label Text.
Definition Label.h:56
Text rendered with TrueType fonts.
Definition Text.h:69