application/main.c

changeset 1246
43a7874a9d0e
parent 1245
4163776eef49
equal deleted inserted replaced
1245:4163776eef49 1246:43a7874a9d0e
220 static UiThreadpool *threadpool; 220 static UiThreadpool *threadpool;
221 221
222 typedef struct TreeNode { 222 typedef struct TreeNode {
223 char *name; 223 char *name;
224 int depth; 224 int depth;
225 int heading;
225 } TreeNode; 226 } TreeNode;
226 227
227 int threadfunc(void *data) { 228 int threadfunc(void *data) {
228 printf("thr wait for data...\n"); 229 printf("thr wait for data...\n");
229 ui_condvar_wait(cond); 230 ui_condvar_wait(cond);
397 398
398 doc->tree = ui_list_new(docctx, "tree"); 399 doc->tree = ui_list_new(docctx, "tree");
399 TreeNode *root = malloc(sizeof(TreeNode)); 400 TreeNode *root = malloc(sizeof(TreeNode));
400 root->name = "Root"; 401 root->name = "Root";
401 root->depth = 0; 402 root->depth = 0;
403 root->heading = 0;
402 ui_list_append(doc->tree, root); 404 ui_list_append(doc->tree, root);
403 405
404 TreeNode *node_a = malloc(sizeof(TreeNode)); 406 TreeNode *node_a = malloc(sizeof(TreeNode));
405 node_a->name = "Folder"; 407 node_a->name = "Folder";
406 node_a->depth = 1; 408 node_a->depth = 1;
409 node_a->heading = 0;
407 ui_list_append(doc->tree, node_a); 410 ui_list_append(doc->tree, node_a);
408 411
409 TreeNode *node_a0 = malloc(sizeof(TreeNode)); 412 TreeNode *node_a0 = malloc(sizeof(TreeNode));
410 node_a0->name = "Leaf 1"; 413 node_a0->name = "Leaf 1";
411 node_a0->depth = 2; 414 node_a0->depth = 2;
415 node_a0->heading = 0;
412 ui_list_append(doc->tree, node_a0); 416 ui_list_append(doc->tree, node_a0);
413 417
414 TreeNode *node_a1 = malloc(sizeof(TreeNode)); 418 TreeNode *node_a1 = malloc(sizeof(TreeNode));
415 node_a1->name = "Leaf 2"; 419 node_a1->name = "Leaf 2";
416 node_a1->depth = 2; 420 node_a1->depth = 2;
421 node_a1->heading = 0;
417 ui_list_append(doc->tree, node_a1); 422 ui_list_append(doc->tree, node_a1);
418 423
419 TreeNode *node_1 = malloc(sizeof(TreeNode)); 424 TreeNode *node_1 = malloc(sizeof(TreeNode));
420 node_1->name = "Leaf 3"; 425 node_1->name = "Leaf 3";
421 node_1->depth = 1; 426 node_1->depth = 1;
427 node_1->heading = 0;
422 ui_list_append(doc->tree, node_1); 428 ui_list_append(doc->tree, node_1);
429
430 TreeNode *root2 = malloc(sizeof(TreeNode));
431 root2->name = "Root 2";
432 root2->depth = 0;
433 root2->heading = 1;
434 ui_list_append(doc->tree, root2);
435
436 TreeNode *node_b = malloc(sizeof(TreeNode));
437 node_b->name = "Item";
438 node_b->depth = 1;
439 node_b->heading = 0;
440 ui_list_append(doc->tree, node_b);
423 441
424 442
425 //doc->text = ui_text_new(docctx, "text"); 443 //doc->text = ui_text_new(docctx, "text");
426 return doc; 444 return doc;
427 } 445 }
573 void* tree_getvalue(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) { 591 void* tree_getvalue(UiList *list, void *elm, int row, int col, void *userdata, UiBool *freeResult) {
574 TreeNode *node = elm; 592 TreeNode *node = elm;
575 return node->name; 593 return node->name;
576 } 594 }
577 595
578 void sourcelist2_getvalue(UiList *list, void *elm, int index, UiSubListItem *item, void *userdata) { 596 void sourcelist2_getvalue(UiList *list, void *elm, int index, UiSourceListItem *item, void *userdata) {
579 TreeNode *node = elm; 597 TreeNode *node = elm;
580 item->label = node->name; 598 item->label = strdup(node->name);
599 item->button_icon = strdup("call-start");
600 item->depth = node->depth;
601 item->is_header = node->heading;
581 } 602 }
582 603
583 int tree_getdepth(UiList *list, void *elm, int row, void *userdata) { 604 int tree_getdepth(UiList *list, void *elm, int row, void *userdata) {
584 TreeNode *node = elm; 605 TreeNode *node = elm;
585 return node->depth; 606 return node->depth;
589 ui_menubuilder_ref(sourcelist_menu); 610 ui_menubuilder_ref(sourcelist_menu);
590 item->label = strdup(rowdata); 611 item->label = strdup(rowdata);
591 item->button_icon = strdup("view-more-horizontal"); 612 item->button_icon = strdup("view-more-horizontal");
592 item->button_menu = sourcelist_menu; 613 item->button_menu = sourcelist_menu;
593 item->eventdata = sublistdata; 614 item->eventdata = sublistdata;
615 }
616
617 void sourcelist2_activate(UiEvent *event, void *userdata) {
618 printf("sourcelist2 activate: %d\n", event->intval);
594 } 619 }
595 620
596 typedef struct Item { 621 typedef struct Item {
597 UiObject *obj; 622 UiObject *obj;
598 MyDocument *doc; 623 MyDocument *doc;
956 } 981 }
957 ui_tab(obj, "Tab 13") { 982 ui_tab(obj, "Tab 13") {
958 //UiModel *model = ui_model(obj->ctx, UI_STRING, "test", -1); 983 //UiModel *model = ui_model(obj->ctx, UI_STRING, "test", -1);
959 //ui_treeview(obj, .fill = TRUE, .model = model, .show_header = TRUE, .getvalue = tree_getvalue, .getdepth = tree_getdepth, .varname = "tree"); 984 //ui_treeview(obj, .fill = TRUE, .model = model, .show_header = TRUE, .getvalue = tree_getvalue, .getdepth = tree_getdepth, .varname = "tree");
960 985
961 ui_sourcelist2(obj, .fill = TRUE, .getvalue = sourcelist2_getvalue, .getdepth = tree_getdepth, .varname = "tree"); 986 ui_sourcelist2(obj, .fill = TRUE, .getvalue = sourcelist2_getvalue, .varname = "tree", .onactivate = sourcelist2_activate);
962 } 987 }
963 } 988 }
964 989
965 /* 990 /*
966 991

mercurial