feat: simple overlay and window modes with intention setting

This commit is contained in:
2026-10-02 12:37:25 -07:00
parent 078dab3ffa
commit 1f3b2686ef
9 changed files with 174 additions and 13 deletions
+48 -4
View File
@@ -1,34 +1,78 @@
#include <stdio.h>
#define RAYGUI_IMPLEMENTATION
#include <raygui.h>
#include <raylib.h>
#include "window_state.h"
#define WINDOW_HEIGHT 700
#define WINDOW_WIDTH 500
#define OVERLAY_HEIGHT 300
#define OVERLAY_WIDTH 700
bool edit_mode = true;
void switch_mode(Mode mode) {
set_mode(mode);
switch (mode) {
case WINDOW:
SetWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
break;
case OVERLAY:
SetWindowSize(OVERLAY_WIDTH, OVERLAY_HEIGHT);
break;
default:
break;
}
}
void render_window() {
ClearBackground(RAYWHITE);
DrawFPS(WINDOW_WIDTH - 50, 10);
// draw a button for toggle mode
const Rectangle text_rect = {(WINDOW_WIDTH / 2) - 200, WINDOW_HEIGHT / 2, 400, 50};
if (GuiTextBox(text_rect, get_intention(), get_intention_size(), &edit_mode)) {
switch_mode(OVERLAY);
}
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);
}
void render_overlay() {
ClearBackground(BLANK);
DrawFPS(OVERLAY_WIDTH - 50, 10);
// draw a button to toggle mode
const Rectangle button_rect = {OVERLAY_WIDTH - 100, 10, 100, 25};
int active = 0;
if (GuiToggleSlider(button_rect, "Toggle mode", &active)) {
switch_mode(WINDOW);
}
GuiSetStyle(DEFAULT, TEXT_SIZE, 100);
GuiSetStyle(LABEL, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
GuiLabel((Rectangle){0, (OVERLAY_HEIGHT / 2), OVERLAY_WIDTH, 50}, get_intention());
}
int main(int argc, char *argv[]) {
init_window_state();
printf("Welcome to Flowy.adhd\n");
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Flowy.adhd");
while (!WindowShouldClose()) {
BeginDrawing();
render_window();
GuiSetStyle(DEFAULT, TEXT_SIZE, 15);
if (get_mode() == WINDOW) render_window();
else render_overlay();
EndDrawing();
}
+54
View File
@@ -0,0 +1,54 @@
#include "window_state.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
struct state *s = NULL;
#define INTENTION_MAX_SIZE 2048
struct state {
Mode mode;
char intention[INTENTION_MAX_SIZE];
};
void init_window_state() {
s = malloc(sizeof(struct state));
s->mode = WINDOW;
memset(s->intention, 0, sizeof(s->intention));
}
void cleanup_window_state() {
if (!s) {
return;
}
free(s);
s = NULL;
}
void set_intention(char *intention) {
assert(s);
strncpy(s->intention, intention, sizeof(s->intention));
s->intention[sizeof(s->intention) - 1] = '\0';
}
char *get_intention() {
assert(s);
return s->intention;
}
size_t get_intention_size() {
assert(s);
return sizeof(s->intention);
}
Mode get_mode() {
assert(s);
return s->mode;
}
void set_mode(Mode new_mode) {
s->mode = new_mode;
}