From 7c6a945996a1d5510ff1412320ac7d07a0f82851 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 11 Feb 2024 00:04:31 +0000 Subject: Start working on it --- props.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 props.c (limited to 'props.c') diff --git a/props.c b/props.c new file mode 100644 index 0000000..40ebcdd --- /dev/null +++ b/props.c @@ -0,0 +1,60 @@ +#include +#include +#include + +#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 -- cgit v1.2.3