summaryrefslogtreecommitdiff
path: root/src/widget/widget_label.c
blob: 449f91677fe232bddbaf7073197765231e5e639b (plain)
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

#include <stdlib.h>
#include <assert.h>

#include "main.h"
#include "interface.h"
#include "font.h"
#include "widget_label.h"
#include "widget.h"

widget_t *
newWidgetLabel(char *text, int x, int y, int bind)
{
    widget_label_t *new;

    new = malloc(sizeof(widget_label_t));
    new->text = strdup(text);
    new->bind = bind;
    getTextSize(text, &(new->w), &(new->h));

    return newWidget(WIDGET_TYPE_LABEL, x, y, new->w, new->h, new);
}

void
drawWidgetLabel(widget_t * widget)
{
    widget_label_t *p;

    assert(widget != NULL);
    assert(widget->type == WIDGET_TYPE_LABEL);

    p = (widget_label_t *) widget->private_data;

    switch (p->bind) {
    case WIDGET_LABEL_RIGHT:
        drawFont(p->text, widget->x + p->w, widget->y + p->h / 2,
                 COLOR_WHITE);
        break;
    case WIDGET_LABEL_LEFT:
        drawFont(p->text, widget->x, widget->y + widget->h / 2, COLOR_WHITE);
        break;
    case WIDGET_LABEL_CENTER:
        drawFont(p->text, widget->x - p->w / 2, widget->y + p->h / 2,
                 COLOR_WHITE);
        break;
    }
}

void
eventWidgetLabel(widget_t * widget)
{
    assert(widget != NULL);
    assert(widget->type == WIDGET_TYPE_LABEL);
}

void
destroyWidgetLabel(widget_t * widget)
{
    widget_label_t *p;

    assert(widget != NULL);
    assert(widget->type == WIDGET_TYPE_LABEL);

    p = (widget_label_t *) widget->private_data;

    free(p->text);
    free(p);

    destroyWidget(widget);
}