diff -r 279c0c81d3b1 -r 1bd5534c395d ui/common/types.c --- a/ui/common/types.c Fri Oct 13 11:26:47 2023 +0200 +++ b/ui/common/types.c Fri Oct 13 15:20:54 2023 +0200 @@ -204,10 +204,28 @@ return info; } +UiModel* ui_model_copy(UiContext *ctx, UiModel* model) { + const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; + + UiModel* newmodel = cxMalloc(a, sizeof(UiModel)); + *newmodel = *model; + + newmodel->types = cxCalloc(a, model->columns, sizeof(UiModelType)); + memcpy(newmodel->types, model->types, model->columns); + + newmodel->titles = cxCalloc(a, model->columns, sizeof(char*)); + for (int i = 0; i < model->columns; i++) { + newmodel->titles[i] = model->titles[i] ? cx_strdup_a(a, cx_str(model->titles[i])).ptr : NULL; + } + + return newmodel; +} + void ui_model_free(UiContext *ctx, UiModel *mi) { - cxFree(ctx->allocator, mi->types); - cxFree(ctx->allocator, mi->titles); - cxFree(ctx->allocator, mi); + const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator; + cxFree(a, mi->types); + cxFree(a, mi->titles); + cxFree(a, mi); } // types