ref: 1181f702c0ee4504eafb1a1134f7672a30217633
parent: 8e2c4db83ac84ceb86c60e50db20e8aca55ec5e9
author: glenda <glenda@krsna>
date: Sun Aug 17 12:54:15 EDT 2025
paragraph-conf
--- a/fc.c
+++ b/fc.c
@@ -27,6 +27,8 @@
#define DEFAULT_MAX_EVAL_DEPTH 10
#define DEFAULT_MAX_RECALC_PASSES 10
#define DEFAULT_FORMULA_PRECISION 2
+#define DEFAULT_PARAGRAPH_W 256
+#define DEFAULT_PARAGRAPH_H 128
/* Constants */
#define MAXBOXES 300
@@ -34,9 +36,8 @@
#define BOXHEIGHT 32
#define MAXFORMULA 256
#define MAXCONTENT 256
-#define PARAGRAPH_BOX_WIDTH 256
-#define PARAGRAPH_BOX_HEIGHT 128
+
enum {
T_TEXT = 0,
T_NUMBER,
@@ -105,6 +106,8 @@
int dialog_width;
int dialog_height;
int dialog_padding;
+ int paragraph_height;
+ int paragraph_width;
int emoji_enabled;
int emoji_speed;
int emoji_frame_delay;
@@ -264,20 +267,22 @@
void (*callback)(void);
};
-Config config;
-Sheet sheet;
Image *colors[6];
Image *boxbg;
Image *boxselected;
Image *boxediting;
Image *gridcolor;
+Config config;
+Sheet sheet;
-void parse_paragraph(Box*);
-void eval_paragraph(Box*);
-void draw_box_paragraph(Box*, Image*);
+void load_spr(char *file);
+void save_spr(char *file);
+void redraw(void);
+void recalc_all(void);
void load_config(char *path);
void save_config(char *path);
void apply_config(void);
+void parse_paragraph(Box*);
void parse_text(Box*);
void parse_number(Box*);
void parse_formula(Box*);
@@ -284,7 +289,7 @@
void eval_text(Box*);
void eval_number(Box*);
void eval_formula(Box*);
-void recalc_all(void);
+void eval_paragraph(Box*);
void handle_normal_mode(int key);
void handle_cell_edit(int key);
void handle_label_edit(int key);
@@ -294,6 +299,7 @@
void handle_label_mouse(Mouse m);
void handle_filename_mouse(Mouse m);
void draw_box_generic(Box*, Image*);
+void draw_box_paragraph(Box*, Image*);
void draw_normal_overlay(void);
void draw_cell_edit_overlay(void);
void draw_label_edit_overlay(void);
@@ -360,33 +366,33 @@
{"dialog_width", CFG_INT, &config.dialog_width, 0, nil},
{"dialog_height", CFG_INT, &config.dialog_height, 0, nil},
{"dialog_padding", CFG_INT, &config.dialog_padding, 0, nil},
+ {"paragraph_height", CFG_INT, &config.paragraph_height, 0, nil},
+ {"paragraph_width", CFG_INT, &config.paragraph_width, 0, nil},
+ {"emoji_enabled", CFG_BOOL, &config.emoji_enabled, 0, nil},
+ {"emoji_speed", CFG_INT, &config.emoji_speed, 0, nil},
+ {"emoji_frame_delay", CFG_INT, &config.emoji_frame_delay, 0, nil},
+ {"ctl_check_interval", CFG_INT, &config.ctl_check_interval, 0, nil},
+ {"redraw_interval", CFG_INT, &config.redraw_interval, 0, nil},
- {"emoji_enabled", CFG_BOOL, &config.emoji_enabled, 0, nil},
- {"emoji_speed", CFG_INT, &config.emoji_speed, 0, nil},
- {"emoji_frame_delay", CFG_INT, &config.emoji_frame_delay, 0, nil},
- {"ctl_check_interval", CFG_INT, &config.ctl_check_interval, 0, nil},
- {"redraw_interval", CFG_INT, &config.redraw_interval, 0, nil},
+ {"gridsize", CFG_INT, &config.gridsize, 0, nil},
+ {"gridsnap", CFG_BOOL, &config.gridsnap, 0, nil},
- {"gridsize", CFG_INT, &config.gridsize, 0, nil},
- {"gridsnap", CFG_BOOL, &config.gridsnap, 0, nil},
+ {"max_eval_depth", CFG_INT, &config.max_eval_depth, 0, nil},
+ {"max_recalc_passes", CFG_INT, &config.max_recalc_passes, 0, nil},
+ {"formula_precision", CFG_INT, &config.formula_precision, 0, update_formula_format},
+ {"show_formula_indicator", CFG_BOOL, &config.show_formula_indicator, 0, nil},
- {"max_eval_depth", CFG_INT, &config.max_eval_depth, 0, nil},
- {"max_recalc_passes", CFG_INT, &config.max_recalc_passes, 0, nil},
- {"formula_precision", CFG_INT, &config.formula_precision, 0, update_formula_format},
- {"show_formula_indicator", CFG_BOOL, &config.show_formula_indicator, 0, nil},
-
- {"ctl_file", CFG_STRING, config.ctl_file, 256, nil},
- {"default_save", CFG_STRING, config.default_save_path, 256, nil},
- {"color_bg", CFG_COLOR, &config.color_bg, 0, nil},
- {"color_fg", CFG_COLOR, &config.color_fg, 0, nil},
- {"color_box_bg", CFG_COLOR, &config.color_box_bg, 0, nil},
- {"color_selected", CFG_COLOR, &config.color_selected, 0, nil},
- {"color_editing", CFG_COLOR, &config.color_editing, 0, nil},
- {"color_grid", CFG_COLOR, &config.color_grid, 0, nil},
- {"color_label", CFG_COLOR, &config.color_label, 0, nil},
- {"color_formula", CFG_COLOR, &config.color_formula, 0, nil},
-
- {nil, 0, nil, 0, nil}
+ {"ctl_file", CFG_STRING, config.ctl_file, 256, nil},
+ {"default_save", CFG_STRING, config.default_save_path, 256, nil},
+ {"color_bg", CFG_COLOR, &config.color_bg, 0, nil},
+ {"color_fg", CFG_COLOR, &config.color_fg, 0, nil},
+ {"color_box_bg", CFG_COLOR, &config.color_box_bg, 0, nil},
+ {"color_selected", CFG_COLOR, &config.color_selected, 0, nil},
+ {"color_editing", CFG_COLOR, &config.color_editing, 0, nil},
+ {"color_grid", CFG_COLOR, &config.color_grid, 0, nil},
+ {"color_label", CFG_COLOR, &config.color_label, 0, nil},
+ {"color_formula", CFG_COLOR, &config.color_formula, 0, nil},
+ {nil, 0, nil, 0, nil} /* sentinel */
};
BoxType boxtypes[] = {
@@ -513,6 +519,120 @@
};
void
+save_spr(char *file)
+{
+ int fd;
+ Biobuf *b;
+ int i;
+ Box *box;
+
+ fd = create(file, OWRITE, 0644);
+ if(fd < 0){
+ fprint(2, "cannot create %s: %r\n", file);
+ return;
+ }
+
+ b = Bfdopen(fd, OWRITE);
+
+ for(i = 0; i < sheet.nboxes; i++){
+ box = &sheet.boxes[i];
+ Bprint(b, "box %d\n", i);
+ Bprint(b, " pos %d %d\n", box->pos.x, box->pos.y);
+ Bprint(b, " type %d\n", box->type);
+ Bprint(b, " formula %s\n", box->formula);
+ Bprint(b, " value %g\n", box->value);
+ Bprint(b, " label %s\n", box->label);
+
+ if(box->nrefs > 0){
+ Bprint(b, " refs");
+ int j;
+ for(j = 0; j < box->nrefs; j++)
+ Bprint(b, " %d", box->refs[j]);
+ Bprint(b, "\n");
+ }
+ }
+
+ Bterm(b);
+ close(fd);
+}
+
+void
+load_spr(char *file)
+{
+ Biobuf *b;
+ char *line;
+ char *fields[10];
+ int nf;
+
+ b = Bopen(file, OREAD);
+ if(b == nil){
+ fprint(2, "cannot open %s: %r\n", file);
+ return;
+ }
+
+ memset(&sheet, 0, sizeof(sheet));
+ sheet.selected = -1;
+ sheet.editing = -1;
+ sheet.editing_label = -1;
+ sheet.entering_filename = 0;
+ sheet.current_mode = 0;
+ sheet.gridsize = config.gridsize;
+ sheet.gridsnap = config.gridsnap;
+ init_emoji();
+
+ while((line = Brdline(b, '\n')) != nil){
+ line[Blinelen(b)-1] = '\0';
+
+ if(line[0] == '#' || line[0] == '\0')
+ continue;
+
+ nf = tokenize(line, fields, nelem(fields));
+
+ if(nf >= 2 && strcmp(fields[0], "box") == 0){
+ if(sheet.nboxes < MAXBOXES){
+ Box *box = &sheet.boxes[sheet.nboxes];
+ memset(box, 0, sizeof(Box));
+ box->r = Rect(0, 0, BOXWIDTH, BOXHEIGHT);
+ sheet.nboxes++;
+ }
+ } else if(nf >= 3 && strcmp(fields[0], "pos") == 0){
+ Box *box = &sheet.boxes[sheet.nboxes-1];
+ box->pos.x = atoi(fields[1]);
+ box->pos.y = atoi(fields[2]);
+ box->r = Rect(box->pos.x, box->pos.y,
+ box->pos.x + BOXWIDTH, box->pos.y + BOXHEIGHT);
+ } else if(nf >= 2 && strcmp(fields[0], "type") == 0){
+ int type = atoi(fields[1]);
+ if (type >= 0 && type < MAXBOXTYPES) {
+ sheet.boxes[sheet.nboxes-1].type = type;
+ } else {
+ sheet.boxes[sheet.nboxes-1].type = T_TEXT;
+ }
+ } else if(nf >= 2 && strcmp(fields[0], "formula") == 0){
+ strcpy(sheet.boxes[sheet.nboxes-1].formula, fields[1]);
+ } else if(nf >= 2 && strcmp(fields[0], "value") == 0){
+ sheet.boxes[sheet.nboxes-1].value = atof(fields[1]);
+ } else if(nf >= 2 && strcmp(fields[0], "label") == 0){
+ strncpy(sheet.boxes[sheet.nboxes-1].label, fields[1], 31);
+ }
+ }
+
+ Bterm(b);
+
+ int i;
+ for(i = 0; i < sheet.nboxes; i++){
+ Box *box = &sheet.boxes[i];
+ if (box->type >= 0 && box->type < MAXBOXTYPES) {
+ BoxType *bt = &boxtypes[box->type];
+ if (bt->parse) bt->parse(box);
+ if (bt->eval) bt->eval(box);
+ }
+ }
+ recalc_all();
+ redraw();
+}
+
+void
save_config(char *path)
{
int fd;
@@ -530,7 +650,6 @@
Bprint(b, "# Generated automatically - edit to customize\n");
Bprint(b, "# Reload with 'r' key while running\n\n");
- Bprint(b, "# Visual Settings\n");
Bprint(b, "banner_height %d\n", config.banner_height);
Bprint(b, "status_height %d\n", config.status_height);
Bprint(b, "box_label_offset_y %d\n", config.box_label_offset_y);
@@ -537,12 +656,12 @@
Bprint(b, "box_text_margin %d\n", config.box_text_margin);
Bprint(b, "formula_indicator_offset %d\n", config.formula_indicator_offset);
- Bprint(b, "\n# Dialog Settings\n");
Bprint(b, "dialog_width %d\n", config.dialog_width);
Bprint(b, "dialog_height %d\n", config.dialog_height);
Bprint(b, "dialog_padding %d\n", config.dialog_padding);
+ Bprint(b, "paragraph_height %d\n", config.paragraph_height);
+ Bprint(b, "paragraph_width %d\n", config.paragraph_width);
- Bprint(b, "\n# Animation Settings\n");
Bprint(b, "emoji_enabled %d\n", config.emoji_enabled);
Bprint(b, "emoji_speed %d\n", config.emoji_speed);
Bprint(b, "emoji_frame_delay %d\n", config.emoji_frame_delay);
@@ -549,21 +668,17 @@
Bprint(b, "ctl_check_interval %d\n", config.ctl_check_interval);
Bprint(b, "redraw_interval %d\n", config.redraw_interval);
- Bprint(b, "\n# Grid Settings\n");
Bprint(b, "gridsize %d\n", config.gridsize);
Bprint(b, "gridsnap %d\n", config.gridsnap);
- Bprint(b, "\n# Behavior Settings\n");
Bprint(b, "max_eval_depth %d\n", config.max_eval_depth);
Bprint(b, "max_recalc_passes %d\n", config.max_recalc_passes);
Bprint(b, "formula_precision %d\n", config.formula_precision);
Bprint(b, "show_formula_indicator %d\n", config.show_formula_indicator);
- Bprint(b, "\n# Paths\n");
Bprint(b, "ctl_file %s\n", config.ctl_file);
Bprint(b, "default_save %s\n", config.default_save_path);
- Bprint(b, "\n# Colors (RGBA hex)\n");
Bprint(b, "color_bg %08lux\n", config.color_bg);
Bprint(b, "color_fg %08lux\n", config.color_fg);
Bprint(b, "color_box_bg %08lux\n", config.color_box_bg);
@@ -590,6 +705,8 @@
config.dialog_width = DEFAULT_DIALOG_WIDTH;
config.dialog_height = DEFAULT_DIALOG_HEIGHT;
config.dialog_padding = DEFAULT_DIALOG_PADDING;
+ config.paragraph_height = DEFAULT_PARAGRAPH_H;
+ config.paragraph_width = DEFAULT_PARAGRAPH_W;
config.emoji_enabled = 1;
config.emoji_speed = DEFAULT_EMOJI_SPEED;
@@ -2028,7 +2145,7 @@
} else if(sheet.editbuf[0] == '"') {
b->type = T_PARAGRAPH;
/* Add this line to resize the box */
- b->r = Rect(b->pos.x, b->pos.y, b->pos.x + PARAGRAPH_BOX_WIDTH, b->pos.y + PARAGRAPH_BOX_HEIGHT);
+ b->r = Rect(b->pos.x, b->pos.y, b->pos.x + config.paragraph_width, b->pos.y + config.paragraph_height);
} else {
char *endp;
strtod(sheet.editbuf, &endp);
@@ -2090,120 +2207,6 @@
}
void
-save(char *file)
-{
- int fd;
- Biobuf *b;
- int i;
- Box *box;
-
- fd = create(file, OWRITE, 0644);
- if(fd < 0){
- fprint(2, "cannot create %s: %r\n", file);
- return;
- }
-
- b = Bfdopen(fd, OWRITE);
-
- for(i = 0; i < sheet.nboxes; i++){
- box = &sheet.boxes[i];
- Bprint(b, "box %d\n", i);
- Bprint(b, " pos %d %d\n", box->pos.x, box->pos.y);
- Bprint(b, " type %d\n", box->type);
- Bprint(b, " formula %s\n", box->formula);
- Bprint(b, " value %g\n", box->value);
- Bprint(b, " label %s\n", box->label);
-
- if(box->nrefs > 0){
- Bprint(b, " refs");
- int j;
- for(j = 0; j < box->nrefs; j++)
- Bprint(b, " %d", box->refs[j]);
- Bprint(b, "\n");
- }
- }
-
- Bterm(b);
- close(fd);
-}
-
-void
-load(char *file)
-{
- Biobuf *b;
- char *line;
- char *fields[10];
- int nf;
-
- b = Bopen(file, OREAD);
- if(b == nil){
- fprint(2, "cannot open %s: %r\n", file);
- return;
- }
-
- memset(&sheet, 0, sizeof(sheet));
- sheet.selected = -1;
- sheet.editing = -1;
- sheet.editing_label = -1;
- sheet.entering_filename = 0;
- sheet.current_mode = 0;
- sheet.gridsize = config.gridsize;
- sheet.gridsnap = config.gridsnap;
- init_emoji();
-
- while((line = Brdline(b, '\n')) != nil){
- line[Blinelen(b)-1] = '\0';
-
- if(line[0] == '#' || line[0] == '\0')
- continue;
-
- nf = tokenize(line, fields, nelem(fields));
-
- if(nf >= 2 && strcmp(fields[0], "box") == 0){
- if(sheet.nboxes < MAXBOXES){
- Box *box = &sheet.boxes[sheet.nboxes];
- memset(box, 0, sizeof(Box));
- box->r = Rect(0, 0, BOXWIDTH, BOXHEIGHT);
- sheet.nboxes++;
- }
- } else if(nf >= 3 && strcmp(fields[0], "pos") == 0){
- Box *box = &sheet.boxes[sheet.nboxes-1];
- box->pos.x = atoi(fields[1]);
- box->pos.y = atoi(fields[2]);
- box->r = Rect(box->pos.x, box->pos.y,
- box->pos.x + BOXWIDTH, box->pos.y + BOXHEIGHT);
- } else if(nf >= 2 && strcmp(fields[0], "type") == 0){
- int type = atoi(fields[1]);
- if (type >= 0 && type < MAXBOXTYPES) {
- sheet.boxes[sheet.nboxes-1].type = type;
- } else {
- sheet.boxes[sheet.nboxes-1].type = T_TEXT;
- }
- } else if(nf >= 2 && strcmp(fields[0], "formula") == 0){
- strcpy(sheet.boxes[sheet.nboxes-1].formula, fields[1]);
- } else if(nf >= 2 && strcmp(fields[0], "value") == 0){
- sheet.boxes[sheet.nboxes-1].value = atof(fields[1]);
- } else if(nf >= 2 && strcmp(fields[0], "label") == 0){
- strncpy(sheet.boxes[sheet.nboxes-1].label, fields[1], 31);
- }
- }
-
- Bterm(b);
-
- int i;
- for(i = 0; i < sheet.nboxes; i++){
- Box *box = &sheet.boxes[i];
- if (box->type >= 0 && box->type < MAXBOXTYPES) {
- BoxType *bt = &boxtypes[box->type];
- if (bt->parse) bt->parse(box);
- if (bt->eval) bt->eval(box);
- }
- }
- recalc_all();
- redraw();
-}
-
-void
handle_filename_input(int key)
{
if(key == '\n') {
@@ -2212,9 +2215,9 @@
}
if(sheet.save_mode == 1) {
- save(sheet.filenamebuf);
+ save_spr(sheet.filenamebuf);
} else {
- load(sheet.filenamebuf);
+ load_spr(sheet.filenamebuf);
recalc_all();
}
@@ -2373,7 +2376,7 @@
ctl_load(char **args, int nargs)
{
if(nargs >= 1) {
- load(args[0]);
+ load_spr(args[0]);
recalc_all();
sheet.needredraw = 1;
}
@@ -2383,7 +2386,7 @@
ctl_save(char **args, int nargs)
{
if(nargs >= 1) {
- save(args[0]);
+ save_spr(args[0]);
}
}
@@ -2536,6 +2539,7 @@
line_start++;
}
}
+
void
eresized(int new)
{
--
⑨