fix: text box focus
This commit is contained in:
+66
-5
@@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include <raygui.h>
|
#include <raygui.h>
|
||||||
@@ -10,7 +11,7 @@
|
|||||||
#define OVERLAY_HEIGHT 400
|
#define OVERLAY_HEIGHT 400
|
||||||
#define OVERLAY_WIDTH 700
|
#define OVERLAY_WIDTH 700
|
||||||
|
|
||||||
bool edit_mode = true;
|
#define NUM_WEEKS 6
|
||||||
|
|
||||||
void switch_mode(Mode mode) {
|
void switch_mode(Mode mode) {
|
||||||
set_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() {
|
void render_window() {
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
DrawFPS(WINDOW_WIDTH - 50, 10);
|
DrawFPS(WINDOW_WIDTH - 50, 10);
|
||||||
|
|
||||||
const Rectangle text_rect = {(WINDOW_WIDTH / 2) - 200, WINDOW_HEIGHT / 2, 400, 50};
|
Rectangle text_box_rect = {(WINDOW_WIDTH / 2) - 200, (WINDOW_HEIGHT / 2) - 200, 400, 50};
|
||||||
if (GuiTextBox(text_rect, get_intention(), get_intention_size(), &edit_mode)) {
|
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);
|
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) + 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() {
|
void render_overlay() {
|
||||||
@@ -61,6 +118,10 @@ void render_overlay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
time(&now);
|
||||||
|
local_time = localtime(&now);
|
||||||
|
mktime(local_time);
|
||||||
|
|
||||||
init_window_state();
|
init_window_state();
|
||||||
|
|
||||||
printf("Welcome to Flowy.adhd\n");
|
printf("Welcome to Flowy.adhd\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user