-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatusbar.c
executable file
·67 lines (58 loc) · 1.86 KB
/
statusbar.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
/* statusbar.c */
#include "ui.h"
static struct ContainerVtable statusBarVtable = {
&ContainerStartDrag, // NOOP
&ContainerDragBy, // NOOP
&ContainerStopDrag, // NOOP
&ContainerWasDragged,// NOOP
&StatusBarLayout,
&StatusBarUpdate,
&ContainerDraw, // no extra stuff
&StatusBarFree,
};
struct StatusBar* StatusBarNew(void)
{
float w = (float)GetScreenWidth();
float h = (float)GetScreenHeight();
struct StatusBar* self = calloc(1, sizeof(struct StatusBar));
if ( self ) {
ContainerCtor((struct Container*)self, (Rectangle){.x=0, .y=h-STATUSBAR_HEIGHT, .width=w, .height=STATUSBAR_HEIGHT});
self->super.vtable = &statusBarVtable;
}
return self;
}
void StatusBarLayoutWidgets(struct Container *const self)
{
size_t index;
for ( struct Widget *w = ArrayFirst(self->widgets, &index); w; w = ArrayNext(self->widgets, &index) ) {
switch (w->align) {
case -1:
w->rect.x = 0.0f + WIDGET_PADDING;
break;
case 0:
w->rect.x = (self->rect.width - w->rect.width) / 2.0f;
break;
case 1:
w->rect.x = self->rect.width - w->rect.width - WIDGET_PADDING;
break;
default:
break;
}
w->rect.y = (self->rect.height / 2.0f) - (w->rect.height / 2.0f);
}
}
void StatusBarLayout(struct Container *const self, const int windowWidth, const int windowHeight)
{
struct StatusBar* s = (struct StatusBar*)self;
s->super.rect = (Rectangle){.x=0, .y=(float)windowHeight-STATUSBAR_HEIGHT, .width=(float)windowWidth, .height=STATUSBAR_HEIGHT};
StatusBarLayoutWidgets(self);
}
void StatusBarUpdate(struct Container *const self)
{
(void)self;
}
void StatusBarFree(struct Container *const self)
{
// no extra members in StatusBar, so just free the base object
ContainerFree(self);
}