shithub: spread

Download patch

ref: f397463f79e2b99db0b7a29d6c61396b88433717
parent: f929a0437dcb977136c0318ca851bfb49a254a51
author: sirjofri <[email protected]>
date: Thu Jul 4 11:05:52 EDT 2024

adds some styling and grid

--- a/spread.c
+++ b/spread.c
@@ -18,14 +18,16 @@
 	Image *bg;
 	Image *err;
 	Image *head;
+	Image *lines;
 };
 
 void
 initcolors(Colors *c)
 {
-	c->bg = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DWhite);
+	c->bg = allocimagemix(display, DPaleyellow, DWhite);
 	c->err = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DRed);
 	c->head = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlue);
+	c->lines = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DDarkyellow);
 }
 
 typedef struct Drawstate Drawstate;
@@ -33,6 +35,8 @@
 	P firstcell;
 	int dcolwidth;
 	Rectangle r;
+	int leftpad;
+	int toppad;
 };
 
 void
@@ -41,6 +45,8 @@
 	d->firstcell.x = d->firstcell.y = 1;
 	d->dcolwidth = 100;
 	d->r = screen->r;
+	d->leftpad = 2;
+	d->toppad = 2;
 }
 
 P
@@ -80,7 +86,9 @@
 	P first;
 	P cell;
 	int x, y;
+	int dx, dy;
 	Point p;
+	Point q;
 	Cell *c;
 	Response r;
 	char buf[10];
@@ -88,6 +96,8 @@
 	dstate.r = insetrect(screen->r, 4);
 	dstate.r.min.y += font->height;
 	dstate.r.min.x += stringwidth(font, "88888888");
+	dx = Dx(dstate.r);
+	dy = Dy(dstate.r);
 	
 	first = dstate.firstcell;
 	
@@ -97,10 +107,16 @@
 	for (x = first.x; x < first.x + dim.x; x++) {
 		cell.x = x;
 		cell.y = first.y - 1;
-		p = getcellpos(cell, &dstate);
+		p = addpt(getcellpos(cell, &dstate), dstate.r.min);
 		/* for some reason, drawing ntoa(x) directly doesn't work */
 		snprint(buf, sizeof(buf), "%s", ntoa(x));
-		string(screen, addpt(p, dstate.r.min), colors.head, ZP, font, buf);
+		
+		q = p;
+		q.y += dy + font->height;
+		line(screen, p, q, Endsquare, Endsquare, 0, colors.lines, ZP);
+		p.x += dstate.leftpad;
+		p.y += dstate.toppad;
+		string(screen, p, colors.head, ZP, font, buf);
 	}
 	
 	for (y = first.y; y < first.y + dim.y; y++) {
@@ -107,9 +123,15 @@
 		cell.x = first.x;
 		cell.y = y;
 		snprint(buf, sizeof(buf), "%d", y);
-		p = getcellpos(cell, &dstate);
-		p.x -= stringwidth(font, buf);
-		string(screen, addpt(p, dstate.r.min), colors.head, ZP, font, buf);
+		p = addpt(getcellpos(cell, &dstate), dstate.r.min);
+		p.x -= stringwidth(font, buf) + 5;
+		
+		q = p;
+		q.x += dx;
+		line(screen, p, q, Endsquare, Endsquare, 0, colors.lines, ZP);
+		p.x += dstate.leftpad;
+		p.y += dstate.toppad;
+		string(screen, p, colors.head, ZP, font, buf);
 	}
 	
 	first = dstate.firstcell;
@@ -121,7 +143,10 @@
 			
 			if (c) {
 				r = getvalue(cell);
-				string(screen, addpt(getcellpos(cell, &dstate), dstate.r.min),
+				p = addpt(getcellpos(cell, &dstate), dstate.r.min);
+				p.x += dstate.leftpad;
+				p.y += dstate.toppad;
+				string(screen, p,
 					r.error ? colors.err : display->black,
 					ZP, font, r.msg);
 				freeresponse(&r);