improve graph with tooltips, row header, and color

This commit is contained in:
2026-10-03 10:36:32 -07:00
parent 289338b123
commit fcd28c49a9
+40 -13
View File
@@ -7,11 +7,11 @@
#include "window_state.h" #include "window_state.h"
#define WINDOW_HEIGHT 700 #define WINDOW_HEIGHT 700
#define WINDOW_WIDTH 500 #define WINDOW_WIDTH 550
#define OVERLAY_HEIGHT 400 #define OVERLAY_HEIGHT 400
#define OVERLAY_WIDTH 700 #define OVERLAY_WIDTH 700
#define NUM_WEEKS 6 #define NUM_WEEKS 12
void switch_mode(Mode mode) { void switch_mode(Mode mode) {
set_mode(mode); set_mode(mode);
@@ -44,14 +44,26 @@ int distance(Cell a, Cell b) {
#define CELL_SPACING 10 #define CELL_SPACING 10
#define CELL_SIZE 20 #define CELL_SIZE 20
time_t now; time_t now;
struct tm *local_time; struct tm local_time;
void get_date_days_ago(int days_ago, char *buffer, size_t buffer_size) {
time_t raw_time;
struct tm *time_info;
time(&raw_time);
time_info = localtime(&raw_time); // caution: localtime() overwrites the static struct internally as opposed to localtime_r
time_info->tm_mday -= days_ago;
mktime(time_info);
strftime(buffer, buffer_size, "%B %d", time_info);
}
void draw_graph(int x, int y) { void draw_graph(int x, int y) {
int num_columns = NUM_WEEKS; int num_columns = NUM_WEEKS;
int num_rows = 7; // days in a week int num_rows = 7; // days in a week
bool checked = false; bool checked = false;
int cell_number_today = cell_number((Cell) {local_time->tm_wday, num_columns - 1}); int cell_number_today = cell_number((Cell) {local_time.tm_wday, num_columns - 1});
for (int c = 0; c < num_columns; c++) { for (int c = 0; c < num_columns; c++) {
for (int r = 0; r < num_rows; r++) { for (int r = 0; r < num_rows; r++) {
@@ -59,11 +71,26 @@ void draw_graph(int x, int y) {
int curr_cell_number = cell_number(cell); int curr_cell_number = cell_number(cell);
if (curr_cell_number > cell_number_today) break; if (curr_cell_number > cell_number_today) break;
int days_ago = cell_number_today - curr_cell_number;
char tooltip_text[128];
get_date_days_ago(days_ago, tooltip_text, sizeof(tooltip_text));
GuiSetTooltip(tooltip_text);
// full size of a cell is spacing * 2 + size, and then need to go little more // full size of a cell is spacing * 2 + size, and then need to go little more
int cell_x = CELL_SPACING + (((CELL_SPACING * 2) + CELL_SIZE) * r); int cell_x = CELL_SPACING + (((CELL_SPACING * 2) + CELL_SIZE) * c);
int cell_y = CELL_SPACING + (((CELL_SPACING * 2) + CELL_SIZE) * c); int cell_y = CELL_SPACING + (((CELL_SPACING * 2) + CELL_SIZE) * r);
if (GuiCheckBox((Rectangle) {cell_x + x, cell_y + y, CELL_SIZE, CELL_SIZE}, "", &checked)) {
printf("checked row %d | column %d\n", r, c); GuiSetStyle(BUTTON, BASE_COLOR_NORMAL, ColorToInt(GREEN));
if (GuiButton((Rectangle) {cell_x + x, cell_y + y, CELL_SIZE, CELL_SIZE}, " ")) {
printf("clicked row %d | column %d\n", r, c);
}
if (c == 0 && r == 1) {
GuiLabel((Rectangle) {x-5, cell_y + y, 20, 20}, "M");
} else if (c==0 && r== 3) {
GuiLabel((Rectangle) {x-5, cell_y + y, 20, 20}, "W");
} else if (c==0 && r == 5) {
GuiLabel((Rectangle) {x-5, cell_y + y, 20, 20}, "F");
} }
} }
} }
@@ -89,14 +116,12 @@ void render_window() {
switch_mode(OVERLAY); switch_mode(OVERLAY);
} }
// GuiLabelButton();
char label[2048]; char label[2048];
sprintf(label, "%d / %d characters | Hit enter to set", (int) strlen(get_intention()), (int) get_intention_size()); sprintf(label, "%d / %d characters | Hit enter to set", (int) strlen(get_intention()), (int) get_intention_size());
GuiLabel((Rectangle){ WINDOW_WIDTH / 2 - 100, (WINDOW_HEIGHT / 2) - 150, 300, 50}, label); GuiLabel((Rectangle){ WINDOW_WIDTH / 2 - 100, (WINDOW_HEIGHT / 2) - 150, 300, 50}, label);
int graph_y_offset = (WINDOW_HEIGHT / 2) + 50; int graph_y_offset = (WINDOW_HEIGHT / 2) + 50;
draw_graph(100, graph_y_offset); draw_graph(20, graph_y_offset);
} }
void render_overlay() { void render_overlay() {
@@ -119,14 +144,16 @@ void render_overlay() {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
time(&now); time(&now);
local_time = localtime(&now); localtime_r(&now, &local_time);
mktime(local_time); mktime(&local_time);
init_window_state(); init_window_state();
printf("Welcome to Flowy.adhd\n"); printf("Welcome to Flowy.adhd\n");
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd"); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd");
GuiEnableTooltip();
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
BeginDrawing(); BeginDrawing();