summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/widget/label.c
blob: bf990513e42c69f8324f8be1f889ac0c6f1176de (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
#include <stdlib.h>
#include <string.h>

#include "eve.h"
#include "eve_kbd.h"
#include "eve_font.h"

#include "screen/window.h"
#include "screen/page.h"

#include "label.h"

void eve_label_init(EVELabel *label, EVERect *g, EVEFont *font, char *title) {
    size_t title_len;
    int title_w, rv;

    memset(label, 0, sizeof(EVELabel));
    if (g) label->g = *g;

    rv = eve_font_str_w(font, label->title, &title_w, &title_len);
    if (rv) title[title_len] = '\0';

    label->font = font;
    label->title = title;
    if (label->g.h == 0) label->g.h = eve_font_h(font);
    if (label->g.w == 0) label->g.w = title_w + EVE_LABEL_MARGIN;
}

void eve_label_create(EVELabel *label, EVELabelSpec *spec, EVEPage *page) {
    EVEFont *font = spec->font ? spec->font : eve_window_font(page->v.window);

    eve_label_init(label, &spec->g, font, spec->title);
}

void eve_label_draw(EVELabel *label) {
    eve_cmd(CMD_TEXT, "hhhhs", label->g.x, label->g.y, label->font->id, 0, label->title);
}