177 ui_list_append(doc->srclist1, "test2"); |
178 ui_list_append(doc->srclist1, "test2"); |
178 ui_list_append(doc->srclist1, "test3"); |
179 ui_list_append(doc->srclist1, "test3"); |
179 ui_list_append(doc->srclist2, "x1"); |
180 ui_list_append(doc->srclist2, "x1"); |
180 ui_list_append(doc->srclist2, "x2"); |
181 ui_list_append(doc->srclist2, "x2"); |
181 |
182 |
182 |
183 doc->items = ui_list_new(docctx, "items"); |
|
184 ui_list_append(doc->items, "Item 1"); |
|
185 ui_list_append(doc->items, "Item 2"); |
|
186 ui_list_append(doc->items, "Item 3"); |
183 |
187 |
184 //doc->text = ui_text_new(docctx, "text"); |
188 //doc->text = ui_text_new(docctx, "text"); |
185 return doc; |
189 return doc; |
186 } |
190 } |
187 |
191 |
276 } |
280 } |
277 |
281 |
278 void sourcelist_getvalue(void *sublistdata, void *rowdata, int index, UiSubListItem *item) { |
282 void sourcelist_getvalue(void *sublistdata, void *rowdata, int index, UiSubListItem *item) { |
279 item->label = strdup(rowdata); |
283 item->label = strdup(rowdata); |
280 item->eventdata = sublistdata; |
284 item->eventdata = sublistdata; |
|
285 } |
|
286 |
|
287 typedef struct Item { |
|
288 UiObject *obj; |
|
289 MyDocument *doc; |
|
290 void *elm; |
|
291 } Item; |
|
292 |
|
293 void item_remove(UiEvent *event, void *userdata) { |
|
294 Item *item = userdata; |
|
295 int index = 0; |
|
296 void *elm = ui_list_first(item->doc->items); |
|
297 while(elm) { |
|
298 if(elm == item->elm) { |
|
299 break; |
|
300 } |
|
301 elm = ui_list_next(item->doc->items); |
|
302 index++; |
|
303 } |
|
304 |
|
305 ui_list_remove(item->doc->items, index); |
|
306 ui_list_update(item->doc->items); |
|
307 } |
|
308 |
|
309 void create_item(UiObject *obj, int index, void *elm, void *userdata) { |
|
310 Item *i = ui_malloc(obj->ctx, sizeof(Item)); |
|
311 i->obj = obj; |
|
312 i->elm = elm; |
|
313 i->doc = userdata; |
|
314 |
|
315 char *item = elm; |
|
316 ui_button(obj, .label = item); |
|
317 ui_checkbox(obj, .label = "Check"); |
|
318 ui_label(obj, .fill = UI_ON); |
|
319 ui_button(obj, .label = "X", .onclick = item_remove, .onclickdata = i); |
|
320 |
|
321 |
|
322 |
281 } |
323 } |
282 |
324 |
283 void application_startup(UiEvent *event, void *data) { |
325 void application_startup(UiEvent *event, void *data) { |
284 // global list |
326 // global list |
285 UiContext *global = ui_global_context(); |
327 UiContext *global = ui_global_context(); |
402 snprintf(labelstr, 32, "button %d", i); |
444 snprintf(labelstr, 32, "button %d", i); |
403 ui_button(obj, .label = labelstr); |
445 ui_button(obj, .label = labelstr); |
404 } |
446 } |
405 } |
447 } |
406 } |
448 } |
|
449 |
|
450 ui_tab(obj, "Tab 7") { |
|
451 ui_itemlist(obj, .create_ui = create_item, .varname = "items", .subcontainer = UI_CONTAINER_HBOX, .sub_spacing = 10, .margin = 10, .spacing = 4, .userdata = doc); |
|
452 } |
407 } |
453 } |
408 |
454 |
409 /* |
455 /* |
410 |
456 |
411 */ |
457 */ |