ui/common/context.c

changeset 557
e6415fd4af4b
parent 553
90e38db0c755
--- a/ui/common/context.c	Sun Apr 06 13:54:28 2025 +0200
+++ b/ui/common/context.c	Sun Apr 06 14:10:04 2025 +0200
@@ -58,6 +58,7 @@
     memset(ctx, 0, sizeof(UiContext));
     ctx->mp = mp;
     ctx->allocator = mp->allocator;
+    ctx->destroy_handler = cxArrayListCreate(ctx->allocator, NULL, sizeof(UiDestroyHandler), 16);
     ctx->obj = toplevel;
     ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
     
@@ -82,6 +83,13 @@
     return ctx->parent ? uic_root_context(ctx->parent) : ctx;
 }
 
+void uic_context_add_destructor(UiContext *ctx, cx_destructor_func func, void *data) {
+    UiDestroyHandler handler;
+    handler.destructor = func;
+    handler.data = data;
+    cxListAdd(ctx->destroy_handler, &handler);
+}
+
 void uic_context_prepare_close(UiContext *ctx) {
     cxListClear(ctx->groups);
     cxListClear(ctx->group_widgets);
@@ -469,6 +477,10 @@
 }
 
 UIEXPORT void ui_context_destroy(UiContext *ctx) {
+    CxIterator i = cxListIterator(ctx->destroy_handler);
+    cx_foreach(UiDestroyHandler *, h, i) {
+        h->destructor(h->data);
+    }
     cxMempoolFree(ctx->mp);
 }
 

mercurial