diff infinite_canvas/dev_ui.c @ 281:c57149ad216e default tip

Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
author MrJuneJune <me@mrjunejune.com>
date Tue, 18 Aug 2026 22:18:15 -0700
parents 49e9e591c9bb
children
line wrap: on
line diff
--- a/infinite_canvas/dev_ui.c	Tue Aug 18 19:14:53 2026 -0700
+++ b/infinite_canvas/dev_ui.c	Tue Aug 18 22:18:15 2026 -0700
@@ -1,11 +1,12 @@
 #include "infinite_canvas/dev_ui.h"
 
 #include <math.h>
+#include <stdio.h>
 
 #define RAYGUI_IMPLEMENTATION
 #include "third_party/raylib/include/raygui.h"
 
-static const Rectangle DEV_PANEL = {18.0f, 18.0f, 264.0f, 520.0f};
+static const Rectangle DEV_PANEL = {18.0f, 18.0f, 264.0f, 650.0f};
 static const Rectangle DEV_PANEL_COLLAPSED = {18.0f, 18.0f, 44.0f, 44.0f};
 
 static Rectangle Canvas_Dev_UI_Context_Bounds(void)
@@ -211,14 +212,33 @@
         .dropdown_open = FALSE,
         .context_open = FALSE,
     };
+    snprintf(
+        p_ui->snapshot_name,
+        sizeof(p_ui->snapshot_name),
+        "workspace");
+    snprintf(
+        p_ui->snapshot_status,
+        sizeof(p_ui->snapshot_status),
+        "Native snapshots use a versioned .zmap file");
     Canvas_Dev_UI_Set_Style(font, p_theme);
 }
 
+void Canvas_Dev_UI_Set_Snapshot_Status(
+    Canvas_Dev_UI *p_ui,
+    const char *p_status)
+{
+    snprintf(
+        p_ui->snapshot_status,
+        sizeof(p_ui->snapshot_status),
+        "%s",
+        p_status ? p_status : "");
+}
+
 boolean Canvas_Dev_UI_Contains_Pointer(const Canvas_Dev_UI *p_ui)
 {
     // The expanded dropdown is modal: it draws outside DEV_PANEL and also
     // consumes outside clicks to close itself.
-    if (p_ui->dropdown_open) return TRUE;
+    if (p_ui->dropdown_open || p_ui->snapshot_name_editing) return TRUE;
 
     Vector2 pointer = GetMousePosition();
     if (CheckCollisionPointRec(
@@ -233,13 +253,19 @@
     return FALSE;
 }
 
-void Canvas_Dev_UI_Draw(
+boolean Canvas_Dev_UI_Is_Editing(const Canvas_Dev_UI *p_ui)
+{
+    return p_ui->dropdown_open || p_ui->snapshot_name_editing;
+}
+
+Canvas_Dev_UI_Action Canvas_Dev_UI_Draw(
     Canvas_Dev_UI *p_ui,
     Canvas_Camera *p_camera,
     Canvas_Scene *p_scene,
     Font font,
     Canvas_Theme *p_theme)
 {
+    Canvas_Dev_UI_Action action = CANVAS_DEV_UI_ACTION_NONE;
     if (p_ui->collapsed) {
         Canvas_Theme_Draw_Shadow(
             p_theme,
@@ -266,7 +292,7 @@
                 10)) {
             p_ui->collapsed = FALSE;
         }
-        return;
+        return action;
     }
 
     Canvas_Context_Snapshot context = Canvas_Scene_Build_Visible_Context(
@@ -299,7 +325,7 @@
         p_ui->collapsed = TRUE;
         p_ui->dropdown_open = FALSE;
         p_ui->context_open = FALSE;
-        return;
+        return action;
     }
 
     if (p_ui->dropdown_open) GuiLock();
@@ -376,19 +402,57 @@
         Canvas_Scene_Show_Parking_Lot(p_scene, p_camera);
     }
 
-    DrawTextEx(font, TextFormat("%d FPS", GetFPS()), (Vector2){34.0f, 438.0f}, 12.0f, 0.0f, p_theme->text_muted);
-    DrawTextEx(font, TextFormat("%.2fx zoom", p_camera->zoom), (Vector2){104.0f, 438.0f}, 12.0f, 0.0f, p_theme->text_muted);
+    DrawTextEx(
+        font,
+        "Named canvas snapshot",
+        (Vector2){34.0f, 424.0f},
+        12.0f,
+        0.0f,
+        p_theme->text_muted);
+    if (GuiTextBox(
+            (Rectangle){34.0f, 444.0f, 232.0f, 34.0f},
+            p_ui->snapshot_name,
+            (int32)sizeof(p_ui->snapshot_name),
+            p_ui->snapshot_name_editing)) {
+        p_ui->snapshot_name_editing = !p_ui->snapshot_name_editing;
+    }
+    if (GuiButtonRounded(
+            (Rectangle){34.0f, 486.0f, 112.0f, 34.0f},
+            "Save",
+            0.32f,
+            10)) {
+        action = CANVAS_DEV_UI_ACTION_SAVE_SNAPSHOT;
+        p_ui->snapshot_name_editing = FALSE;
+    }
+    if (GuiButtonRounded(
+            (Rectangle){154.0f, 486.0f, 112.0f, 34.0f},
+            "Load",
+            0.32f,
+            10)) {
+        action = CANVAS_DEV_UI_ACTION_LOAD_SNAPSHOT;
+        p_ui->snapshot_name_editing = FALSE;
+    }
+    DrawTextEx(
+        font,
+        p_ui->snapshot_status,
+        (Vector2){34.0f, 530.0f},
+        11.0f,
+        0.0f,
+        p_theme->text_muted);
+
+    DrawTextEx(font, TextFormat("%d FPS", GetFPS()), (Vector2){34.0f, 570.0f}, 12.0f, 0.0f, p_theme->text_muted);
+    DrawTextEx(font, TextFormat("%.2fx zoom", p_camera->zoom), (Vector2){104.0f, 570.0f}, 12.0f, 0.0f, p_theme->text_muted);
     DrawTextEx(
         font,
         TextFormat("%d objects", (int)Dowa_Array_Length(p_scene->p_entities)),
-        (Vector2){196.0f, 438.0f},
+        (Vector2){196.0f, 570.0f},
         12.0f,
         0.0f,
         p_theme->text_muted);
     DrawTextEx(
         font,
         "Drag objects directly on the canvas",
-        (Vector2){34.0f, 484.0f},
+        (Vector2){34.0f, 616.0f},
         12.0f,
         0.0f,
         p_theme->text_muted);
@@ -413,4 +477,5 @@
             10)) {
         p_ui->dropdown_open = !p_ui->dropdown_open;
     }
+    return action;
 }