diff 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
line wrap: on
line diff
--- a/postdog/main.c	Tue Jan 06 08:15:37 2026 -0800
+++ b/postdog/main.c	Tue Jan 06 08:19:07 2026 -0800
@@ -491,7 +491,7 @@
 
 Rectangle AddPadding(Rectangle rect, float padding)
 {
-  return (Rectangle){ 
+  return (Rectangle){
     rect.x + padding,
     rect.y + padding,
     rect.width - (2 * padding),
@@ -499,6 +499,57 @@
   };
 }
 
+// Layout helper functions
+Rectangle RightOf(Rectangle ref, float padding)
+{
+  return (Rectangle){
+    .x = ref.x + ref.width + padding,
+    .y = ref.y,
+    .width = 0,
+    .height = ref.height
+  };
+}
+
+Rectangle Below(Rectangle ref, float padding)
+{
+  return (Rectangle){
+    .x = ref.x,
+    .y = ref.y + ref.height + padding,
+    .width = ref.width,
+    .height = 0
+  };
+}
+
+Rectangle LeftColumn(Rectangle container, float ratio, float padding)
+{
+  return (Rectangle){
+    .x = container.x + padding,
+    .y = container.y + padding,
+    .width = (container.width * ratio) - padding,
+    .height = container.height - (2 * padding)
+  };
+}
+
+Rectangle RightColumn(Rectangle container, Rectangle leftCol, float padding)
+{
+  return (Rectangle){
+    .x = leftCol.x + leftCol.width + padding,
+    .y = container.y + padding,
+    .width = container.width - leftCol.width - (3 * padding),
+    .height = container.height - (2 * padding)
+  };
+}
+
+Rectangle HorizontalSplit(Rectangle container, float ratio)
+{
+  return (Rectangle){
+    .x = container.x,
+    .y = container.y,
+    .width = container.width * ratio,
+    .height = container.height
+  };
+}
+
 int main()
 {
   // -- initizlied --//
@@ -569,75 +620,92 @@
     int screen_width = GetScreenWidth();
     int screen_height = GetScreenHeight();
 
-    history_sidebar.width = screen_width * 0.15;
-    history_sidebar.height = screen_width - 10; 
+    // Define main screen container
+    Rectangle screen = { 0, 0, screen_width, screen_height };
 
+    // Layout: Sidebar (left 15%) and Content Area (right 85%)
+    history_sidebar = LeftColumn(screen, 0.15, padding);
+    Rectangle content_area = RightColumn(screen, history_sidebar, padding);
+
+    // History items inside sidebar
     int32 new_history_items_length = Dowa_Array_Length(new_history_items);
     int32 history_item_length = Dowa_Array_Length(history_items);
-    int32 total =  new_history_items_length + history_item_length;
+    int32 total = new_history_items_length + history_item_length;
+    float item_height = history_sidebar.height * 0.05;
+
     for (int i = 0; i < total; i++)
     {
-      HistoryItem *curr_history_items = i < new_history_items_length ? &new_history_items[i] : &history_items[i - new_history_items_length];
-      curr_history_items->rect.x = history_sidebar.x + padding;
-      curr_history_items->rect.y = history_sidebar.y + (padding * 2 * (i+1)) + (i * history_sidebar.height * 0.05);
-      curr_history_items->rect.width = history_sidebar.width - (padding * 2);
-      curr_history_items->rect.height = history_sidebar.height * 0.05;
+      HistoryItem *curr_history_items = i < new_history_items_length ?
+        &new_history_items[i] : &history_items[i - new_history_items_length];
+
+      curr_history_items->rect = (Rectangle){
+        .x = history_sidebar.x,
+        .y = history_sidebar.y + (padding + item_height) * i,
+        .width = history_sidebar.width,
+        .height = item_height
+      };
     }
 
-    // -- URL Area --//
-    url_area.x = (side_bar_x + history_sidebar.width);
-    url_area.y = (side_bar_y);
-    url_area.width = (screen_width - history_sidebar.width) * 0.9;
-    url_area.height = (screen_height) * 0.1;
+    // Content area: split into URL bar (top 10%) and body (bottom 90%)
+    url_area = (Rectangle){
+      .x = content_area.x,
+      .y = content_area.y,
+      .width = content_area.width,
+      .height = content_area.height * 0.1
+    };
 
-    url_text_bounds.x = url_area.x + padding;
-    url_text_bounds.y = (url_area.height) / 2;
-    url_text_bounds.width = 7 * (TEXT_SIZE / 2);
-    url_text_bounds.height = TEXT_SIZE * 2;
+    // URL bar elements laid out horizontally
+    float url_control_y = url_area.y + (url_area.height - TEXT_SIZE * 2) / 2;
 
-    url_input_bounds.x = url_text_bounds.x + url_text_bounds.width + padding;
-    url_input_bounds.y = (url_area.height) / 2;
-    url_input_bounds.width = (url_area.width - padding) * 0.7;
+    url_text_bounds = (Rectangle){
+      .x = url_area.x + padding,
+      .y = url_control_y,
+      .width = 7 * (TEXT_SIZE / 2),
+      .height = TEXT_SIZE * 2
+    };
+
+    url_input_bounds = RightOf(url_text_bounds, padding);
+    url_input_bounds.width = url_area.width * 0.7;
     url_input_bounds.height = TEXT_SIZE * 2;
 
-    url_enter_button.x = url_input_bounds.x + url_input_bounds.width + padding;
-    url_enter_button.y = (url_area.height) / 2;
-    url_enter_button.width = (url_area.width - padding) * 0.1;
+    url_enter_button = RightOf(url_input_bounds, padding);
+    url_enter_button.width = url_area.width * 0.1;
     url_enter_button.height = TEXT_SIZE * 2;
 
-    method_dropdown.x = url_enter_button.x + url_enter_button.width + padding;
-    method_dropdown.y = (url_area.height) / 2;
-    method_dropdown.width = (url_area.width - padding) * 0.1;
+    method_dropdown = RightOf(url_enter_button, padding);
+    method_dropdown.width = url_area.width * 0.1;
     method_dropdown.height = TEXT_SIZE * 2;
 
-    // -- Input Area --//
-    input_area.x = (side_bar_x + history_sidebar.width);
-    input_area.y = (side_bar_y + url_area.height);
-    input_area.width = url_area.width * 0.5;
-    input_area.height = screen_height - url_area.height;
+    // Body area: split into input (left 50%) and result (right 50%)
+    Rectangle body_area = Below(url_area, 0);
+    body_area.height = content_area.height - url_area.height;
+
+    input_area = HorizontalSplit(body_area, 0.5);
+    result_area = RightOf(input_area, 0);
+    result_area.width = body_area.width - input_area.width;
 
-    input_tab.x = (side_bar_x + history_sidebar.width) + padding;
-    input_tab.y = (side_bar_y + url_area.height) + padding;
-    input_tab.width = url_area.width * 0.49 - padding;
-    input_tab.height = input_area.height * 0.1;
+    // Input area: tabs at top (10%) and text box below (90%)
+    input_tab = (Rectangle){
+      .x = input_area.x + padding,
+      .y = input_area.y + padding,
+      .width = input_area.width - (2 * padding),
+      .height = input_area.height * 0.1
+    };
+
     input_tab_item = input_tab;
     input_tab_item.width = input_tab.width / 4;
 
-    input_body.x = input_tab.x;
-    input_body.y = input_tab.y + input_tab.height;
-    input_body.width = url_area.width * 0.49 - padding;
-    input_body.height = input_area.height - input_tab.height - padding;
+    input_body = Below(input_tab, 0);
+    input_body.width = input_tab.width;
+    input_body.height = input_area.height - input_tab.height - (2 * padding);
 
-    // -- Result Area --//
-    result_area.x = (input_area.x + input_area.width);
-    result_area.y = (side_bar_y + url_area.height);
-    result_area.width = url_area.width * 0.49;
-    result_area.height = screen_height - url_area.height;
-
-    result_body.x = result_area.x + padding;
-    result_body.y = result_area.y + input_tab.height + padding;
-    result_body.width = url_area.width * 0.49 - padding;
-    result_body.height = result_area.height - input_tab.height - padding;
+    // Result area: aligned with input tabs
+    result_body = (Rectangle){
+      .x = result_area.x + padding,
+      .y = input_body.y,
+      .width = result_area.width - (2 * padding),
+      .height = input_body.height
+    };
 
     Vector2 mouse_position = GetMousePosition();