comparison postdog/main.c @ 155:3bb45eb67906

[Postdog] Updated variables names and padding sizes. Needs more work.
author June Park <parkjune1995@gmail.com>
date Mon, 12 Jan 2026 09:12:31 -0800
parents 790930d9bb90
children 05cf9467a1c3
comparison
equal deleted inserted replaced
154:bdcc610eeed8 155:3bb45eb67906
72 HistoryItem *history_items = NULL; 72 HistoryItem *history_items = NULL;
73 HistoryItem *new_history_items = NULL; 73 HistoryItem *new_history_items = NULL;
74 74
75 // Global UI state 75 // Global UI state
76 char *url_input_text = NULL; 76 char *url_input_text = NULL;
77 char *url_result_text = NULL; 77 char *result_text = NULL;
78 char **url_body_map = NULL; 78 char **input_body_array = NULL;
79 int active_method_dropdown = 0; 79 int active_method_dropdown = 0;
80 int active_input_tab = 0; 80 int active_input_tab = 0;
81 Seobeo_WebSocket *ws = NULL; 81 Seobeo_WebSocket *ws = NULL;
82 boolean WS_BREAK = FALSE; 82 boolean WS_BREAK = FALSE;
83 Color TEXT_COLOR = BLACK;
83 84
84 int CompareHistoryItemsByDate(const void *a, const void *b) { 85 int CompareHistoryItemsByDate(const void *a, const void *b) {
85 HistoryItem *itemA = (HistoryItem *)a; 86 HistoryItem *itemA = (HistoryItem *)a;
86 HistoryItem *itemB = (HistoryItem *)b; 87 HistoryItem *itemB = (HistoryItem *)b;
87 return (itemB->time_modified - itemA->time_modified); 88 return (itemB->time_modified - itemA->time_modified);
246 "---\n" 247 "---\n"
247 "%s\n", 248 "%s\n",
248 title, 249 title,
249 url_input_text, 250 url_input_text,
250 method, 251 method,
251 url_body_map[TAB_HEADER], 252 input_body_array[TAB_HEADER],
252 url_body_map[TAB_BODY], 253 input_body_array[TAB_BODY],
253 url_body_map[TAB_GET_PARAMS], 254 input_body_array[TAB_GET_PARAMS],
254 url_body_map[TAB_WEBSOCKET], 255 input_body_array[TAB_WEBSOCKET],
255 url_result_text 256 result_text
256 ); 257 );
257 char *filename = Dowa_Arena_Allocate(arena, 1024); 258 char *filename = Dowa_Arena_Allocate(arena, 1024);
258 if (!filename) 259 if (!filename)
259 { 260 {
260 perror("Error opening file"); 261 perror("Error opening file");
285 { 286 {
286 if (!ws) 287 if (!ws)
287 ws = Seobeo_WebSocket_Connect(url_input_text); 288 ws = Seobeo_WebSocket_Connect(url_input_text);
288 289
289 printf("URL %s\n", url_input_text); 290 printf("URL %s\n", url_input_text);
290 if (Seobeo_WebSocket_Send_Text(ws, url_body_map[active_input_tab]) < 0) 291 if (Seobeo_WebSocket_Send_Text(ws, input_body_array[active_input_tab]) < 0)
291 printf("Failed to send message\n"); 292 printf("Failed to send message\n");
292 293
293 printf("Receiving responses...\n"); 294 printf("Receiving responses...\n");
294 int received = 0; 295 int received = 0;
295 while (TRUE) 296 while (TRUE)
300 if (p_msg) 301 if (p_msg)
301 { 302 {
302 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT) 303 if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT)
303 { 304 {
304 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data); 305 printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data);
305 snprintf(url_result_text + strlen(url_result_text), RESULT_BUFFER_LENGTH - strlen(url_result_text), 306 snprintf(result_text + strlen(result_text), RESULT_BUFFER_LENGTH - strlen(result_text),
306 "\n%s", (char*)p_msg->data); 307 "\n%s", (char*)p_msg->data);
307 received++; 308 received++;
308 } 309 }
309 Seobeo_WebSocket_Message_Destroy(p_msg); 310 Seobeo_WebSocket_Message_Destroy(p_msg);
310 } 311 }
360 break; 361 break;
361 } 362 }
362 } 363 }
363 364
364 { 365 {
365 if (url_body_map[TAB_HEADER] && strlen(url_body_map[TAB_HEADER]) > 0) 366 if (input_body_array[TAB_HEADER] && strlen(input_body_array[TAB_HEADER]) > 0)
366 { 367 {
367 char *headersCopy = strdup(url_body_map[TAB_HEADER]); 368 char *headersCopy = strdup(input_body_array[TAB_HEADER]);
368 char *line = strtok(headersCopy, "\n"); 369 char *line = strtok(headersCopy, "\n");
369 while (line != NULL) 370 while (line != NULL)
370 { 371 {
371 while (*line == ' ' || *line == '\t') line++; 372 while (*line == ' ' || *line == '\t') line++;
372 if (strlen(line) > 0) 373 if (strlen(line) > 0)
377 } 378 }
378 Seobeo_Client_Request_Set_Follow_Redirects(req, TRUE, 5); // TODO: remove magic number; 379 Seobeo_Client_Request_Set_Follow_Redirects(req, TRUE, 5); // TODO: remove magic number;
379 res = Seobeo_Client_Request_Execute(req); 380 res = Seobeo_Client_Request_Execute(req);
380 381
381 if (res == NULL) 382 if (res == NULL)
382 snprintf(url_result_text, RESULT_BUFFER_LENGTH, "Error: Failed to send the request\n"); 383 snprintf(result_text, RESULT_BUFFER_LENGTH, "Error: Failed to send the request\n");
383 else 384 else
384 snprintf(url_result_text, RESULT_BUFFER_LENGTH, "HTTP Status: %d\n\n%s", 385 snprintf(result_text, RESULT_BUFFER_LENGTH, "HTTP Status: %d\n\n%s",
385 res->status_code, res->body ? res->body : ""); 386 res->status_code, res->body ? res->body : "");
386 } 387 }
387 Seobeo_Client_Request_Destroy(req); 388 Seobeo_Client_Request_Destroy(req);
388 Seobeo_Client_Response_Destroy(res); 389 Seobeo_Client_Response_Destroy(res);
389 PostDog_Request_SaveFile(); 390 PostDog_Request_SaveFile();
395 // Save existing query string if present 396 // Save existing query string if present
396 char *question_mark = strchr(url_input_text, '?'); 397 char *question_mark = strchr(url_input_text, '?');
397 if (question_mark) 398 if (question_mark)
398 *question_mark = '\0'; 399 *question_mark = '\0';
399 400
400 int get_params_length = (int)strlen(url_body_map[TAB_GET_PARAMS]); 401 int get_params_length = (int)strlen(input_body_array[TAB_GET_PARAMS]);
401 if (get_params_length == 0) 402 if (get_params_length == 0)
402 return; 403 return;
403 404
404 char *separator = "?"; 405 char *separator = "?";
405 406
406 Dowa_Arena *arena = Dowa_Arena_Create(1024*1024); 407 Dowa_Arena *arena = Dowa_Arena_Create(1024*1024);
407 char **lines = Dowa_String_Split(url_body_map[TAB_GET_PARAMS], "\n", get_params_length, 1, arena); 408 char **lines = Dowa_String_Split(input_body_array[TAB_GET_PARAMS], "\n", get_params_length, 1, arena);
408 for (int i = 0; i < Dowa_Array_Length(lines); i++) 409 for (int i = 0; i < Dowa_Array_Length(lines); i++)
409 { 410 {
410 char *line = lines[i]; 411 char *line = lines[i];
411 char **key_value = Dowa_String_Split(line, " ", (int)strlen(line), 1, arena); 412 char **key_value = Dowa_String_Split(line, " ", (int)strlen(line), 1, arena);
412 413
443 } 444 }
444 445
445 void PostDog_Params_Reset(void) 446 void PostDog_Params_Reset(void)
446 { 447 {
447 url_input_text[0] = '\0'; 448 url_input_text[0] = '\0';
448 url_result_text[0] = '\0'; 449 result_text[0] = '\0';
449 active_method_dropdown = 0; 450 active_method_dropdown = 0;
450 for (int i = 0; i < Dowa_Array_Length(url_body_map); i++) 451 for (int i = 0; i < Dowa_Array_Length(input_body_array); i++)
451 url_body_map[i][0] = '\0'; 452 input_body_array[i][0] = '\0';
452 } 453 }
453 454
454 void PostDog_Load_File(const char *filename) 455 void PostDog_Load_File(const char *filename)
455 { 456 {
456 char full_file_path[512] = {0}; 457 char full_file_path[512] = {0};
488 break; 489 break;
489 490
490 case 3: // Headers (TAB_HEADER) 491 case 3: // Headers (TAB_HEADER)
491 case 4: // Body (TAB_BODY) 492 case 4: // Body (TAB_BODY)
492 case 5: // Get Params (TAB_GET_PARAMS) 493 case 5: // Get Params (TAB_GET_PARAMS)
493 case 6: // Bar (TAB_WEBSOCKET) 494 case 6: // Websocket (TAB_WEBSOCKET)
494 { 495 {
495 int map_index = i - 3; // 3->0, 4->1, 5->2, 6->3 496 int map_index = i - 3; // 3->0, 4->1, 5->2, 6->3
496 snprintf(url_body_map[map_index], strlen(values[i]) + 1, "%s", values[i]); 497 snprintf(input_body_array[map_index], strlen(values[i]) + 1, "%s", values[i]);
497 // Trim trailing newlines 498 // Trim trailing newlines
498 for (int j = strlen(values[i]); j > 0; j--) 499 for (int j = strlen(values[i]); j > 0; j--)
499 { 500 {
500 if (url_body_map[map_index][j] == '\n') 501 if (input_body_array[map_index][j] == '\n')
501 { 502 {
502 url_body_map[map_index][j] = '\0'; 503 input_body_array[map_index][j] = '\0';
503 break; 504 break;
504 } 505 }
505 } 506 }
506 break; 507 break;
507 } 508 }
508 509
509 default: // Response (index 7+) 510 default: // Response (index 7+)
510 snprintf(url_result_text, strlen(values[i]) + 1, "%s", values[i]); 511 snprintf(result_text, strlen(values[i]) + 1, "%s", values[i]);
511 break; 512 break;
512 } 513 }
513 } 514 }
514 515
515 Dowa_Arena_Free(init_arena); 516 Dowa_Arena_Free(init_arena);
523 rect.y + padding, 524 rect.y + padding,
524 rect.width - (2 * padding), 525 rect.width - (2 * padding),
525 rect.height - (2 * padding) 526 rect.height - (2 * padding)
526 }; 527 };
527 } 528 }
529
530 Rectangle AddPaddingAll(Rectangle rect, float top, float right,float down, float left)
531 {
532 return (Rectangle){
533 rect.x + left,
534 rect.y + top,
535 rect.width - (right + left),
536 rect.height - (top + down),
537 };
538 }
539
540
528 541
529 Rectangle AddPaddingHorizontal(Rectangle rect, float padding) 542 Rectangle AddPaddingHorizontal(Rectangle rect, float padding)
530 { 543 {
531 return (Rectangle){ 544 return (Rectangle){
532 rect.x + padding, 545 rect.x + padding,
612 SetWindowIcon(logo_original); 625 SetWindowIcon(logo_original);
613 Texture2D logo_texture = LoadTextureFromImage(logo_original); 626 Texture2D logo_texture = LoadTextureFromImage(logo_original);
614 UnloadImage(logo_original); 627 UnloadImage(logo_original);
615 628
616 // -- Starting pos ---// 629 // -- Starting pos ---//
617 Rectangle history_sidebar = { 0 }; 630 Rectangle history_sidebar_rect = { 0 };
618 Dowa_Array_Reserve(history_items, 10); 631 Dowa_Array_Reserve(history_items, 10);
619 Dowa_Array_Reserve(new_history_items, 10); 632 Dowa_Array_Reserve(new_history_items, 10);
620 PostDog_History_Load(&history_items); 633 PostDog_History_Load(&history_items);
621 int32 *history_deleted_items = NULL; 634 int32 *history_deleted_items = NULL;
622 635
623 Rectangle url_area = { 0 }; 636 Rectangle url_area_rect = { 0 };
624 Rectangle textBounds = { 0 }; 637 Rectangle url_input_bounds_rect = { 0 };
625 Rectangle url_input_bounds = { 0 };
626 bool url_input_edit = false; 638 bool url_input_edit = false;
627 Rectangle url_text_bounds = { 0 }; 639 Rectangle url_text_bounds_rect = { 0 };
628 Rectangle url_enter_button = { 0 }; 640 Rectangle url_enter_button_rect = { 0 };
629 Rectangle method_dropdown = { 0 }; 641 Rectangle method_dropdown_rect = { 0 };
630 642
631 643
632 // Initialize global UI state 644 // Initialize global UI state
633 url_input_text = (char *)malloc(sizeof(char) * URL_TEXT_BUFFER_LENGTH); 645 url_input_text = (char *)malloc(sizeof(char) * URL_TEXT_BUFFER_LENGTH);
634 snprintf(url_input_text, URL_TEXT_BUFFER_LENGTH, "wss://mrjunejune.com/echo"); 646 snprintf(url_input_text, URL_TEXT_BUFFER_LENGTH, "wss://mrjunejune.com/echo");
635 647
636 Dowa_Array_Push(url_body_map, (char *)malloc(sizeof(char) * HEADER_BUFFER_LENGTH)); 648 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * HEADER_BUFFER_LENGTH));
637 Dowa_Array_Push(url_body_map, (char *)malloc(sizeof(char) * BODY_BUFFER_LENGTH)); 649 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * BODY_BUFFER_LENGTH));
638 Dowa_Array_Push(url_body_map, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH)); 650 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH));
639 Dowa_Array_Push(url_body_map, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH)); 651 Dowa_Array_Push(input_body_array, (char *)malloc(sizeof(char) * DEFAULT_TEXT_BUFFER_LENGTH));
640 652
641 snprintf(url_body_map[TAB_HEADER], HEADER_BUFFER_LENGTH, "Content-Type: application/json"); 653 snprintf(input_body_array[TAB_HEADER], HEADER_BUFFER_LENGTH, "Content-Type: application/json");
642 snprintf(url_body_map[TAB_BODY], HEADER_BUFFER_LENGTH, ""); 654 snprintf(input_body_array[TAB_BODY], HEADER_BUFFER_LENGTH, "");
643 655
644 url_result_text = (char *)malloc(sizeof(char) * RESULT_BUFFER_LENGTH); 656 result_text = (char *)malloc(sizeof(char) * RESULT_BUFFER_LENGTH);
645 657
646 bool method_edit = false; 658 bool method_edit = false;
647 659
648 int sendRequest; 660 int sendRequest;
649 661
650 // -- input --// 662 // -- input --//
651 Rectangle input_area = { 0 }; 663 Rectangle input_area_rect = { 0 };
652 Rectangle input_tab = { 0 }; 664 Rectangle input_tab_rect = { 0 };
653 Rectangle input_tab_item = { 0 }; 665 Rectangle input_tab_item_rect = { 0 };
654 Rectangle input_body = { 0 }; 666 Rectangle input_body_rect = { 0 };
655 bool input_body_bool = false; 667 bool input_body_bool = false;
656 668
657 // -- result --// 669 // -- result --//
658 Rectangle result_area = { 0 }; 670 Rectangle result_area_rect = { 0 };
659 Rectangle result_body = { 0 }; 671 Rectangle result_body_rect = { 0 };
660 672
661 // General styling. 673 // General styling.
662 float padding = 10; // TODO make it % based? 674 float padding = 10; // TODO make it % based?
663 int prev_input_tab = 0; 675 int prev_input_tab = 0;
664 676
676 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) + 1); 688 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) + 1);
677 689
678 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyDown(KEY_MINUS)) 690 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyDown(KEY_MINUS))
679 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) - 1); 691 GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetStyle(DEFAULT, TEXT_SIZE) - 1);
680 692
681 Rectangle screen = { 0, 0, screen_width, screen_height }; 693 Rectangle screen_rect = { 0, 0, screen_width, screen_height };
682 694
683 // -- Side bar --// 695 // -- Side bar --//
684 history_sidebar = LeftColumn(screen, 0.15, padding); 696 history_sidebar_rect = LeftColumn(screen_rect, 0.15, padding);
685 Rectangle content_area = RightColumn(screen, history_sidebar, padding); 697 Rectangle content_area_rect = RightColumn(screen_rect, history_sidebar_rect, padding);
686 Rectangle logo_area = (Rectangle){ 698 Rectangle logo_area_rect = (Rectangle){
687 .x = history_sidebar.x, 699 .x = history_sidebar_rect.x,
688 .y = history_sidebar.y, 700 .y = history_sidebar_rect.y,
689 .width = history_sidebar.width, 701 .width = history_sidebar_rect.width,
690 .height = 80 702 .height = 80
691 }; 703 };
692 704
693 Rectangle history_list_area = Below(logo_area, padding); 705 Rectangle history_list_area_rect = Below(logo_area_rect, padding);
694 history_list_area.width = history_sidebar.width; 706 history_list_area_rect.x += padding;
695 history_list_area.height = history_sidebar.height - logo_area.height - padding; 707 history_list_area_rect.width = history_sidebar_rect.width - (2 * padding);
708 history_list_area_rect.height = history_sidebar_rect.height - logo_area_rect.height - padding;
696 709
697 int32 new_history_items_length = Dowa_Array_Length(new_history_items); 710 int32 new_history_items_length = Dowa_Array_Length(new_history_items);
698 int32 history_item_length = Dowa_Array_Length(history_items); 711 int32 history_item_length = Dowa_Array_Length(history_items);
699 int32 total = new_history_items_length + history_item_length; 712 int32 total = new_history_items_length + history_item_length;
700 float item_height = history_list_area.height * 0.10; 713 float item_height = history_list_area_rect.height * 0.10;
701 714
702 int32 number_of_skipped_items = 0; 715 int32 number_of_skipped_items = 0;
703 for (int i = 0; i < total; i++) 716 for (int i = 0; i < total; i++)
704 { 717 {
705 HistoryItem *curr_history_items = i < new_history_items_length ? 718 HistoryItem *curr_history_items = i < new_history_items_length ?
710 number_of_skipped_items++; 723 number_of_skipped_items++;
711 continue; 724 continue;
712 } 725 }
713 726
714 curr_history_items->rect = (Rectangle){ 727 curr_history_items->rect = (Rectangle){
715 .x = history_list_area.x, 728 .x = history_list_area_rect.x,
716 .y = history_list_area.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset, 729 .y = history_list_area_rect.y + (padding + item_height) * (i - number_of_skipped_items) + history_scroll_offset,
717 .width = history_list_area.width, 730 .width = history_list_area_rect.width,
718 .height = item_height 731 .height = item_height
719 }; 732 };
720 } 733 }
721 734
722 // --- URL --- // 735 // --- URL --- //
723 url_area = (Rectangle){ 736 url_area_rect = (Rectangle){
724 .x = content_area.x, 737 .x = content_area_rect.x,
725 .y = content_area.y, 738 .y = content_area_rect.y,
726 .width = content_area.width, 739 .width = content_area_rect.width,
727 .height = content_area.height * 0.1 740 .height = content_area_rect.height * 0.1
728 }; 741 };
729 742
730 float url_control_y = url_area.y + (url_area.height - TEXT_SIZE * 2) / 2; 743 float url_control_y = url_area_rect.y + (url_area_rect.height - TEXT_SIZE * 2) / 2;
731 744
732 url_text_bounds = (Rectangle){ 745 url_text_bounds_rect = (Rectangle){
733 .x = url_area.x + padding, 746 .x = url_area_rect.x + padding,
734 .y = url_control_y, 747 .y = url_control_y,
735 .width = 7 * (TEXT_SIZE / 2), 748 .width = 7 * (TEXT_SIZE / 2),
736 .height = TEXT_SIZE * 2 749 .height = TEXT_SIZE * 2
737 }; 750 };
738 751
739 url_input_bounds = RightOf(url_text_bounds, padding); 752 url_input_bounds_rect = RightOf(url_text_bounds_rect, padding);
740 url_input_bounds.width = url_area.width * 0.7; 753 url_input_bounds_rect.width = url_area_rect.width * 0.7;
741 url_input_bounds.height = TEXT_SIZE * 2; 754 url_input_bounds_rect.height = TEXT_SIZE * 2;
742 755
743 url_enter_button = RightOf(url_input_bounds, padding); 756 url_enter_button_rect = RightOf(url_input_bounds_rect, padding);
744 url_enter_button.width = url_area.width * 0.1; 757 url_enter_button_rect.width = url_area_rect.width * 0.1;
745 url_enter_button.height = TEXT_SIZE * 2; 758 url_enter_button_rect.height = TEXT_SIZE * 2;
746 759
747 method_dropdown = RightOf(url_enter_button, padding); 760 method_dropdown_rect = RightOf(url_enter_button_rect, padding);
748 method_dropdown.width = url_area.width * 0.1; 761 method_dropdown_rect.width = url_area_rect.width * 0.1;
749 method_dropdown.height = TEXT_SIZE * 2; 762 method_dropdown_rect.height = TEXT_SIZE * 2;
750 763
751 // -- Body -- // 764 // -- Body -- //
752 Rectangle body_area = Below(url_area, 0); 765 Rectangle body_area_rect = Below(url_area_rect, 0);
753 body_area.height = content_area.height - url_area.height; 766 body_area_rect.height = content_area_rect.height - url_area_rect.height;
754 767
755 input_area = HorizontalSplit(body_area, 0.5); 768 input_area_rect = HorizontalSplit(body_area_rect, 0.5);
756 result_area = RightOf(input_area, 0); 769 result_area_rect = RightOf(input_area_rect, 0);
757 result_area.width = body_area.width - input_area.width; 770 result_area_rect.width = body_area_rect.width - input_area_rect.width;
758 771
759 input_tab = (Rectangle){ 772 input_tab_rect = (Rectangle){
760 .x = input_area.x + padding, 773 .x = input_area_rect.x + padding,
761 .y = input_area.y + padding, 774 .y = input_area_rect.y + padding,
762 .width = input_area.width - (2 * padding), 775 .width = input_area_rect.width - (2 * padding),
763 .height = input_area.height * 0.1 776 .height = input_area_rect.height * 0.1
764 }; 777 };
765 778
766 input_tab_item = input_tab; 779 input_tab_item_rect = input_tab_rect;
767 input_tab_item.width = input_tab.width / 4; 780 input_tab_item_rect.width = input_tab_rect.width / 4;
768 781
769 input_body = Below(input_tab, 0); 782 input_body_rect = Below(input_tab_rect, 0);
770 input_body.width = input_tab.width; 783 input_body_rect.width = input_tab_rect.width;
771 input_body.height = input_area.height - input_tab.height - (2 * padding); 784 input_body_rect.height = input_area_rect.height - input_tab_rect.height - (2 * padding);
772 785
773 // -- Result -- / 786 // -- Result -- /
774 result_body = (Rectangle){ 787 result_body_rect = (Rectangle){
775 .x = result_area.x + padding, 788 .x = result_area_rect.x + padding,
776 .y = input_body.y, 789 .y = input_body_rect.y,
777 .width = result_area.width - (2 * padding), 790 .width = result_area_rect.width - (2 * padding),
778 .height = input_body.height 791 .height = input_body_rect.height
779 }; 792 };
780 793
781 Vector2 mouse_position = GetMousePosition(); 794 Vector2 mouse_position = GetMousePosition();
782 float mouse_wheel = GetMouseWheelMove(); 795 float mouse_wheel = GetMouseWheelMove();
783 796
787 input_body_scroll_offset = 0; 800 input_body_scroll_offset = 0;
788 prev_input_tab = active_input_tab; 801 prev_input_tab = active_input_tab;
789 } 802 }
790 803
791 // Handle scroll wheel for history 804 // Handle scroll wheel for history
792 if (InArea(mouse_position, history_list_area) && mouse_wheel != 0) { 805 if (InArea(mouse_position, history_list_area_rect) && mouse_wheel != 0) {
793 history_scroll_offset += mouse_wheel * 30; // 30 pixels per wheel tick 806 history_scroll_offset += mouse_wheel * 30; // 30 pixels per wheel tick
794 // Clamp scroll offset 807 // Clamp scroll offset
795 float max_scroll = (total * (item_height + padding)) - history_list_area.height; 808 float max_scroll = (total * (item_height + padding)) - history_list_area_rect.height;
796 if (history_scroll_offset > 0) history_scroll_offset = 0; 809 if (history_scroll_offset > 0) history_scroll_offset = 0;
797 if (history_scroll_offset < -max_scroll && max_scroll > 0) history_scroll_offset = -max_scroll; 810 if (history_scroll_offset < -max_scroll && max_scroll > 0) history_scroll_offset = -max_scroll;
798 } 811 }
799 812
800 // Handle scroll wheel for input body 813 // Handle scroll wheel for input body
801 if (InArea(mouse_position, input_body) && mouse_wheel != 0) { 814 if (InArea(mouse_position, input_body_rect) && mouse_wheel != 0) {
802 input_body_scroll_offset += mouse_wheel * 30; 815 input_body_scroll_offset += mouse_wheel * 30;
803 if (input_body_scroll_offset > 0) input_body_scroll_offset = 0; 816 if (input_body_scroll_offset > 0) input_body_scroll_offset = 0;
804 } 817 }
805 818
806 // Handle scroll wheel for result body 819 // Handle scroll wheel for result body
807 if (InArea(mouse_position, result_body) && mouse_wheel != 0) { 820 if (InArea(mouse_position, result_body_rect) && mouse_wheel != 0) {
808 result_body_scroll_offset += mouse_wheel * 30; 821 result_body_scroll_offset += mouse_wheel * 30;
809 if (result_body_scroll_offset > 0) result_body_scroll_offset = 0; 822 if (result_body_scroll_offset > 0) result_body_scroll_offset = 0;
810 } 823 }
811 824
812 BeginDrawing(); 825 BeginDrawing();
813 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); 826 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
814 827
815 DrawRectangleRec(history_sidebar, Fade(GRAY, 0.1f)); 828 // DrawRectangleRec(history_sidebar_rect, Fade(GRAY, 0.1f));
816 829 DrawRectangleRounded(history_sidebar_rect, 0.5, 1, Fade(BLUE, 0.1f));
817 // DrawRectangleRec(logo_area, Fade(BLUE, 0.2f)); 830
818 Rectangle logo_image_rect = AddPadding(logo_area, padding); 831 // DrawRectangleRec(logo_area_rect, Fade(BLUE, 0.2f));
832 Rectangle logo_image_rect = AddPadding(logo_area_rect, padding);
819 // Fit logo to area while maintaining aspect ratio 833 // Fit logo to area while maintaining aspect ratio
820 float logo_size = logo_image_rect.height < logo_image_rect.width ? logo_image_rect.height : logo_image_rect.width; 834 float logo_size = logo_image_rect.height < logo_image_rect.width ? logo_image_rect.height : logo_image_rect.width;
821 Rectangle dest = { 835 Rectangle dest_rect = {
822 .x = logo_image_rect.x + (logo_image_rect.width - logo_size) / 2, // Center horizontally 836 .x = logo_image_rect.x + (logo_image_rect.width - logo_size) / 2, // Center horizontally
823 .y = logo_image_rect.y, 837 .y = logo_image_rect.y,
824 .width = logo_size, 838 .width = logo_size,
825 .height = logo_size 839 .height = logo_size
826 }; 840 };
827 841
828 Rectangle source = { 0, 0, logo_texture.width, logo_texture.height }; 842 Rectangle source_rect = { 0, 0, logo_texture.width, logo_texture.height };
829 DrawTexturePro(logo_texture, source, dest, (Vector2){0, 0}, 0.0f, WHITE); 843 DrawTexturePro(logo_texture, source_rect, dest_rect, (Vector2){0, 0}, 0.0f, WHITE);
830 844
831 BeginScissorMode(history_list_area.x, history_list_area.y, history_list_area.width, history_list_area.height); 845 BeginScissorMode(history_list_area_rect.x, history_list_area_rect.y, history_list_area_rect.width, history_list_area_rect.height);
832 for (int i = 0; i < total; i++) 846 for (int i = 0; i < total; i++)
833 { 847 {
834 HistoryItem *curr_history_items = i < new_history_items_length ? 848 HistoryItem *curr_history_items = i < new_history_items_length ?
835 &new_history_items[i - new_history_items_length - 1] : &history_items[i - new_history_items_length]; 849 &new_history_items[i - new_history_items_length - 1] : &history_items[i - new_history_items_length];
836 850
837 if (curr_history_items->deleted) 851 if (curr_history_items->deleted)
838 continue; 852 continue;
839 853
840 float diff = curr_history_items->rect.height*0.3; 854 float diff = curr_history_items->rect.height*0.6;
841 // DrawRectangleRec(curr_history_items->rect, Fade(RED, 0.1f)); 855 DrawRectangleRounded(curr_history_items->rect, 0.5, 1, Fade(BLACK, 0.1f));
842 Rectangle filename_area = curr_history_items->rect; 856 Rectangle filename_area_rect = curr_history_items->rect;
843 857
844 filename_area.height -= diff; 858 filename_area_rect.height -= diff;
845 Rectangle icon_area = Below(filename_area, 0); 859 Rectangle icon_area = Below(filename_area_rect, 0);
846 icon_area.height = diff; 860 icon_area.height = diff;
847 861
848 DrawRectangleRec(filename_area, Fade(BLUE, 0.1f)); 862 // DrawRectangleRec(filename_area_rect, Fade(BLUE, 0.1f));
849 DrawRectangleRec(icon_area, Fade(YELLOW, 0.1f)); 863 // DrawRectangleRec(icon_area, Fade(YELLOW, 0.1f));
864 // DrawRectangleRec(AddPadding(filename_area_rect, 5), Fade(BLUE, 0.1f));
850 865
851 Rectangle icon_area_left_column = LeftColumn(icon_area, 0.5, 0); 866 Rectangle icon_area_left_column = LeftColumn(icon_area, 0.5, 0);
852 Rectangle icon_area_right_column = RightColumn(icon_area, icon_area_left_column, 0); 867 Rectangle icon_area_right_column = RightColumn(icon_area, icon_area_left_column, 0);
853 868
854 GuiDrawText(curr_history_items->title, AddPadding(filename_area, padding), TEXT_ALIGN_CENTER, RED); 869 GuiDrawText(curr_history_items->title, AddPaddingHorizontal(curr_history_items->rect, padding), TEXT_ALIGN_MIDDLE, BLACK);
855 if (GuiButton(AddPaddingHorizontal(icon_area_left_column, padding), "view")) 870 if (GuiButton(AddPadding(icon_area_left_column, padding), "view"))
856 PostDog_Load_File(curr_history_items->filename); 871 PostDog_Load_File(curr_history_items->filename);
857 if (GuiButton(AddPaddingHorizontal(icon_area_right_column,padding), "delete")) 872 if (GuiButton(AddPadding(icon_area_right_column, padding), "delete"))
858 { 873 {
859 if (!remove(PostDog_Construct_URL(curr_history_items->filename))) 874 if (!remove(PostDog_Construct_URL(curr_history_items->filename)))
860 curr_history_items->deleted = TRUE; 875 curr_history_items->deleted = TRUE;
861 else 876 else
862 fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename); 877 fprintf(stderr, "Wasn't able to delete file: %s \n", curr_history_items->filename);
865 EndScissorMode(); 880 EndScissorMode();
866 881
867 if (total > 0) 882 if (total > 0)
868 { 883 {
869 float content_height = total * (item_height + padding); 884 float content_height = total * (item_height + padding);
870 if (content_height > history_list_area.height) 885 if (content_height > history_list_area_rect.height)
871 { 886 {
872 float scrollbar_height = (history_list_area.height / content_height) * history_list_area.height; 887 float scrollbar_height = (history_list_area_rect.height / content_height) * history_list_area_rect.height;
873 float scrollbar_y = history_list_area.y - (history_scroll_offset / content_height) * history_list_area.height; 888 float scrollbar_y = history_list_area_rect.y - (history_scroll_offset / content_height) * history_list_area_rect.height;
874 Rectangle scrollbar = { 889 Rectangle scrollbar_rect = {
875 history_list_area.x + history_list_area.width - 5, 890 history_list_area_rect.x + history_list_area_rect.width - 5,
876 scrollbar_y, 891 scrollbar_y,
877 5, 892 5,
878 scrollbar_height 893 scrollbar_height
879 }; 894 };
880 DrawRectangleRec(scrollbar, Fade(WHITE, 0.5f)); 895 DrawRectangleRec(scrollbar_rect, Fade(WHITE, 0.5f));
881 } 896 }
882 } 897 }
883 898
884 // URL area Rect 899 // URL area Rect
885 GuiDrawText("URL: ", url_text_bounds, TEXT_ALIGN_CENTER, RED); 900 GuiDrawText("URL: ", url_text_bounds_rect, TEXT_ALIGN_CENTER, BLACK);
886 DrawRectangleRec(url_area, Fade(RED, 0.1f)); 901 DrawRectangleRec(url_area_rect, Fade(BLACK, 0.1f));
887 if (GuiTextBox(url_input_bounds, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit)) 902 if (GuiTextBox(url_input_bounds_rect, url_input_text, DEFAULT_TEXT_BUFFER_LENGTH, url_input_edit))
888 url_input_edit = !url_input_edit; 903 url_input_edit = !url_input_edit;
889 904
890 sendRequest = GuiButton(url_enter_button, "ENTER"); 905 sendRequest = GuiButton(url_enter_button_rect, "ENTER");
891 if (sendRequest) 906 if (sendRequest)
892 PostDog_Http_Request(); 907 PostDog_Http_Request();
893 if (GuiDropdownBox(method_dropdown, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit)) 908 if (GuiDropdownBox(method_dropdown_rect, "GET;POST;PUT;DELETE", &active_method_dropdown, method_edit))
894 method_edit = !method_edit; 909 method_edit = !method_edit;
895 910
896 // Input Tabs Rect 911 // Input Tabs Rect
897 DrawRectangleRec(input_area, Fade(BLUE, 0.1f)); 912 DrawRectangleRec(input_area_rect, Fade(BLUE, 0.1f));
898 DrawRectangleRec(input_tab, Fade(DARKBLUE, 0.1f)); 913 DrawRectangleRec(input_tab_rect, Fade(DARKBLUE, 0.1f));
899 GuiSetStyle(TOGGLE, GROUP_PADDING, 0); 914 GuiSetStyle(TOGGLE, GROUP_PADDING, 0);
900 GuiDrawRectangle(input_body, 1, GetColor(GuiGetStyle(TEXTBOX, BORDER)), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED))); 915 GuiDrawRectangle(input_body_rect, 1, GetColor(GuiGetStyle(TEXTBOX, BORDER)), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)));
901 916
902 BeginScissorMode(input_body.x, input_body.y, input_body.width, input_body.height); 917 BeginScissorMode(input_body_rect.x, input_body_rect.y, input_body_rect.width, input_body_rect.height);
903 Rectangle scrolled_input = AddPadding(input_body, padding * 2); 918 Rectangle scrolled_input_rect = AddPadding(input_body_rect, padding * 2);
904 scrolled_input.y += input_body_scroll_offset; 919 scrolled_input_rect.y += input_body_scroll_offset;
905 scrolled_input.height = MAX_SCROLL_HEIGHT; 920 scrolled_input_rect.height = MAX_SCROLL_HEIGHT;
906 if (active_input_tab != TAB_WEBSOCKET) 921 if (active_input_tab != TAB_WEBSOCKET)
907 { 922 {
908 WS_BREAK = TRUE; 923 WS_BREAK = TRUE;
909 if (JUNE_GuiTextBox(scrolled_input, url_body_map[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool)) 924 if (JUNE_GuiTextBox(scrolled_input_rect, input_body_array[active_input_tab], DEFAULT_TEXT_BUFFER_LENGTH, input_body_bool))
910 input_body_bool = !input_body_bool; 925 input_body_bool = !input_body_bool;
911 } 926 }
912 else 927 else
913 { 928 {
914 boolean temp = true; 929 boolean temp = true;
915 WS_BREAK = FALSE; 930 WS_BREAK = FALSE;
916 if (GuiTextInputBox( 931 if (GuiTextInputBox(
917 input_body, 932 input_body_rect,
918 "send message", ws != NULL ? "connected" : "start messaging", 933 "send message", ws != NULL ? "connected" : "start messaging",
919 "send", url_body_map[active_input_tab], BODY_BUFFER_LENGTH, &temp) == 1) 934 "send", input_body_array[active_input_tab], BODY_BUFFER_LENGTH, &temp) == 1)
920 PostDog_Websocket_Thread_Send(); 935 PostDog_Websocket_Thread_Send();
921 } 936 }
922 EndScissorMode(); 937 EndScissorMode();
923 938
924 if (input_body_scroll_offset < 0) { 939 if (input_body_scroll_offset < 0) {
925 float scrollbar_height = 10; 940 float scrollbar_height = 10;
926 float scrollbar_y = input_body.y - (input_body_scroll_offset / MAX_SCROLL_HEIGHT) * (input_body.height - scrollbar_height); 941 float scrollbar_y = input_body_rect.y - (input_body_scroll_offset / MAX_SCROLL_HEIGHT) * (input_body_rect.height - scrollbar_height);
927 Rectangle scrollbar = { 942 Rectangle scrollbar_rect = {
928 input_body.x + input_body.width - 5, 943 input_body_rect.x + input_body_rect.width - 5,
929 scrollbar_y, 944 scrollbar_y,
930 5, 945 5,
931 scrollbar_height 946 scrollbar_height
932 }; 947 };
933 DrawRectangleRec(scrollbar, Fade(BLUE, 0.5f)); 948 DrawRectangleRec(scrollbar_rect, Fade(BLUE, 0.5f));
934 } 949 }
935 950
936 GuiToggleGroup(input_tab_item, "Header;Body;Get Param;Bar", &active_input_tab); 951 GuiToggleGroup(input_tab_item_rect, "Header;Body;Get Param;Websocket", &active_input_tab);
937 952
938 PostDog_Update_URL(); 953 PostDog_Update_URL();
939 954
940 // Result Rect 955 // Result Rect
941 DrawRectangleRec(result_area, Fade(GREEN, 0.1f)); 956 DrawRectangleRec(result_area_rect, Fade(GREEN, 0.1f));
942 DrawRectangleRec(result_body, Fade(DARKGREEN, 0.1f)); 957 DrawRectangleRec(result_body_rect, Fade(DARKGREEN, 0.1f));
943 958
944 // Create scrollable result body with offset 959 // Create scrollable result body with offset
945 BeginScissorMode(result_body.x, result_body.y, result_body.width, result_body.height); 960 BeginScissorMode(result_body_rect.x, result_body_rect.y, result_body_rect.width, result_body_rect.height);
946 Rectangle scrolled_result = result_body; 961 Rectangle scrolled_result = result_body_rect;
947 scrolled_result.y += result_body_scroll_offset; 962 scrolled_result.y += result_body_scroll_offset;
948 scrolled_result.height = MAX_SCROLL_HEIGHT; 963 scrolled_result.height = MAX_SCROLL_HEIGHT;
949 GuiTextBoxMulti(scrolled_result, url_result_text, RESULT_BUFFER_LENGTH, false); 964 GuiTextBoxMulti(scrolled_result, result_text, RESULT_BUFFER_LENGTH, false);
950 EndScissorMode(); 965 EndScissorMode();
951 966
952 if (result_body_scroll_offset < 0) 967 if (result_body_scroll_offset < 0)
953 { 968 {
954 float scrollbar_height = 10; 969 float scrollbar_height = 10;
955 float scrollbar_y = result_body.y - (result_body_scroll_offset / MAX_SCROLL_HEIGHT) * (result_body.height - scrollbar_height); 970 float scrollbar_y = result_body_rect.y - (result_body_scroll_offset / MAX_SCROLL_HEIGHT) * (result_body_rect.height - scrollbar_height);
956 Rectangle scrollbar = { 971 Rectangle scrollbar_rect = {
957 result_body.x + result_body.width - 5, 972 result_body_rect.x + result_body_rect.width - 5,
958 scrollbar_y, 973 scrollbar_y,
959 5, 974 5,
960 scrollbar_height 975 scrollbar_height
961 }; 976 };
962 DrawRectangleRec(scrollbar, Fade(GREEN, 0.5f)); 977 DrawRectangleRec(scrollbar_rect, Fade(GREEN, 0.5f));
963 } 978 }
964 979
965 if (url_input_edit && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) 980 if (url_input_edit && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
966 { 981 {
967 SetClipboardText(url_input_text); 982 SetClipboardText(url_input_text);
968 } 983 }
969 else if (input_body_bool && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) 984 else if (input_body_bool && (IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
970 { 985 {
971 SetClipboardText(url_body_map[active_input_tab]); 986 SetClipboardText(input_body_array[active_input_tab]);
972 } 987 }
973 else if (InArea(mouse_position, result_body)) 988 else if (InArea(mouse_position, result_body_rect))
974 { 989 {
975 DrawRectangleRec(result_body, Fade(GREEN, 0.3f)); 990 DrawRectangleRec(result_body_rect, Fade(GREEN, 0.3f));
976 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C)) 991 if ((IsKeyDown(KEY_LEFT_SUPER) || IsKeyDown(KEY_LEFT_CONTROL)) && IsKeyPressed(KEY_C))
977 SetClipboardText(url_result_text); 992 SetClipboardText(result_text);
978 } 993 }
979 EndDrawing(); 994 EndDrawing();
980 } 995 }
981 CloseWindow(); 996 CloseWindow();
982 return 0; 997 return 0;