comparison postdog/main.c @ 115:96db6c3f38d6

[Postdog] Got history working.
author June Park <parkjune1995@gmail.com>
date Tue, 06 Jan 2026 08:19:07 -0800
parents e2a73e64e8e6
children 7bd795bac997
comparison
equal deleted inserted replaced
114:e2a73e64e8e6 115:96db6c3f38d6
489 } 489 }
490 } 490 }
491 491
492 Rectangle AddPadding(Rectangle rect, float padding) 492 Rectangle AddPadding(Rectangle rect, float padding)
493 { 493 {
494 return (Rectangle){ 494 return (Rectangle){
495 rect.x + padding, 495 rect.x + padding,
496 rect.y + padding, 496 rect.y + padding,
497 rect.width - (2 * padding), 497 rect.width - (2 * padding),
498 rect.height - (2 * padding) 498 rect.height - (2 * padding)
499 };
500 }
501
502 // Layout helper functions
503 Rectangle RightOf(Rectangle ref, float padding)
504 {
505 return (Rectangle){
506 .x = ref.x + ref.width + padding,
507 .y = ref.y,
508 .width = 0,
509 .height = ref.height
510 };
511 }
512
513 Rectangle Below(Rectangle ref, float padding)
514 {
515 return (Rectangle){
516 .x = ref.x,
517 .y = ref.y + ref.height + padding,
518 .width = ref.width,
519 .height = 0
520 };
521 }
522
523 Rectangle LeftColumn(Rectangle container, float ratio, float padding)
524 {
525 return (Rectangle){
526 .x = container.x + padding,
527 .y = container.y + padding,
528 .width = (container.width * ratio) - padding,
529 .height = container.height - (2 * padding)
530 };
531 }
532
533 Rectangle RightColumn(Rectangle container, Rectangle leftCol, float padding)
534 {
535 return (Rectangle){
536 .x = leftCol.x + leftCol.width + padding,
537 .y = container.y + padding,
538 .width = container.width - leftCol.width - (3 * padding),
539 .height = container.height - (2 * padding)
540 };
541 }
542
543 Rectangle HorizontalSplit(Rectangle container, float ratio)
544 {
545 return (Rectangle){
546 .x = container.x,
547 .y = container.y,
548 .width = container.width * ratio,
549 .height = container.height
499 }; 550 };
500 } 551 }
501 552
502 int main() 553 int main()
503 { 554 {
567 while (!WindowShouldClose()) 618 while (!WindowShouldClose())
568 { 619 {
569 int screen_width = GetScreenWidth(); 620 int screen_width = GetScreenWidth();
570 int screen_height = GetScreenHeight(); 621 int screen_height = GetScreenHeight();
571 622
572 history_sidebar.width = screen_width * 0.15; 623 // Define main screen container
573 history_sidebar.height = screen_width - 10; 624 Rectangle screen = { 0, 0, screen_width, screen_height };
574 625
626 // Layout: Sidebar (left 15%) and Content Area (right 85%)
627 history_sidebar = LeftColumn(screen, 0.15, padding);
628 Rectangle content_area = RightColumn(screen, history_sidebar, padding);
629
630 // History items inside sidebar
575 int32 new_history_items_length = Dowa_Array_Length(new_history_items); 631 int32 new_history_items_length = Dowa_Array_Length(new_history_items);
576 int32 history_item_length = Dowa_Array_Length(history_items); 632 int32 history_item_length = Dowa_Array_Length(history_items);
577 int32 total = new_history_items_length + history_item_length; 633 int32 total = new_history_items_length + history_item_length;
634 float item_height = history_sidebar.height * 0.05;
635
578 for (int i = 0; i < total; i++) 636 for (int i = 0; i < total; i++)
579 { 637 {
580 HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length]; 638 HistoryItem *curr_history_items = i < new_history_items_length ?
581 curr_history_items->rect.x = history_sidebar.x + padding; 639 &new_history_items[i] : &history_items[i - new_history_items_length];
582 curr_history_items->rect.y = history_sidebar.y + (padding * 2 * (i+1)) + (i * history_sidebar.height * 0.05); 640
583 curr_history_items->rect.width = history_sidebar.width - (padding * 2); 641 curr_history_items->rect = (Rectangle){
584 curr_history_items->rect.height = history_sidebar.height * 0.05; 642 .x = history_sidebar.x,
585 } 643 .y = history_sidebar.y + (padding + item_height) * i,
586 644 .width = history_sidebar.width,
587 // -- URL Area --// 645 .height = item_height
588 url_area.x = (side_bar_x + history_sidebar.width); 646 };
589 url_area.y = (side_bar_y); 647 }
590 url_area.width = (screen_width - history_sidebar.width) * 0.9; 648
591 url_area.height = (screen_height) * 0.1; 649 // Content area: split into URL bar (top 10%) and body (bottom 90%)
592 650 url_area = (Rectangle){
593 url_text_bounds.x = url_area.x + padding; 651 .x = content_area.x,
594 url_text_bounds.y = (url_area.height) / 2; 652 .y = content_area.y,
595 url_text_bounds.width = 7 * (TEXT_SIZE / 2); 653 .width = content_area.width,
596 url_text_bounds.height = TEXT_SIZE * 2; 654 .height = content_area.height * 0.1
597 655 };
598 url_input_bounds.x = url_text_bounds.x + url_text_bounds.width + padding; 656
599 url_input_bounds.y = (url_area.height) / 2; 657 // URL bar elements laid out horizontally
600 url_input_bounds.width = (url_area.width - padding) * 0.7; 658 float url_control_y = url_area.y + (url_area.height - TEXT_SIZE * 2) / 2;
659
660 url_text_bounds = (Rectangle){
661 .x = url_area.x + padding,
662 .y = url_control_y,
663 .width = 7 * (TEXT_SIZE / 2),
664 .height = TEXT_SIZE * 2
665 };
666
667 url_input_bounds = RightOf(url_text_bounds, padding);
668 url_input_bounds.width = url_area.width * 0.7;
601 url_input_bounds.height = TEXT_SIZE * 2; 669 url_input_bounds.height = TEXT_SIZE * 2;
602 670
603 url_enter_button.x = url_input_bounds.x + url_input_bounds.width + padding; 671 url_enter_button = RightOf(url_input_bounds, padding);
604 url_enter_button.y = (url_area.height) / 2; 672 url_enter_button.width = url_area.width * 0.1;
605 url_enter_button.width = (url_area.width - padding) * 0.1;
606 url_enter_button.height = TEXT_SIZE * 2; 673 url_enter_button.height = TEXT_SIZE * 2;
607 674
608 method_dropdown.x = url_enter_button.x + url_enter_button.width + padding; 675 method_dropdown = RightOf(url_enter_button, padding);
609 method_dropdown.y = (url_area.height) / 2; 676 method_dropdown.width = url_area.width * 0.1;
610 method_dropdown.width = (url_area.width - padding) * 0.1;
611 method_dropdown.height = TEXT_SIZE * 2; 677 method_dropdown.height = TEXT_SIZE * 2;
612 678
613 // -- Input Area --// 679 // Body area: split into input (left 50%) and result (right 50%)
614 input_area.x = (side_bar_x + history_sidebar.width); 680 Rectangle body_area = Below(url_area, 0);
615 input_area.y = (side_bar_y + url_area.height); 681 body_area.height = content_area.height - url_area.height;
616 input_area.width = url_area.width * 0.5; 682
617 input_area.height = screen_height - url_area.height; 683 input_area = HorizontalSplit(body_area, 0.5);
618 684 result_area = RightOf(input_area, 0);
619 input_tab.x = (side_bar_x + history_sidebar.width) + padding; 685 result_area.width = body_area.width - input_area.width;
620 input_tab.y = (side_bar_y + url_area.height) + padding; 686
621 input_tab.width = url_area.width * 0.49 - padding; 687 // Input area: tabs at top (10%) and text box below (90%)
622 input_tab.height = input_area.height * 0.1; 688 input_tab = (Rectangle){
689 .x = input_area.x + padding,
690 .y = input_area.y + padding,
691 .width = input_area.width - (2 * padding),
692 .height = input_area.height * 0.1
693 };
694
623 input_tab_item = input_tab; 695 input_tab_item = input_tab;
624 input_tab_item.width = input_tab.width / 4; 696 input_tab_item.width = input_tab.width / 4;
625 697
626 input_body.x = input_tab.x; 698 input_body = Below(input_tab, 0);
627 input_body.y = input_tab.y + input_tab.height; 699 input_body.width = input_tab.width;
628 input_body.width = url_area.width * 0.49 - padding; 700 input_body.height = input_area.height - input_tab.height - (2 * padding);
629 input_body.height = input_area.height - input_tab.height - padding; 701
630 702 // Result area: aligned with input tabs
631 // -- Result Area --// 703 result_body = (Rectangle){
632 result_area.x = (input_area.x + input_area.width); 704 .x = result_area.x + padding,
633 result_area.y = (side_bar_y + url_area.height); 705 .y = input_body.y,
634 result_area.width = url_area.width * 0.49; 706 .width = result_area.width - (2 * padding),
635 result_area.height = screen_height - url_area.height; 707 .height = input_body.height
636 708 };
637 result_body.x = result_area.x + padding;
638 result_body.y = result_area.y + input_tab.height + padding;
639 result_body.width = url_area.width * 0.49 - padding;
640 result_body.height = result_area.height - input_tab.height - padding;
641 709
642 Vector2 mouse_position = GetMousePosition(); 710 Vector2 mouse_position = GetMousePosition();
643 711
644 BeginDrawing(); 712 BeginDrawing();
645 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR))); 713 ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));