ui/common/context.c

branch
newapi
changeset 343
54f5d7eb1335
parent 342
99f83fbf48e9
--- a/ui/common/context.c	Mon Oct 21 15:47:10 2024 +0200
+++ b/ui/common/context.c	Tue Oct 22 21:17:01 2024 +0200
@@ -523,19 +523,28 @@
     cxListDestroy(groups);
 }
 
+size_t uic_group_array_size(const int *groups) {
+    int i;
+    for(i=0;groups[i] >= 0;i++) { }
+    return i;
+}
+
 void uic_add_group_widget(UiContext *ctx, void *widget, ui_enablefunc enable, CxList *groups) {
+    uic_add_group_widget_i(ctx, widget, enable, cxListAt(groups, 0), cxListSize(groups));
+}
+
+void uic_add_group_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *groups, size_t numgroups) {
     const CxAllocator *a = ctx->allocator;
     UiGroupWidget gw;
     
     gw.widget = widget;
     gw.enable = enable;
-    gw.numgroups = cxListSize(groups);
-    gw.groups = cxCalloc(a, gw.numgroups, sizeof(int));
+    gw.numgroups = numgroups;
+    gw.groups = cxCalloc(a, numgroups, sizeof(int));
     
     // copy groups
-    int *intgroups = cxListAt(groups, 0);
-    if(intgroups) {
-        memcpy(gw.groups, intgroups, gw.numgroups * sizeof(int));
+    if(groups) {
+        memcpy(gw.groups, groups, gw.numgroups * sizeof(int));
     }
     
     cxListAdd(ctx->group_widgets, &gw);

mercurial