summaryrefslogtreecommitdiff
path: root/props.c
diff options
context:
space:
mode:
Diffstat (limited to 'props.c')
-rw-r--r--props.c77
1 files changed, 64 insertions, 13 deletions
diff --git a/props.c b/props.c
index df61782..f31270a 100644
--- a/props.c
+++ b/props.c
@@ -10,6 +10,7 @@
#include "guifs.h"
#define Eparse "could not parse property"
+#define Eoffset "cannot parse this property when writing at a non-zero offset"
int
allspace(char *r)
@@ -120,6 +121,17 @@ defmenus(int gtag, int ptag)
return v;
}
+PropVal
+defscroll(int gtag, int ptag)
+{
+ USED(gtag);
+ USED(ptag);
+
+ PropVal v;
+ v.scroll = 0;
+ return v;
+}
+
char *
printcolour(PropVal p)
{
@@ -196,20 +208,31 @@ printmenus(PropVal p)
}
char *
-parsecolour(char *str, PropVal *p)
+printscroll(PropVal p)
{
+ return smprint("%d\n", p.scroll);
+}
+
+char *
+parsecolour(char *str, int offset, PropVal *p)
+{
+ if(offset != 0)
+ return Eoffset;
+
char *r;
ulong c = strtoul(str, &r, 16);
if((r - str) != 8 || !allspace(r))
return Eparse;
- (*p).colour = mkcolour(c);
+ p->colour = mkcolour(c);
return nil;
}
char *
-parsespacing(char *str, PropVal *p)
+parsespacing(char *str, int offset, PropVal *p)
{
- USED(p);
+ if(offset != 0)
+ return Eoffset;
+
char *fields[5];
int spacings[4];
@@ -240,36 +263,50 @@ parsespacing(char *str, PropVal *p)
s->left = spacings[3];
break;
}
- (*p).spacing = s;
+ p->spacing = s;
return nil;
}
char *
-parseorientation(char *str, PropVal *p)
+parseorientation(char *str, int offset, PropVal *p)
{
+ if(offset != 0)
+ return Eoffset;
+
if(strncmp(str, "horizontal", 10) == 0 && allspace(str+10))
- (*p).orientation = Horizontal;
+ p->orientation = Horizontal;
else if(strncmp(str, "vertical", 8) == 0 && allspace(str+8))
- (*p).orientation = Vertical;
+ p->orientation = Vertical;
else
return Eparse;
return nil;
}
char *
-parsetext(char *str, PropVal *p)
+parsetext(char *str, int offset, PropVal *p)
{
- Rune *rstr = runesmprint("%s", str);
+ char *old = smprint("%S", p->text);
+ long oldlen = strlen(old);
+
+ if(offset > oldlen)
+ return Eparse;
+
+ old[offset] = 0;
+ Rune *rstr = runesmprint("%s%s", old, str);
+ free(old);
if(rstr == nil)
sysfatal("runesmprint failed");
- (*p).text = rstr;
+ p->text = rstr;
return nil;
}
char *
-parsemenus(char *str, PropVal *p)
+parsemenus(char *str, int offset, PropVal *p)
{
+ if(offset != 0)
+ return Eoffset;
+
char *err = nil;
int n = 0;
for(int i = 0; str[i] != 0; i++)
@@ -327,7 +364,6 @@ parsemenus(char *str, PropVal *p)
}
}
spec->menus[which]->item[count] = nil;
- print("count: %d\n", count);
}
Lend:
@@ -335,6 +371,20 @@ Lend:
return err;
}
+char *
+parsescroll(char *str, int offset, PropVal *p)
+{
+ if(offset != 0)
+ return Eoffset;
+
+ char *r;
+ ulong s = strtoul(str, &r, 10);
+ if(!allspace(r))
+ return Eparse;
+ p->scroll = (int)s;
+ return nil;
+}
+
PropVal
getprop(GuiElement *g, int tag, int lock)
{
@@ -378,6 +428,7 @@ PropSpec propspecs[Pmax] = {
[Ptext] = {"text", deftext, printtext, parsetext},
[Ptextcolour] = {"textcolour", defcolour, printcolour, parsecolour},
[Pmenus] = {"menus", defmenus, printmenus, parsemenus},
+ [Pscroll] = {"scroll", defscroll, printscroll, parsescroll},
};
int baseprops[nbaseprops] = {Pbackground, Pborder, Pmargin, Ppadding, Pbordercolour, Pmenus}; \ No newline at end of file