39 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
40 UiContext *ctx = ucx_mempool_malloc(mp, sizeof(UiContext)); |
40 ctx->mempool = mp; |
41 ctx->mempool = mp; |
41 |
42 |
42 ctx->toplevel = toplevel; |
43 ctx->toplevel = toplevel; |
43 ctx->vars = ucx_map_new_a(mp->allocator, 16); |
44 ctx->vars = ucx_map_new_a(mp->allocator, 16); |
|
45 ctx->groups = NULL; |
44 |
46 |
45 #ifdef UI_GTK |
47 #ifdef UI_GTK |
46 ctx->accel_group = gtk_accel_group_new(); |
48 ctx->accel_group = gtk_accel_group_new(); |
47 gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group); |
49 gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group); |
48 #endif |
50 #endif |
147 fprintf(stderr, "UI Error: unkown variable %s.\n", name); |
149 fprintf(stderr, "UI Error: unkown variable %s.\n", name); |
148 } |
150 } |
149 return 0; |
151 return 0; |
150 } |
152 } |
151 |
153 |
|
154 |
|
155 |
|
156 |
|
157 void ui_set_group(UiContext *ctx, int group) { |
|
158 if(ucx_list_find(ctx->groups, (void*)(intptr_t)group, NULL, NULL) == -1) { |
|
159 ctx->groups = ucx_list_append_a(ctx->mempool->allocator, ctx->groups, (void*)(intptr_t)group); |
|
160 } |
|
161 } |
|
162 |
|
163 void ui_unset_group(UiContext *ctx, int group) { |
|
164 int i = ucx_list_find(ctx->groups, (void*)(intptr_t)group, NULL, NULL); |
|
165 if(i != -1) { |
|
166 UcxList *elm = ucx_list_get(ctx->groups, i); |
|
167 ctx->groups = ucx_list_remove_a(ctx->mempool->allocator, ctx->groups, elm); |
|
168 } |
|
169 } |
|
170 |
|
171 int* ui_active_groups(UiContext *ctx, int *ngroups) { |
|
172 int nelm = ucx_list_size(ctx->groups); |
|
173 int *groups = calloc(sizeof(int), nelm); |
|
174 |
|
175 int i = 0; |
|
176 UCX_FOREACH(elm, ctx->groups) { |
|
177 groups[i++] = (int)elm->data; |
|
178 } |
|
179 |
|
180 *ngroups = nelm; |
|
181 return groups; |
|
182 } |