-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontainer.c
executable file
·70 lines (58 loc) · 1.47 KB
/
container.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* container.c */
#include "ui.h"
void ContainerCtor(struct Container *const self, Rectangle r)
{
self->rect = r;
self->widgets = ArrayNew(8);
}
#if 0
void ContainerLayoutWidgets(struct Container *const self)
{
(void)self; // all laying out will be done by subclasses
}
#endif
void ContainerStartDrag(struct Container *const self, Vector2 pos)
{
(void)self;
(void)pos;
}
void ContainerDragBy(struct Container *const self, Vector2 delta)
{
(void)self;
(void)delta;
}
void ContainerStopDrag(struct Container *const self, Vector2 pos)
{
(void)self;
(void)pos;
}
_Bool ContainerWasDragged(struct Container *const self, Vector2 pos)
{
(void)self;
(void)pos;
return 0;
}
void ContainerUpdate(struct Container *const self)
{
(void)self; // all updating done by subclass
}
void ContainerDraw(struct Container *const self)
{
extern Color uiBackgroundColor;
DrawRectangle((int)self->rect.x, (int)self->rect.y, (int)self->rect.width, (int)self->rect.height, uiBackgroundColor);
size_t index;
for ( struct Widget *w = ArrayFirst(self->widgets, &index); w; w = ArrayNext(self->widgets, &index) ) {
w->vtable->Draw(w);
}
}
void ContainerFree(struct Container *const self)
{
if ( self ) {
size_t index;
for ( struct Widget *w = ArrayFirst(self->widgets, &index); w; w = ArrayNext(self->widgets, &index) ) {
w->vtable->Free(w);
}
ArrayFree(self->widgets);
free(self);
}
}