summaryrefslogtreecommitdiff
path: root/props.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 00:04:31 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2024-02-11 00:04:31 +0000
commit7c6a945996a1d5510ff1412320ac7d07a0f82851 (patch)
treef77259f26b5c33307ba8ebc670951ed0acce1b00 /props.c
parentb5a96b97ee2f3fd30e5935d2b3c2c6e0d96c4640 (diff)
Start working on it
Diffstat (limited to 'props.c')
-rw-r--r--props.c60
1 files changed, 60 insertions, 0 deletions
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 <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