]> git.ipfire.org Git - thirdparty/newt.git/blame - label.c
removed newtEntryAddCallback(), changed callback logic to use component
[thirdparty/newt.git] / label.c
CommitLineData
0d5acc76 1#include <slang/slang.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include "newt.h"
6#include "newt_pr.h"
7
8struct label {
9 char * text;
10};
11
12static void labelDraw(newtComponent co);
13static void labelDestroy(newtComponent co);
14
15static struct componentOps labelOps = {
16 labelDraw,
17 newtDefaultEventHandler,
18 labelDestroy,
19} ;
20
21newtComponent newtLabel(int left, int top, char * text) {
22 newtComponent co;
23 struct label * la;
24
25 co = malloc(sizeof(*co));
26 la = malloc(sizeof(struct label));
27 co->data = la;
28
29 co->ops = &labelOps;
30
31 co->height = 1;
32 co->width = strlen(text);
33 co->top = top;
34 co->left = left;
35 co->takesFocus = 0;
36
37 la->text = strdup(text);
38
39 return co;
40}
41
42static void labelDraw(newtComponent co) {
43 struct label * la = co->data;
44
45 if (co->top == -1) return;
46
47 SLsmg_set_color(COLORSET_LABEL);
48
49 newtGotorc(co->top, co->left);
50 SLsmg_write_string(la->text);
51}
52
53static void labelDestroy(newtComponent co) {
54 struct label * la = co->data;
55
56 free(la->text);
57 free(la);
58 free(co);
59}