ref: 44f313b017b58d39731b1c2d034973bd67575376
parent: 1322210e058aee6327c77ea4acf8779d6620682f
author: sirjofri <[email protected]>
date: Fri Jul 5 10:25:50 EDT 2024
adds math mode, adjusts readme
--- a/README
+++ b/README
@@ -41,6 +41,9 @@
### Mouse control
- RMB click on a cell to edit it
+- Math cells that refer to other empty math cells generate those
+ cells automatically, with a default value of `0`. This will
+ overwrite existing text cells!
### Keyboard control
@@ -53,7 +56,8 @@
- `w [file]` - save to file (without file: save to original file)
- `s addr` - open the edit dialog for cell addr (addr be like: B5)
- `gg` - go to A1
-- `g addr` - go to addr. This scrolls so that addr is in the top left corner.
+- `g addr` - go to addr. This scrolls so that addr is in the top left corner
+- `m` - toggle math mode. Math mode displays non-math cells in a greyed out state
### Edit dialog
@@ -88,9 +92,13 @@
it is impossible to support ranges (`A3()..A5()`) out of the box.
If we need ranges we need to find a good solution or at least a
solid workaround, like building a list dynamically.
+ At the moment, I'm thinking about implementing a preprocessor that
+ transforms snippets like `[A1()+A5()]` to `A1()+A2()+A3()+A4()+A5()`.
+ Same should work for `[A1()*A5()]` etc.
## Bugs
Sure, there are many. Known issues are:
-- Cyclic dependencies are not allowed, but also not really checked for!
+- Cyclic dependencies are not allowed, I added come rudimentary check
+ that could leak some memory.
--- a/spread.c
+++ b/spread.c
@@ -22,6 +22,7 @@
Image *err;
Image *head;
Image *lines;
+ Image *mtext;
};
void
@@ -31,6 +32,7 @@
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);
+ c->mtext = allocimagemix(display, DBlack, DPaleyellow);
}
typedef struct Drawstate Drawstate;
@@ -40,6 +42,7 @@
Rectangle r;
int leftpad;
int toppad;
+ int mathmode;
};
void
@@ -50,6 +53,7 @@
d->r = screen->r;
d->leftpad = 2;
d->toppad = 2;
+ d->mathmode = 0;
}
P
@@ -109,6 +113,18 @@
string(screen, p, colors.err, ZP, font, error);
}
+static Image*
+getcolor(Cell *c)
+{
+ switch (c->type) {
+ case STRING:
+ return dstate.mathmode ? colors.mtext : display->black;
+ case FUNCTION:
+ default:
+ return display->black;
+ }
+}
+
void
redraw(void)
{
@@ -120,6 +136,7 @@
Point p;
Point q;
Cell *c;
+ Image *img;
Response r;
char buf[10];
@@ -174,12 +191,13 @@
c = getcell(cell);
if (c) {
+ img = getcolor(c);
r = getvalue(cell);
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,
+ r.error ? colors.err : img,
ZP, font, r.msg);
freeresponse(&r);
}
@@ -322,6 +340,9 @@
break;
}
error = Ebadcmd;
+ break;
+ case 'm': /* toggle math mode */
+ dstate.mathmode = !dstate.mathmode;
break;
}
}