Mercurial
comparison infinite_canvas/canvas.h @ 278:8d560f50ed4c
Improve infinite canvas interactions and browser chrome
Render Lucide icons directly with Raylib, add searchable icon browsing, robust text editing, entity lifecycle animations, z-order-safe input, semantic themes, and animated editable browser controls. Document rendering, pinning, context, and component extension for future agents.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 17 Aug 2026 22:16:14 -0700 |
| parents | b55c22cff335 |
| children | 49e9e591c9bb |
comparison
equal
deleted
inserted
replaced
| 277:1d99147f520c | 278:8d560f50ed4c |
|---|---|
| 5 #include "infinite_canvas/theme.h" | 5 #include "infinite_canvas/theme.h" |
| 6 #include "third_party/raylib/include/raylib.h" | 6 #include "third_party/raylib/include/raylib.h" |
| 7 | 7 |
| 8 #define CANVAS_MAX_ENTITIES 1024 | 8 #define CANVAS_MAX_ENTITIES 1024 |
| 9 #define CANVAS_WEB_FRAME_INSET 8.0f | 9 #define CANVAS_WEB_FRAME_INSET 8.0f |
| 10 #define CANVAS_WEB_TOOLBAR_HEIGHT 42.0f | |
| 10 #define CANVAS_WEB_RESIZE_HANDLE 18.0f | 11 #define CANVAS_WEB_RESIZE_HANDLE 18.0f |
| 11 #define CANVAS_WEB_MIN_WIDTH 160.0f | 12 #define CANVAS_WEB_MIN_WIDTH 160.0f |
| 12 #define CANVAS_WEB_MIN_HEIGHT 120.0f | 13 #define CANVAS_WEB_MIN_HEIGHT 120.0f |
| 13 #define CANVAS_CONTEXT_MAX_LENGTH (64 * 1024) | 14 #define CANVAS_CONTEXT_MAX_LENGTH (64 * 1024) |
| 15 #define CANVAS_ENTITY_TEXT_CAPACITY 2048 | |
| 14 | 16 |
| 15 typedef enum { | 17 typedef enum { |
| 16 CANVAS_ENTITY_RECTANGLE = 0, | 18 CANVAS_ENTITY_RECTANGLE = 0, |
| 17 CANVAS_ENTITY_CIRCLE, | 19 CANVAS_ENTITY_CIRCLE, |
| 18 CANVAS_ENTITY_LINE, | 20 CANVAS_ENTITY_LINE, |
| 27 CANVAS_ENTITY_TABLE, | 29 CANVAS_ENTITY_TABLE, |
| 28 CANVAS_ENTITY_NOTIFICATION, | 30 CANVAS_ENTITY_NOTIFICATION, |
| 29 CANVAS_ENTITY_SCROLL_AREA, | 31 CANVAS_ENTITY_SCROLL_AREA, |
| 30 CANVAS_ENTITY_IMAGE, | 32 CANVAS_ENTITY_IMAGE, |
| 31 CANVAS_ENTITY_WEB_CONTENT, | 33 CANVAS_ENTITY_WEB_CONTENT, |
| 34 CANVAS_ENTITY_LUCIDE_GALLERY, | |
| 32 CANVAS_ENTITY_TYPE_COUNT, | 35 CANVAS_ENTITY_TYPE_COUNT, |
| 33 } Canvas_Entity_Type; | 36 } Canvas_Entity_Type; |
| 34 | 37 |
| 35 typedef struct { | 38 typedef struct { |
| 36 uint32 id; | 39 uint32 id; |
| 37 Canvas_Entity_Type type; | 40 Canvas_Entity_Type type; |
| 38 Vector2 position; | 41 Vector2 position; |
| 39 Vector2 size; | 42 Vector2 size; |
| 40 Color color; | 43 Color color; |
| 41 char text[128]; | 44 char text[CANVAS_ENTITY_TEXT_CAPACITY]; |
| 42 int32 value; | 45 int32 value; |
| 46 int32 text_cursor; | |
| 47 int32 text_selection_anchor; | |
| 48 float text_scroll_y; | |
| 49 float visibility_amount; | |
| 43 boolean active; | 50 boolean active; |
| 44 boolean pinned; | 51 boolean pinned; |
| 52 boolean removing; | |
| 45 boolean screen_space_initialized; | 53 boolean screen_space_initialized; |
| 46 float hover_amount; | 54 float hover_amount; |
| 47 float animation_amount; | 55 float animation_amount; |
| 56 float web_chrome_amount; | |
| 48 Vector2 pinned_screen_position; | 57 Vector2 pinned_screen_position; |
| 49 Vector2 pinned_screen_size; | 58 Vector2 pinned_screen_size; |
| 50 } Canvas_Entity; | 59 } Canvas_Entity; |
| 51 | 60 |
| 52 typedef struct { | 61 typedef struct { |
| 66 int32 selected_index; | 75 int32 selected_index; |
| 67 int32 pressed_index; | 76 int32 pressed_index; |
| 68 int32 hover_index; | 77 int32 hover_index; |
| 69 boolean dragging; | 78 boolean dragging; |
| 70 boolean resizing; | 79 boolean resizing; |
| 80 boolean selecting_text; | |
| 81 boolean editing_web_url; | |
| 71 boolean show_grid; | 82 boolean show_grid; |
| 72 float notification_stack_amount; | 83 float notification_stack_amount; |
| 84 uint32 web_url_entity_id; | |
| 85 int32 web_url_cursor; | |
| 86 int32 web_url_selection_anchor; | |
| 87 float web_url_scroll_x; | |
| 88 char web_url_draft[CANVAS_ENTITY_TEXT_CAPACITY]; | |
| 73 Vector2 pointer_start; | 89 Vector2 pointer_start; |
| 74 Vector2 entity_start; | 90 Vector2 entity_start; |
| 75 Vector2 entity_size_start; | 91 Vector2 entity_size_start; |
| 76 } Canvas_Scene; | 92 } Canvas_Scene; |
| 77 | 93 |
| 78 typedef struct { | 94 typedef struct { |
| 79 size_t visible_count; | 95 size_t visible_count; |
| 80 size_t bytes_written; | 96 size_t bytes_written; |
| 81 boolean truncated; | 97 boolean truncated; |
| 82 } Canvas_Context_Snapshot; | 98 } Canvas_Context_Snapshot; |
| 99 | |
| 100 typedef enum { | |
| 101 CANVAS_WEB_CHROME_NONE = 0, | |
| 102 CANVAS_WEB_CHROME_CAPTURE, | |
| 103 CANVAS_WEB_CHROME_BACK, | |
| 104 CANVAS_WEB_CHROME_FORWARD, | |
| 105 CANVAS_WEB_CHROME_NAVIGATE, | |
| 106 } Canvas_Web_Chrome_Action; | |
| 83 | 107 |
| 84 void Canvas_Camera_Init(Canvas_Camera *p_camera, int32 width, int32 height); | 108 void Canvas_Camera_Init(Canvas_Camera *p_camera, int32 width, int32 height); |
| 85 void Canvas_Camera_Set_Viewport(Canvas_Camera *p_camera, int32 width, int32 height); | 109 void Canvas_Camera_Set_Viewport(Canvas_Camera *p_camera, int32 width, int32 height); |
| 86 Vector2 Canvas_Camera_Screen_To_World(const Canvas_Camera *p_camera, Vector2 screen); | 110 Vector2 Canvas_Camera_Screen_To_World(const Canvas_Camera *p_camera, Vector2 screen); |
| 87 Vector2 Canvas_Camera_World_To_Screen(const Canvas_Camera *p_camera, Vector2 world); | 111 Vector2 Canvas_Camera_World_To_Screen(const Canvas_Camera *p_camera, Vector2 world); |
| 89 void Canvas_Camera_Zoom_At( | 113 void Canvas_Camera_Zoom_At( |
| 90 Canvas_Camera *p_camera, | 114 Canvas_Camera *p_camera, |
| 91 Vector2 screen_anchor, | 115 Vector2 screen_anchor, |
| 92 float zoom_multiplier); | 116 float zoom_multiplier); |
| 93 Rectangle Canvas_Camera_Viewport_Bounds(const Canvas_Camera *p_camera); | 117 Rectangle Canvas_Camera_Viewport_Bounds(const Canvas_Camera *p_camera); |
| 118 void Canvas_Camera_Fit_Bounds( | |
| 119 Canvas_Camera *p_camera, | |
| 120 Rectangle bounds, | |
| 121 float padding_left, | |
| 122 float padding_top, | |
| 123 float padding_right, | |
| 124 float padding_bottom); | |
| 94 float Canvas_Grid_Spacing(float zoom); | 125 float Canvas_Grid_Spacing(float zoom); |
| 126 int32 Canvas_Lucide_Count_Matches(const char *p_query); | |
| 127 Canvas_Web_Chrome_Action Canvas_Web_Chrome_Update_Input( | |
| 128 const Canvas_Camera *p_camera, | |
| 129 Canvas_Scene *p_scene, | |
| 130 Font font, | |
| 131 const char *p_current_url); | |
| 132 boolean Canvas_Web_Chrome_Is_Editing(const Canvas_Scene *p_scene); | |
| 95 | 133 |
| 96 void Canvas_Scene_Init(Canvas_Scene *p_scene, Dowa_Arena *p_arena); | 134 void Canvas_Scene_Init(Canvas_Scene *p_scene, Dowa_Arena *p_arena); |
| 97 boolean Canvas_Scene_Add(Canvas_Scene *p_scene, Canvas_Entity_Type type, Vector2 position); | 135 boolean Canvas_Scene_Add(Canvas_Scene *p_scene, Canvas_Entity_Type type, Vector2 position); |
| 98 void Canvas_Scene_Clear(Canvas_Scene *p_scene); | 136 void Canvas_Scene_Clear(Canvas_Scene *p_scene); |
| 137 void Canvas_Scene_Fade_Out_All(Canvas_Scene *p_scene); | |
| 138 void Canvas_Scene_Fade_Out_Selected(Canvas_Scene *p_scene); | |
| 99 void Canvas_Scene_Add_Demo(Canvas_Scene *p_scene); | 139 void Canvas_Scene_Add_Demo(Canvas_Scene *p_scene); |
| 100 void Canvas_Scene_Add_Browser_Grid(Canvas_Scene *p_scene); | 140 void Canvas_Scene_Add_Browser_Grid(Canvas_Scene *p_scene); |
| 141 boolean Canvas_Scene_Show_Lucide_Gallery( | |
| 142 Canvas_Scene *p_scene, | |
| 143 Canvas_Camera *p_camera); | |
| 101 int32 Canvas_Scene_Pick( | 144 int32 Canvas_Scene_Pick( |
| 145 const Canvas_Scene *p_scene, | |
| 146 Vector2 world_pointer, | |
| 147 float zoom); | |
| 148 int32 Canvas_Scene_Topmost_Visual( | |
| 102 const Canvas_Scene *p_scene, | 149 const Canvas_Scene *p_scene, |
| 103 Vector2 world_pointer, | 150 Vector2 world_pointer, |
| 104 float zoom); | 151 float zoom); |
| 105 boolean Canvas_Scene_Update_Interaction( | 152 boolean Canvas_Scene_Update_Interaction( |
| 106 Canvas_Scene *p_scene, | 153 Canvas_Scene *p_scene, |
| 107 const Canvas_Camera *p_camera, | 154 const Canvas_Camera *p_camera, |
| 155 Font font, | |
| 108 boolean block_pointer_input); | 156 boolean block_pointer_input); |
| 109 boolean Canvas_Scene_Is_Text_Editing(const Canvas_Scene *p_scene); | 157 boolean Canvas_Scene_Is_Text_Editing(const Canvas_Scene *p_scene); |
| 110 void Canvas_Scene_Toggle_Selected_Pin( | 158 void Canvas_Scene_Toggle_Selected_Pin( |
| 111 Canvas_Scene *p_scene, | 159 Canvas_Scene *p_scene, |
| 112 const Canvas_Camera *p_camera); | 160 const Canvas_Camera *p_camera); |
| 129 void Canvas_Draw_World( | 177 void Canvas_Draw_World( |
| 130 const Canvas_Camera *p_camera, | 178 const Canvas_Camera *p_camera, |
| 131 const Canvas_Scene *p_scene, | 179 const Canvas_Scene *p_scene, |
| 132 Font font, | 180 Font font, |
| 133 const Canvas_Theme *p_theme); | 181 const Canvas_Theme *p_theme); |
| 182 void Canvas_Draw_World_Background( | |
| 183 const Canvas_Camera *p_camera, | |
| 184 const Canvas_Scene *p_scene, | |
| 185 const Canvas_Theme *p_theme); | |
| 186 void Canvas_Draw_World_Entity( | |
| 187 const Canvas_Camera *p_camera, | |
| 188 const Canvas_Scene *p_scene, | |
| 189 size_t entity_index, | |
| 190 Font font, | |
| 191 const Canvas_Theme *p_theme); | |
| 192 void Canvas_Draw_Web_Chrome_Entity( | |
| 193 const Canvas_Camera *p_camera, | |
| 194 const Canvas_Scene *p_scene, | |
| 195 size_t entity_index, | |
| 196 Font font, | |
| 197 const Canvas_Theme *p_theme, | |
| 198 const char *p_url, | |
| 199 boolean can_go_back, | |
| 200 boolean can_go_forward); | |
| 201 void Canvas_Draw_World_Overlays( | |
| 202 const Canvas_Camera *p_camera, | |
| 203 const Canvas_Scene *p_scene, | |
| 204 Font font, | |
| 205 const Canvas_Theme *p_theme); | |
| 134 | 206 |
| 135 const char *Canvas_Entity_Type_Name(Canvas_Entity_Type type); | 207 const char *Canvas_Entity_Type_Name(Canvas_Entity_Type type); |
| 136 | 208 |
| 137 #endif | 209 #endif |