Mercurial
diff infinite_canvas/canvas.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/canvas.c Tue Aug 18 19:14:53 2026 -0700 +++ b/infinite_canvas/canvas.c Tue Aug 18 22:18:15 2026 -0700 @@ -268,6 +268,22 @@ line_thickness, color); } + +} + +void Canvas_Draw_Lucide_Icon( + const char *p_name, + Vector2 origin, + float scale, + float line_thickness, + Color color) +{ + Canvas_Lucide_Draw_Icon( + Canvas_Lucide_Find_Icon(p_name), + origin, + scale, + line_thickness, + color); } static Rectangle Canvas_Web_Toolbar_Bounds( @@ -1633,24 +1649,32 @@ } } -static boolean Canvas_Web_Resize_Handle_Contains( +Rectangle Canvas_Entity_Resize_Handle_Bounds( + const Canvas_Entity *p_entity, + float zoom) +{ + float handle_size = CANVAS_WEB_RESIZE_HANDLE / zoom; + return (Rectangle){ + p_entity->position.x + p_entity->size.x - handle_size, + p_entity->position.y + p_entity->size.y - handle_size, + handle_size, + handle_size, + }; +} + +static boolean Canvas_Entity_Resize_Handle_Contains( const Canvas_Entity *p_entity, Vector2 point, float zoom) { if (p_entity->type != CANVAS_ENTITY_WEB_CONTENT && - p_entity->type != CANVAS_ENTITY_IMAGE) { + p_entity->type != CANVAS_ENTITY_IMAGE && + p_entity->type != CANVAS_ENTITY_TEXT_AREA) { return FALSE; } - float handle_size = CANVAS_WEB_RESIZE_HANDLE / zoom; return CheckCollisionPointRec( point, - (Rectangle){ - p_entity->position.x + p_entity->size.x - handle_size, - p_entity->position.y + p_entity->size.y - handle_size, - handle_size, - handle_size, - }) ? TRUE : FALSE; + Canvas_Entity_Resize_Handle_Bounds(p_entity, zoom)) ? TRUE : FALSE; } int32 Canvas_Scene_Pick( @@ -2603,11 +2627,17 @@ world_pointer, Canvas_Lucide_Search_Bounds(p_entity)) ? TRUE : FALSE; } + p_scene->resizing = Canvas_Entity_Resize_Handle_Contains( + p_entity, + world_pointer, + p_camera->zoom); p_scene->selecting_text = FALSE; if (p_entity->type == CANVAS_ENTITY_TEXT_AREA) { - boolean inside_content = CheckCollisionPointRec( - world_pointer, - Canvas_Text_Area_Content_Bounds(p_entity)) ? TRUE : FALSE; + boolean inside_content = + !p_scene->resizing && + CheckCollisionPointRec( + world_pointer, + Canvas_Text_Area_Content_Bounds(p_entity)); p_entity->active = inside_content; if (inside_content) { int32 cursor = Canvas_Text_Cursor_At_Point( @@ -2623,10 +2653,6 @@ } p_scene->pressed_index = p_scene->selected_index; p_scene->dragging = FALSE; - p_scene->resizing = Canvas_Web_Resize_Handle_Contains( - p_entity, - world_pointer, - p_camera->zoom); p_scene->pointer_start = world_pointer; p_scene->entity_start = p_entity->position; p_scene->entity_size_start = p_entity->size; @@ -2663,10 +2689,25 @@ if (p_entity->type == CANVAS_ENTITY_NOTIFICATION) { p_scene->dragging = FALSE; } else if (p_scene->resizing) { + float min_width = + p_entity->type == CANVAS_ENTITY_TEXT_AREA + ? CANVAS_TEXT_AREA_MIN_WIDTH + : CANVAS_WEB_MIN_WIDTH; + float min_height = + p_entity->type == CANVAS_ENTITY_TEXT_AREA + ? CANVAS_TEXT_AREA_MIN_HEIGHT + : CANVAS_WEB_MIN_HEIGHT; p_entity->size = (Vector2){ - fmaxf(CANVAS_WEB_MIN_WIDTH, p_scene->entity_size_start.x + delta.x), - fmaxf(CANVAS_WEB_MIN_HEIGHT, p_scene->entity_size_start.y + delta.y), + fmaxf( + min_width, + p_scene->entity_size_start.x + delta.x), + fmaxf( + min_height, + p_scene->entity_size_start.y + delta.y), }; + if (p_entity->type == CANVAS_ENTITY_TEXT_AREA) { + Canvas_Text_Ensure_Cursor_Visible(p_entity, font); + } } else { p_entity->position = (Vector2){ p_scene->entity_start.x + delta.x, @@ -3059,32 +3100,31 @@ 10, line, selection); - DrawRectangleRec( - (Rectangle){ - p_entity->position.x + p_entity->size.x - - CANVAS_WEB_RESIZE_HANDLE / zoom, - p_entity->position.y + p_entity->size.y - - CANVAS_WEB_RESIZE_HANDLE / zoom, - CANVAS_WEB_RESIZE_HANDLE / zoom, - CANVAS_WEB_RESIZE_HANDLE / zoom, - }, - Canvas_Color_Fade(selection, 0.18f)); - DrawLineEx( - (Vector2){ - p_entity->position.x + p_entity->size.x - 11.0f / zoom, - p_entity->position.y + p_entity->size.y - 4.0f / zoom, - }, - (Vector2){ - p_entity->position.x + p_entity->size.x - 4.0f / zoom, - p_entity->position.y + p_entity->size.y - 11.0f / zoom, - }, - 1.5f / zoom, - selection); break; default: break; } + if (p_entity->type == CANVAS_ENTITY_TEXT_AREA || + p_entity->type == CANVAS_ENTITY_IMAGE || + p_entity->type == CANVAS_ENTITY_WEB_CONTENT) { + Rectangle handle = + Canvas_Entity_Resize_Handle_Bounds(p_entity, zoom); + DrawRectangleRec( + handle, + Canvas_Color_Fade(selection, 0.18f)); + DrawLineEx( + (Vector2){ + handle.x + handle.width - 11.0f / zoom, + handle.y + handle.height - 4.0f / zoom, + }, + (Vector2){ + handle.x + handle.width - 4.0f / zoom, + handle.y + handle.height - 11.0f / zoom, + }, + 1.5f / zoom, + selection); + } } static void Canvas_Draw_Text_Area_Content(