ui/common/object.c

changeset 113
dde28a806552
parent 112
c3f2f16fa4b8
--- a/ui/common/object.c	Sun Oct 19 21:20:08 2025 +0200
+++ b/ui/common/object.c	Mon Nov 10 21:52:51 2025 +0100
@@ -28,7 +28,6 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-
 #include "object.h"
 #include "context.h"
 
@@ -107,11 +106,15 @@
 }
 
 UiObject* uic_object_new_toplevel(void) {
+    fflush(stdout);
     CxMempool *mp = cxMempoolCreateSimple(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
+    fflush(stdout);
     obj->ctx = uic_context(obj, mp);
     obj->ctx->parent = ui_global_context();
+    fflush(stdout);
     uic_object_created(obj);
+    fflush(stdout);
     return obj;
 }
 
@@ -141,4 +144,29 @@
     } else {
         toplevel->container_begin = NULL;
     }
+    
+    // TODO: free container?
 }
+
+/*
+ * This might look like a weird function, but in case a container creates a
+ * sub-container, 2 container objects are added to the list, however we want
+ * only one container, otherwise ui_container_finish() would not work
+ */
+void uic_object_remove_second_last_container(UiObject *toplevel) {
+    if(toplevel->container_end && toplevel->container_end->prev) {
+        UiContainerX *end = toplevel->container_end;
+        UiContainerX *rm = toplevel->container_end->prev;
+        
+        end->prev = rm->prev;
+        if(rm->prev) {
+            rm->prev->next = end;
+        } else {
+            toplevel->container_begin = end;
+        }
+        
+        // TODO: free container?
+    } else {
+        fprintf(stderr, "Error: uic_object_remove_second_last_container expected at least 2 containers\n");
+    }
+}

mercurial