--- a/ui/common/types.c Sun Apr 16 10:20:21 2023 +0200 +++ b/ui/common/types.c Tue May 23 11:11:28 2023 +0200 @@ -31,7 +31,8 @@ #include <string.h> #include <stdarg.h> -#include <ucx/list.h> +#include <cx/list.h> +#include <cx/array_list.h> #include "../ui/tree.h" #include "types.h" #include "context.h" @@ -99,7 +100,7 @@ list->count = ui_list_count; list->observers = NULL; - list->data = NULL; + list->data = cxArrayListCreate(cxDefaultAllocator, NULL, CX_STORE_POINTERS, 32); list->iter = NULL; list->update = NULL; @@ -113,54 +114,43 @@ } void ui_list_free(UiList *list) { - ucx_list_free(list->data); + cxListDestroy(list->data); free(list); } void* ui_list_first(UiList *list) { - UcxList *elm = list->data; - list->iter = elm; - return elm ? elm->data : NULL; + list->iter = (void*)(intptr_t)0; + return cxListAt(list->data, 0); } void* ui_list_next(UiList *list) { - UcxList *elm = list->iter; + intptr_t iter = (intptr_t)list->iter; + iter++; + void *elm = cxListAt(list->data, iter); if(elm) { - elm = elm->next; - if(elm) { - list->iter = elm; - return elm->data; - } + list->iter = (void*)iter; } - return NULL; + return elm; } void* ui_list_get(UiList *list, int i) { - UcxList *elm = ucx_list_get(list->data, i); - if(elm) { - list->iter = elm; - return elm->data; - } else { - return NULL; - } + return cxListAt(list->data, i); } int ui_list_count(UiList *list) { - UcxList *elm = list->data; - return (int)ucx_list_size(elm); + return ((CxList*)list->data)->size; } void ui_list_append(UiList *list, void *data) { - list->data = ucx_list_append(list->data, data); + cxListAdd(list->data, data); } void ui_list_prepend(UiList *list, void *data) { - list->data = ucx_list_prepend(list->data, data); + cxListInsert(list->data, 0, data); } void ui_list_clear(UiList *list) { - ucx_list_free(list->data); - list->data = NULL; + cxListClear(list->data); } void ui_list_addobsv(UiList *list, ui_callback f, void *data) { @@ -183,42 +173,41 @@ va_list ap; va_start(ap, ctx); - UcxList *cols = NULL; + CxList *cols = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(UiColumn), 32); int type; while((type = va_arg(ap, int)) != -1) { char *name = va_arg(ap, char*); - UiColumn *column = malloc(sizeof(UiColumn)); - column->type = type; - column->name = name; + UiColumn column; + column.type = type; + column.name = name; - cols = ucx_list_append(cols, column); + cxListAdd(cols, &column); } va_end(ap); - size_t len = ucx_list_size(cols); + size_t len = cols->size; info->columns = len; info->types = ui_calloc(ctx, len, sizeof(UiModelType)); info->titles = ui_calloc(ctx, len, sizeof(char*)); int i = 0; - UCX_FOREACH(elm, cols) { - UiColumn *c = elm->data; + CxIterator iter = cxListIterator(cols); + cx_foreach(UiColumn*, c, iter) { info->types[i] = c->type; info->titles[i] = c->name; - free(c); i++; } - ucx_list_free(cols); + cxListDestroy(cols); return info; } void ui_model_free(UiContext *ctx, UiModel *mi) { - ucx_mempool_free(ctx->mempool, mi->types); - ucx_mempool_free(ctx->mempool, mi->titles); - ucx_mempool_free(ctx->mempool, mi); + cxFree(ctx->allocator, mi->types); + cxFree(ctx->allocator, mi->titles); + cxFree(ctx->allocator, mi); } // types