ui/common/context.c

branch
newapi
changeset 187
24ce2c326d85
parent 174
0358f1d9c506
child 192
bcacd00ea955
--- a/ui/common/context.c	Sun Oct 01 09:23:47 2023 +0200
+++ b/ui/common/context.c	Sun Oct 01 12:08:09 2023 +0200
@@ -34,7 +34,7 @@
 
 #include <cx/array_list.h>
 #include <cx/compare.h>
-#include <cx/basic_mempool.h>
+#include <cx/mempool.h>
 
 #include "context.h"
 #include "../ui/window.h"
@@ -45,23 +45,24 @@
 
 void uic_init_global_context(void) {
     CxMempool *mp = cxBasicMempoolCreate(32);
-    global_context = uic_context(NULL, mp->allocator);
+    global_context = uic_context(NULL, mp);
 }
 
 UiContext* ui_global_context(void) {
     return global_context;
 }
 
-UiContext* uic_context(UiObject *toplevel, const CxAllocator *a) {
-    UiContext *ctx = cxMalloc(a, sizeof(UiContext));
+UiContext* uic_context(UiObject *toplevel, CxMempool *mp) {
+    UiContext *ctx = cxMalloc(mp->allocator, sizeof(UiContext));
     memset(ctx, 0, sizeof(UiContext));
-    ctx->allocator = a;
+    ctx->mp = mp;
+    ctx->allocator = mp->allocator;
     ctx->obj = toplevel;
-    ctx->vars = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
+    ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
     
-    ctx->documents = cxLinkedListCreate(a, cx_cmp_intptr, CX_STORE_POINTERS);
-    ctx->group_widgets = cxLinkedListCreate(a, NULL, sizeof(UiGroupWidget));
-    ctx->groups = cxArrayListCreate(a, cx_cmp_int, sizeof(int), 32);
+    ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_intptr, CX_STORE_POINTERS);
+    ctx->group_widgets = cxLinkedListCreate(mp->allocator, NULL, sizeof(UiGroupWidget));
+    ctx->groups = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32);
     
     ctx->attach_document = uic_context_attach_document;
     ctx->detach_document2 = uic_context_detach_document2;
@@ -195,6 +196,8 @@
     var->from = NULL;
     var->from_ctx = ctx;
 
+    cxMempoolRegister(ctx->mp, var, (cx_destructor_func)uic_unbind_var);
+
     if(!ctx->vars_unbound) {
         ctx->vars_unbound = cxHashMapCreate(ctx->allocator, CX_STORE_POINTERS, 16);
     }
@@ -203,6 +206,15 @@
     return var;
 }
 
+UiVar* uic_create_value_var(UiContext* ctx, void* value) {
+    UiVar *var = (UiVar*)ui_malloc(ctx, sizeof(UiVar));
+    var->from = NULL;
+    var->from_ctx = NULL;
+    var->value = value;
+    var->type = UI_VAR_SPECIAL;
+    return var;
+}
+
 void* uic_create_value(UiContext *ctx, UiVarType type) {
     void *val = NULL;
     switch(type) {

mercurial