ref: 0fce054fb4b0866873f734ce5bdbc39d56ed5e5e
parent: 3eea9f16ffc138a7a5e728397b4e4cc2a7147508
author: glenda <glenda@krsna>
date: Wed Aug 20 11:41:14 EDT 2025
avoid-stacking
--- a/fc.c
+++ b/fc.c
@@ -6,8 +6,6 @@
#include <bio.h>
#include <ctype.h>
-/* Designed in acme and for acme dev */
-
#define CONFIG_FILE "/usr/glenda/fc/fc.conf"
#define DEFAULT_CTL_FILE "/usr/glenda/fc/fc.ctl"
#define DEFAULT_SAVE_PATH "/usr/glenda/fc/sheet.spr"
@@ -28,13 +26,13 @@
#define DEFAULT_MAX_RECALC_PASSES 10
#define DEFAULT_FORMULA_PRECISION 2
#define DEFAULT_PARAGRAPH_W 256
-#define DEFAULT_PARAGRAPH_H 256
+#define DEFAULT_PARAGRAPH_H 128
#define DEFAULT_BOXWIDTH 128
#define DEFAULT_BOXHEIGHT 32
-#define MAXFORMULA 256
-#define MAXCONTENT 300
-#define MAXBOXES 300
+#define MAXFORMULA 256
+#define MAXCONTENT 300
+#define MAXBOXES 300
enum {@@ -292,6 +290,8 @@
void eval_number(Box*);
void eval_formula(Box*);
void eval_paragraph(Box*);
+void handlekey(int key);
+void handlemouse(Mouse m);
void handle_normal_mode(int key);
void handle_cell_edit(int key);
void handle_label_edit(int key);
@@ -328,8 +328,10 @@
void ctl_quit(char**, int);
void init_emoji(void);
void initcolors(void);
+void init_config_defaults(void);
void update_formula_format(void);
void validate_config(void);
+int box_would_overlap(Point pos);
int cistrcmp(char *s1, char *s2);
int tokenize_formula(char *formula, Token *tokens, int maxtokens);
int cellref_lookup(char *ref);
@@ -362,6 +364,7 @@
ConfigField config_fields[] = { {"banner_height", CFG_INT, &config.banner_height, 0, nil}, {"status_height", CFG_INT, &config.status_height, 0, nil},+ {"status_margin", CFG_INT, &config.status_margin, 0, nil}, {"box_label_offset_y", CFG_INT, &config.box_label_offset_y, 0, nil}, {"box_text_margin", CFG_INT, &config.box_text_margin, 0, nil}, {"formula_indicator_offset", CFG_INT, &config.formula_indicator_offset, 0, nil},@@ -377,8 +380,8 @@
{"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}, {"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},@@ -450,7 +453,7 @@
handle_filename_input,
handle_filename_mouse,
draw_filename_overlay,
- "Tab:.spr Enter:confirm Esc:cancel"
+ "Tab:/usr/glenda/fc/ Enter:confirm Esc:cancel"
},
};
@@ -936,8 +939,8 @@
sheet.editing_label = -1;
sheet.entering_filename = 0;
sheet.current_mode = 0;
- sheet.gridsize = config.gridsize;
sheet.gridsnap = config.gridsnap;
+ sheet.gridsize = config.gridsize;
init_emoji();
while((line = Brdline(b, '\n')) != nil){@@ -1048,6 +1051,7 @@
Bprint(b, "# auto-gen fc.conf $\n");
Bprint(b, "banner_height %d\n", config.banner_height);
Bprint(b, "status_height %d\n", config.status_height);
+ Bprint(b, "status_margin %d\n", config.status_margin);
Bprint(b, "box_label_offset_y %d\n", config.box_label_offset_y);
Bprint(b, "box_text_margin %d\n", config.box_text_margin);
Bprint(b, "formula_indicator_offset %d\n", config.formula_indicator_offset);
@@ -1063,8 +1067,8 @@
Bprint(b, "emoji_frame_delay %d\n", config.emoji_frame_delay);
Bprint(b, "ctl_check_interval %d\n", config.ctl_check_interval);
Bprint(b, "redraw_interval %d\n", config.redraw_interval);
- Bprint(b, "gridsize %d\n", config.gridsize);
Bprint(b, "gridsnap %d\n", config.gridsnap);
+ Bprint(b, "gridsize %d\n", config.gridsize);
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);
@@ -1277,8 +1281,8 @@
apply_config(void)
{sheet.emoji_enabled = config.emoji_enabled;
- sheet.gridsize = config.gridsize;
sheet.gridsnap = config.gridsnap;
+ sheet.gridsize = config.gridsize;
if(colors[0]) {freeimage(colors[0]);
@@ -2961,51 +2965,73 @@
}
}
+int
+box_would_overlap(Point pos)
+{+ Rectangle new_rect = Rect(pos.x, pos.y,
+ pos.x + config.box_width,
+ pos.y + config.box_height);
+
+ for(int i = 0; i < sheet.nboxes; i++) {+ if(rectXrect(new_rect, sheet.boxes[i].r)) {+ return 1; // Overlap detected
+ }
+ }
+ return 0; // No overlap
+}
+
void
handle_normal_mouse(Mouse m)
{- int i;
-
- if(m.buttons & 1){- i = boxat(m.xy);
- if(i >= 0){- sheet.selected = i;
-
- while(m.buttons & 1){- sheet.boxes[i].pos = subpt(m.xy, Pt(config.box_width/2, config.box_height/2));
- if(sheet.gridsnap){- sheet.boxes[i].pos.x = (sheet.boxes[i].pos.x / sheet.gridsize) * sheet.gridsize;
- sheet.boxes[i].pos.y = (sheet.boxes[i].pos.y / sheet.gridsize) * sheet.gridsize;
- }
- sheet.boxes[i].r = Rect(sheet.boxes[i].pos.x, sheet.boxes[i].pos.y,
- sheet.boxes[i].pos.x + config.box_width, sheet.boxes[i].pos.y + config.box_height);
- redraw();
- m = emouse();
- }
- } else {- i = addbox(m.xy);
- if(i >= 0){- sheet.selected = i;
- sheet.editing = i;
- sheet.current_mode = 1;
- sheet.editbuf[0] = '\0';
- sheet.editpos = 0;
- }
- }
- sheet.needredraw = 1;
- }
-
- if(m.buttons & 2){- i = boxat(m.xy);
- if(i >= 0){- sheet.selected = i;
- sheet.editing = i;
- sheet.current_mode = 1;
- strcpy(sheet.editbuf, sheet.boxes[i].formula);
- sheet.editpos = strlen(sheet.editbuf);
- sheet.needredraw = 1;
- }
- }
+ int i;
+ if(m.buttons & 1){+ i = boxat(m.xy);
+ if(i >= 0){+ // Found a box - drag it
+ sheet.selected = i;
+ while(m.buttons & 1){+ sheet.boxes[i].pos = subpt(m.xy, Pt(config.box_width/2, config.box_height/2));
+ if(sheet.gridsnap){+ sheet.boxes[i].pos.x = (sheet.boxes[i].pos.x / sheet.gridsize) * sheet.gridsize;
+ sheet.boxes[i].pos.y = (sheet.boxes[i].pos.y / sheet.gridsize) * sheet.gridsize;
+ }
+ sheet.boxes[i].r = Rect(sheet.boxes[i].pos.x, sheet.boxes[i].pos.y,
+ sheet.boxes[i].pos.x + config.box_width, sheet.boxes[i].pos.y + config.box_height);
+ redraw();
+ m = emouse();
+ }
+ } else {+ Point new_pos = m.xy;
+ if(sheet.gridsnap){+ new_pos.x = (new_pos.x / sheet.gridsize) * sheet.gridsize;
+ new_pos.y = (new_pos.y / sheet.gridsize) * sheet.gridsize;
+ }
+
+ if(!box_would_overlap(new_pos)){+ i = addbox(new_pos);
+ if(i >= 0){+ sheet.selected = i;
+ sheet.editing = i;
+ sheet.current_mode = 1;
+ sheet.editbuf[0] = '\0';
+ sheet.editpos = 0;
+ }
+ }
+ }
+ sheet.needredraw = 1;
+ }
+
+ if(m.buttons & 2){+ i = boxat(m.xy);
+ if(i >= 0){+ sheet.selected = i;
+ sheet.editing = i;
+ sheet.current_mode = 1;
+ strcpy(sheet.editbuf, sheet.boxes[i].formula);
+ sheet.editpos = strlen(sheet.editbuf);
+ sheet.needredraw = 1;
+ }
+ }
}
void
--
⑨