From de7324fc90265d9bcce2d66b647ae6c3e4e8c9e2 Mon Sep 17 00:00:00 2001 From: igor Date: Sun, 15 Feb 2026 11:28:36 -0800 Subject: [PATCH] Cleaned up the activity button a bit and renamed some things. --- main.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index bbbf26e..c8692f4 100644 --- a/main.c +++ b/main.c @@ -92,7 +92,7 @@ char my_button(int x, int y, int width, int height, int font_size, char *title) } #endif -char activity_button(int x, int y, int width, int height, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color) +char activity_button(Rectangle rect, char *title, char *subtitle, F32 font_size, Color font_color, Color background_color) { char button_pressed = 0; @@ -103,8 +103,6 @@ char activity_button(int x, int y, int width, int height, char *title, char *sub Vector2 title_font_d = MeasureTextEx(state.font, title, (float)font_size, 2); Vector2 subtitle_font_d = MeasureTextEx(state.font, subtitle, (float)subtitle_font_size, 2); - Rectangle rect = { x, y, width, height }; - if(CheckCollisionPointRec(state.mouse_pos, rect)) { if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) button_pressed = 1; @@ -148,12 +146,12 @@ Color activity_type_color_representation[activity_type_COUNT] = { // TODO: String representation. -typedef struct Activity { - activity_type activity; // TODO: Rename to kind or type. +typedef struct activity { + activity_type type; // TODO: Rename to kind or type. Color color; U64 began; U64 ended; -} Activity; +} activity; typedef struct Activity_Stat { U64 total_seconds; @@ -180,7 +178,7 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; - Activity activities[100]; + activity activities[100]; U32 current_activity = 0; Activity_Stat activities_stats[activity_type_COUNT]; @@ -261,7 +259,7 @@ int main(int argc, char *argv[]) else continue; - activities[current_activity].activity = type; + activities[current_activity].type = type; activities[current_activity].color = activity_type_color_representation[type]; activities[current_activity].began = lower; activities[current_activity].ended = upper; @@ -300,7 +298,7 @@ int main(int argc, char *argv[]) GenTextureMipmaps(&state.font.texture); SetTextureFilter(state.font.texture, TEXTURE_FILTER_BILINEAR); - activities[current_activity].activity = other; + activities[current_activity].type = other; activities[current_activity].color = RED; activities[current_activity].began = now(); activities[current_activity].ended = lower_bound_s; @@ -347,32 +345,33 @@ int main(int argc, char *argv[]) F32 width = (window_w-padding_x*6.0f) / 5.0f; for(U32 i = 0; i <= current_activity; i++) { - activities_stats[activities[i].activity].total_seconds += activities[i].ended - activities[i].began; + activities_stats[activities[i].type].total_seconds += activities[i].ended - activities[i].began; } for(U32 i = 0; i < activity_type_COUNT; i ++) { Hours time = break_time(activities_stats[i].total_seconds); snprintf(activities_stats[i].seconds_str, sizeof(activities_stats[i].seconds_str), "%02llu:%02llu:%02llu", time.hours, time.minutes, time.seconds); - if(activity_button((padding_x*(i+1))+(width*i), 60, width, (window_h-70), activity_type_string_representation[i], activities_stats[i].seconds_str, font_size, (activities[current_activity].activity == i ? WHITE : BLACK), activity_type_color_representation[i])) { - if(activities[current_activity].activity != i) { + Rectangle rect = { (padding_x*(i+1))+(width*i), 60, width, (window_h-70) }; + if(activity_button(rect, activity_type_string_representation[i], activities_stats[i].seconds_str, font_size, (activities[current_activity].type == i ? WHITE : BLACK), activity_type_color_representation[i])) { + if(activities[current_activity].type != i) { current_activity++; - activities[current_activity].activity = i; + activities[current_activity].type = i; activities[current_activity].color = activity_type_color_representation[i]; activities[current_activity].began = now_s; activities[current_activity].ended = now_s; } } - if(activities[current_activity].activity == i) - DrawRectangleRoundedLinesEx((Rectangle){ (padding_x*(i+1))+(width*i), 60, width, (window_h-70) }, 0.2f, 100, 5.0f, WHITE); + if(activities[current_activity].type == i) + DrawRectangleRoundedLinesEx(rect, 0.2f, 100, 5.0f, WHITE); } // DrawTextEx(state.font, "Hello, world! && How are you?", (Vector2){100, 400}, font_size, 2, BLUE); EndDrawing(); for(U32 i = 0; i <= current_activity; i++) { - activities_stats[activities[i].activity].total_seconds = 0; + activities_stats[activities[i].type].total_seconds = 0; } // Save the state every 5 seconds. @@ -383,7 +382,7 @@ int main(int argc, char *argv[]) for(U32 i = 0; i <= current_activity; i++) { snprintf(write_buffer, sizeof(write_buffer), "%s %llu %llu\n", - activity_type_string_representation[activities[i].activity], + activity_type_string_representation[activities[i].type], activities[i].began, activities[i].ended);