From 289338b12304ca650bba165956a0ea522932da25 Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 3 Oct 2026 10:05:15 -0700 Subject: [PATCH] fix: text box focus --- src/main.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 9933c23..a9cae6e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #define RAYGUI_IMPLEMENTATION #include @@ -10,7 +11,7 @@ #define OVERLAY_HEIGHT 400 #define OVERLAY_WIDTH 700 -bool edit_mode = true; +#define NUM_WEEKS 6 void switch_mode(Mode mode) { set_mode(mode); @@ -27,19 +28,75 @@ void switch_mode(Mode mode) { } } +typedef struct cell_t { + int row; + int column; +} Cell; + +int cell_number(Cell c) { + return (c.row + 1) * (c.column + 1); +} + +int distance(Cell a, Cell b) { + return cell_number(b) - cell_number(a); +} + +#define CELL_SPACING 10 +#define CELL_SIZE 20 +time_t now; +struct tm *local_time; + +void draw_graph(int x, int y) { + int num_columns = NUM_WEEKS; + int num_rows = 7; // days in a week + bool checked = false; + + int cell_number_today = cell_number((Cell) {local_time->tm_wday, num_columns - 1}); + + for (int c = 0; c < num_columns; c++) { + for (int r = 0; r < num_rows; r++) { + Cell cell = { r, c }; + int curr_cell_number = cell_number(cell); + if (curr_cell_number > cell_number_today) break; + + // 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_y = CELL_SPACING + (((CELL_SPACING * 2) + CELL_SIZE) * c); + if (GuiCheckBox((Rectangle) {cell_x + x, cell_y + y, CELL_SIZE, CELL_SIZE}, "", &checked)) { + printf("checked row %d | column %d\n", r, c); + } + } + } +} + +bool edit_mode = false; + void render_window() { ClearBackground(RAYWHITE); DrawFPS(WINDOW_WIDTH - 50, 10); - const Rectangle text_rect = {(WINDOW_WIDTH / 2) - 200, WINDOW_HEIGHT / 2, 400, 50}; - if (GuiTextBox(text_rect, get_intention(), get_intention_size(), &edit_mode)) { + Rectangle text_box_rect = {(WINDOW_WIDTH / 2) - 200, (WINDOW_HEIGHT / 2) - 200, 400, 50}; + Vector2 mouse_pos = GetMousePosition(); + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { + if (CheckCollisionRecs((Rectangle) {mouse_pos.x, mouse_pos.y, 2, 2}, text_box_rect)) { + + edit_mode = true; + } else { + edit_mode = false; + } + } + if (GuiTextBox(text_box_rect, get_intention(), get_intention_size(), edit_mode)) { switch_mode(OVERLAY); } + // GuiLabelButton(); + char label[2048]; 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) + 50, 300, 50}, label); - + GuiLabel((Rectangle){ WINDOW_WIDTH / 2 - 100, (WINDOW_HEIGHT / 2) - 150, 300, 50}, label); + + int graph_y_offset = (WINDOW_HEIGHT / 2) + 50; + draw_graph(100, graph_y_offset); } void render_overlay() { @@ -61,6 +118,10 @@ void render_overlay() { } int main(int argc, char *argv[]) { + time(&now); + local_time = localtime(&now); + mktime(local_time); + init_window_state(); printf("Welcome to Flowy.adhd\n");