summaryrefslogtreecommitdiff
path: root/props.c
blob: 40ebcdd0897e8ecc4adc4b23390dde0ba9d54651 (plain) (blame)
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
#include <u.h>
#include <libc.h>
#include <draw.h>

#include "guifs.h"

#define Eparse "could not parse property"

PropVal
defbackground(void)
{
	PropVal v;
	v.colour = mkcolour(DBlack);
	return v;
}

char *
printcolour(PropVal p)
{
	int bufsize = 64;
	char *buf = emalloc(bufsize);
	snprint(buf, bufsize, "%08ulX\n", p.colour->code);
	return buf;
}

char *
parsecolour(char *str, PropVal *p)
{
	char *r;
	ulong c = strtoul(str, &r, 16);
	if((r - str) != 8)
		return Eparse;
	(*p).colour = mkcolour(c);
	return nil;
}

PropVal
getprop(GuiElement *g, int tag)
{
	for(int i = 0; i < g->nprops; i++)
		if(g->props[i].tag == tag)
			return g->props[i].val;
	sysfatal("invalid prop for this gui element");
}

void
setprop(GuiElement *g, int tag, PropVal val)
{
	/* TODO: free old propval */
	for(int i = 0; i < g->nprops; i++)
		if(g->props[i].tag == tag){
			g->props[i].val = val;
			updategui(0);
			return;
		}
}

PropSpec propspecs[Pmax] = {
	[Pbackground] = {"background",	defbackground,	printcolour,	parsecolour},
};