ObjectivelyMVC
Object oriented MVC framework for SDL3 and GNU C
Loading...
Searching...
No Matches
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 View * init (View *self)
 
static void initialize (Class *clazz)
 
static Box * initWithFrame (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 134 of file Box.c.

134 {
135 static Class *clazz;
136 static Once once;
137
138 do_once(&once, {
139 clazz = _initialize(&(const ClassDef) {
140 .name = "Box",
141 .superclass = _View(),
142 .instanceSize = sizeof(Box),
143 .interfaceSize = sizeof(BoxInterface),
144 .initialize = initialize,
145 });
146 });
147
148 return clazz;
149}
static void initialize(Class *clazz)
Definition Box.c:119
Class * _View(void)
Definition View.c:2336
A container View with a positioned Label.
Definition Box.h:44

◆ 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}
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
Definition Box.c:50
@ 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 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}
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
Definition Box.c:92

◆ initialize()

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

Definition at line 119 of file Box.c.

119 {
120
121 ((ObjectInterface *) clazz->interface)->dealloc = dealloc;
122
123 ((ViewInterface *) clazz->interface)->awakeWithDictionary = awakeWithDictionary;
124 ((ViewInterface *) clazz->interface)->init = init;
125 ((ViewInterface *) clazz->interface)->layoutSubviews = layoutSubviews;
126
127 ((BoxInterface *) clazz->interface)->initWithFrame = initWithFrame;
128}
static View * init(View *self)
Definition Box.c:67
static void layoutSubviews(View *self)
Definition Box.c:74
layoutSubviews(View *self)
Arranges this View's immediate subviews within its (already final) frame.
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 *) self, addSubview, (View *) self->label);
109 }
110
111 return self;
112}
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
StackView * contentView
The internal container.
Definition Box.h:60
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

◆ 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->visibility != ViewVisibilityHidden) {
80
81 const SDL_Size size = $(label, sizeThatContains);
82 label->frame.y = -size.h * 0.5;
83 }
84}
static SDL_Size size(const Image *self)
Definition Image.c:416
static SDL_Size sizeThatContains(const View *self)
Definition View.c:1886
@ ViewVisibilityHidden
Definition View.h:122
ViewVisibility visibility
Whether this View is drawn, and contributes to its superview's size.
Definition View.h:468
SDL_Rect frame
The frame, relative to the superview.
Definition View.h:301