diff options
Diffstat (limited to 'props.c')
-rw-r--r-- | props.c | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -0,0 +1,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}, +};
\ No newline at end of file |