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

Go to the source code of this file.

Macros

#define _Class   _Box
 

Functions

Class * _Box (void)
 
static void awakeWithDictionary (View *self, const Dictionary *dictionary)
 
static void dealloc (Object *self)
 
static Viewinit (View *self)
 
static void initialize (Class *clazz)
 
static BoxinitWithFrame (Box *self, const SDL_Rect *frame)
 
static void layoutSubviews (View *self)
 

Macro Definition Documentation

◆ _Class

#define _Class   _Box

Definition at line 28 of file Box.c.

Function Documentation

◆ _Box()

Class * _Box ( void  )

Definition at line 138 of file Box.c.

138 {
139 static Class *clazz;
140 static Once once;
141
142 do_once(&once, {
143 clazz = _initialize(&(const ClassDef) {
144 .name = "Box",
145 .superclass = _View(),
146 .instanceSize = sizeof(Box),
147 .interfaceOffset = offsetof(Box, interface),
148 .interfaceSize = sizeof(BoxInterface),
150 });
151 });
152
153 return clazz;
154}
static void initialize(Class *clazz)
Definition: Box.c:123
A container View with a positioned Label.
Definition: Box.h:44
Class * _View(void)
The View archetype.
Definition: View.c:1769

◆ awakeWithDictionary()

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

Definition at line 50 of file Box.c.

50 {
51
52 super(View, self, awakeWithDictionary, dictionary);
53
54 Box *this = (Box *) self;
55
56 const Inlet inlets[] = MakeInlets(
57 MakeInlet("contentView", InletTypeView, &this->contentView, NULL),
58 MakeInlet("label", InletTypeView, &this->label, NULL)
59 );
60
61 $(self, bind, inlets, dictionary);
62}
@ 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.
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 Box.c.

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

◆ init()

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

Definition at line 67 of file Box.c.

67 {
68 return (View *) $((Box *) self, initWithFrame, NULL);
69}
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 123 of file Box.c.

123 {
124
125 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
126
127 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
128 ((ViewInterface *) clazz->interface)->init = init;
129 ((ViewInterface *) clazz->interface)->layoutSubviews = layoutSubviews;
130
131 ((BoxInterface *) clazz->interface)->initWithFrame = initWithFrame;
132}
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
Definition: Box.c:74

◆ initWithFrame()

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

Definition at line 92 of file Box.c.

92 {
93
94 self = (Box *) super(View, self, initWithFrame, frame);
95 if (self) {
96
97 self->contentView = $(alloc(StackView), initWithFrame, NULL);
98 assert(self->contentView);
99
100 $((View *) self->contentView, addClassName, "contentView");
101 $((View *) self->contentView, addClassName, "container");
102
103 $((View *) self, addSubview, (View *) self->contentView);
104
105 self->label = $(alloc(Label), initWithText, NULL, NULL);
106 assert(self->label);
107
108 View *label = (View *) self->label;
109
111
112 $((View *) self, addSubview, (View *) self->label);
113 }
114
115 return self;
116}
@ ViewAlignmentInternal
Definition: View.h:77
StackView * contentView
The internal container.
Definition: Box.h:60
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
ViewAlignment alignment
The alignment.
Definition: View.h:149
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

◆ layoutSubviews()

static void layoutSubviews ( View self)
static
See also
View::layoutSubviews(View *)

Definition at line 74 of file Box.c.

74 {
75
76 super(View, self, layoutSubviews);
77
78 View *label = (View *) ((Box *) self)->label;
79 if (label->hidden == false) {
80
81 const SDL_Size size = $(label, sizeThatContains);
82 label->frame.y = -size.h * 0.5;
83 }
84}
SDL_Size size(const Image *self)
Definition: Image.c:181
The SDL_Size type.
Definition: Types.h:62
int h
Definition: Types.h:63
_Bool hidden
If true, this View is not drawn.
Definition: View.h:195
SDL_Size sizeThatContains(const View *self)
Definition: View.c:1423
SDL_Rect frame
The frame, relative to the superview.
Definition: View.h:190