application/main.c

changeset 431
bb7da585debc
parent 429
0921f8a5d535
child 433
605bb5dc34f1
equal deleted inserted replaced
169:fe49cff3c571 431:bb7da585debc
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h>
31 32
32 #include <ui/ui.h> 33 #include <ui/ui.h>
33 #include <ucx/buffer.h> 34 #include <cx/buffer.h>
34 #include <ucx/utils.h> 35 #include <cx/utils.h>
36
37 #if !defined(UI_COCOA) && !defined(UI_MOTIF)
35 38
36 typedef struct { 39 typedef struct {
40 UiString *str1;
41 UiString *str2;
42 UiString *path;
37 UiText *text; 43 UiText *text;
44 UiDouble *progress;
45 UiList *list;
46 UiList *list2;
47 UiList *menulist;
48 UiInteger *radio;
49 UiInteger *tabview;
50 UiGeneric *image;
51 UiList *srclist1;
52 UiList *srclist2;
53 UiList *items;
38 } MyDocument; 54 } MyDocument;
39 55
40 MyDocument *doc1; 56 MyDocument *doc1;
41 MyDocument *doc2; 57 MyDocument *doc2;
42 58
59 UIWIDGET tabview;
60
61 static UiCondVar *cond;
62 static int thr_end = 0;
63 static int thr_started = 0;
64
65 int threadfunc(void *data) {
66 printf("thr wait for data...\n");
67 ui_condvar_wait(cond);
68 printf("thr data received: {%s} [%d]\n", cond->data, cond->intdata);
69 ui_condvar_destroy(cond);
70 cond = NULL;
71
72 return 0;
73 }
74
75 void action_start_thread(UiEvent *event, void *data) {
76 if(!thr_started) {
77 cond = ui_condvar_create();
78 ui_job(event->obj, threadfunc, NULL, NULL, NULL);
79 thr_started = 1;
80 }
81 }
82
83 void action_notify_thread(UiEvent *event, void *data) {
84 if(!thr_end) {
85 ui_condvar_signal(cond, "hello thread", 123);
86 thr_end = 1;
87 }
88 }
43 89
44 void action_menu(UiEvent *event, void *userdata) { 90 void action_menu(UiEvent *event, void *userdata) {
45 printf("action_menu: %s\n", (char*)userdata); 91
92 }
93
94 void action_file_selected(UiEvent *event, void *userdata) {
95 UiFileList *files = event->eventdata;
96 MyDocument *doc = event->document;
97 printf("files: %d\n", (int)files->nfiles);
98 if(files->nfiles > 0) {
99 printf("selected file: %s\n", files->files[0]);
100 ui_image_load_file(doc->image, files->files[0]);
101 }
46 } 102 }
47 103
48 void action_button(UiEvent *event, void *userdata) { 104 void action_button(UiEvent *event, void *userdata) {
49 printf("button test\n"); 105 ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_SINGLE, action_file_selected, NULL);
50 MyDocument *doc = event->document;
51 if(!doc) {
52 printf("no document\n");
53 return;
54 }
55
56 char *text = doc->text->get(doc->text);
57 printf("text: {\n%s\n}\n", text);
58 } 106 }
59 107
60 void action_switch(UiEvent *event, void *userdata) { 108 void action_switch(UiEvent *event, void *userdata) {
61 if(event->document == doc1) { 109
62 ui_set_document(event->obj, doc2); 110 }
63 } else { 111
64 ui_set_document(event->obj, doc1); 112 void action_toolbar_button(UiEvent *event, void *userdata) {
65 } 113 printf("toolbar button\n");
66 } 114
67 115 ui_dialog(event->obj, .title = "Dialog Title", .content = "Content Label", .button1_label = "btn1", .button2_label = "btn2", .input = TRUE, .closebutton_label = "Cancel");
116 }
117
118 void action_dialog_button(UiEvent *event, void *userdata) {
119 ui_close(event->obj);
120 }
121
122 void action_dialog_onactivate(UiEvent *event, void *userdata) {
123 printf("textfield activate\n");
124 ui_close(event->obj);
125 }
126
127 void action_toolbar_dialog(UiEvent *event, void *userdata) {
128
129 UiObject *dialog = ui_dialog_window(event->obj, .title = "Dialog Window", .lbutton1 = "Cancel 1", .lbutton2 = "Btn2", .rbutton3 = "Btn3", .rbutton4 = "Login 4", .onclick = action_dialog_button, .default_button = 4, .show_closebutton = UI_OFF);
130
131 ui_vbox(dialog, .margin = 10, .spacing = 10) {
132 ui_label(dialog, .label = "Enter password:");
133 ui_passwordfield(dialog, .varname = "password", .onactivate = action_dialog_onactivate);
134 }
135
136 ui_show(dialog);
137 }
138
139 void action_toolbar_newwindow(UiEvent *event, void *userdata) {
140 UiObject *obj = ui_simple_window("New Window", NULL);
141
142 ui_headerbar0(obj) {
143 ui_headerbar_start(obj) {
144 ui_button(obj, .label = "Open");
145 }
146 ui_headerbar_end(obj) {
147 ui_button(obj, .label = "Test");
148 }
149 }
150
151 ui_textarea(obj, .varname="text");
152
153 ui_show(obj);
154 }
68 155
69 MyDocument* create_doc(void) { 156 MyDocument* create_doc(void) {
70 MyDocument *doc = ui_document_new(sizeof(MyDocument)); 157 MyDocument *doc = ui_document_new(sizeof(MyDocument));
71 UiContext *docctx = ui_document_context(doc); 158 UiContext *docctx = ui_document_context(doc);
72 doc->text = ui_text_new(docctx, "text"); 159 doc->str1 = ui_string_new(docctx, "str1");
160 doc->str1 = ui_string_new(docctx, "str2");
161 doc->path = ui_string_new(docctx, "path");
162 doc->progress = ui_double_new(docctx, "progress");
163 doc->list = ui_list_new(docctx, "list");
164 ui_list_append(doc->list, "test1");
165 ui_list_append(doc->list, "test2");
166 ui_list_append(doc->list, "test3");
167 doc->list2 = ui_list_new(docctx, "list2");
168 ui_list_append(doc->list2, "test1");
169 ui_list_append(doc->list2, "test2");
170 ui_list_append(doc->list2, "test3");
171 doc->radio = ui_int_new(docctx, "radio");
172 doc->tabview = ui_int_new(docctx, "tabview");
173 doc->image = ui_generic_new(docctx, "image");
174
175 doc->srclist1 = ui_list_new(docctx, "srclist1");
176 doc->srclist2 = ui_list_new(docctx, "srclist2");
177 ui_list_append(doc->srclist1, "test1");
178 ui_list_append(doc->srclist1, "test2");
179 ui_list_append(doc->srclist1, "test3");
180 ui_list_append(doc->srclist2, "x1");
181 ui_list_append(doc->srclist2, "x2");
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");
187
188 //doc->text = ui_text_new(docctx, "text");
73 return doc; 189 return doc;
74 } 190 }
75 191
192 UiIcon *icon = NULL;
193
194 static void* list_getvalue(void *elm, int col) {
195 /*
196 if(col == 0) {
197 if(!icon) {
198 icon = ui_icon("folder", 24);
199 }
200 return icon;
201 }
202 */
203
204 char *str = elm;
205 return col == 0 ? str : "x";
206 }
207
208 static UiList *menu_list;
209 int new_item_count = 0;
210
211 void action_add_menu_item(UiEvent *event, void *userdata) {
212 char str[64];
213 snprintf(str, 64, "new item %d", new_item_count++);
214
215 ui_list_append(menu_list, strdup(str));
216 ui_list_notify(menu_list);
217 }
218
219 void action_menu_list(UiEvent *event, void *userdata) {
220 printf("menu list item: %d\n", event->intval);
221 }
222
223 static int tab_x = 0;
224 void action_tab2_button(UiEvent *event, void *userdata) {
225 MyDocument *doc = event->document;
226 printf("current page: %d\n", (int)ui_get(doc->tabview));
227 ui_set(doc->tabview, 0);
228 }
229
230
231 void action_group1(UiEvent *event, void *userdata) {
232 UiContext *ctx = event->obj->ctx;
233 if(userdata) {
234 ui_unset_group(ctx, 1);
235 } else {
236 ui_set_group(ctx, 1);
237 }
238 }
239
240 void action_group2(UiEvent *event, void *userdata) {
241 UiContext *ctx = event->obj->ctx;
242 if(userdata) {
243 ui_unset_group(ctx, 2);
244 } else {
245 ui_set_group(ctx, 2);
246 }
247 }
248
249 static UiObject *ref_window;
250
251 void action_button_ref(UiEvent *event, void *userdata) {
252 UiObject *obj = event->obj;
253 printf("action_button_ref: %u\n", obj->ref);
254 ui_object_ref(obj);
255 ref_window = obj;
256 }
257
258 void action_button_unref(UiEvent *event, void *userdata) {
259 UiObject *obj = userdata;
260 printf("action_button_unref: %u\n", obj->ref);
261 ui_object_unref(obj);
262 }
263
264 void action_toolbar_unrefwindow(UiEvent *event, void *userdata) {
265 UiObject *obj = ui_simple_window("Unref", NULL);
266 ui_grid(obj, .margin = 20) {
267 ui_button(obj, .label = "Unref", .onclick = action_button_unref, .onclickdata = ref_window);
268 }
269 ui_show(obj);
270 }
271
272 void action_sourcelist_activate(UiEvent *event, void *userdata) {
273 printf("sourcelist %s index %d\n", event->eventdata, event->intval);
274 }
275
276 UiMenuBuilder *menubuilder;
277
278 void* table_getvalue(void *row, int col) {
279 return row;
280 }
281
282 void sourcelist_getvalue(void *sublistdata, void *rowdata, int index, UiSubListItem *item) {
283 item->label = strdup(rowdata);
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
323 }
324
76 void application_startup(UiEvent *event, void *data) { 325 void application_startup(UiEvent *event, void *data) {
77 326 // global list
78 UiObject *obj = ui_window("Test", NULL); 327 UiContext *global = ui_global_context();
79 ui_textarea_nv(obj, "text"); 328 menu_list = ui_list_new(global, "menulist");
80 ui_button(obj, "Test", action_button, NULL); 329 ui_list_append(menu_list, "menu list item 1");
81 ui_button(obj, "Switch Document", action_switch, NULL); 330 ui_list_append(menu_list, "menu list item 2");
82 331 ui_list_append(menu_list, "menu list item 3");
83 doc1 = create_doc(); 332
84 doc2 = create_doc(); 333
85 334
86 ui_attach_document(obj->ctx, doc1); 335 UiObject *obj = ui_sidebar_window("Test", NULL);
336
337 MyDocument *doc = create_doc();
338 ui_attach_document(obj->ctx, doc);
339
340 ui_sidebar(obj, .margin = 0, .spacing = 0) {
341 ui_sourcelist(obj, .fill = UI_ON,
342 .getvalue = sourcelist_getvalue,
343 .sublists = UI_SUBLISTS(UI_SUBLIST(.varname = "srclist1", .header = "Header 1", .userdata = "Sublist1"), UI_SUBLIST(.varname = "srclist2", .header = "Header 2", .userdata = "Sublist2")),
344 .onactivate = action_sourcelist_activate);
345 }
346
347 ui_tabview(obj, .spacing=10, .margin=10, .tabview = UI_TABVIEW_NAVIGATION_SIDE, .varname="tabview") {
348 ui_tab(obj, "Tab 1") {
349 ui_vbox(obj, .fill = UI_OFF, .margin = 15, .spacing = 15) {
350 ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button);
351 ui_togglebutton(obj, .label = "Toggle");
352 ui_checkbox(obj, .label = "My Checkbox");
353 }
354 ui_grid(obj, .fill = UI_OFF, .columnspacing = 15, .rowspacing = 15, .margin = 15) {
355 ui_button(obj, .label = "Activate Group 1", .hexpand = TRUE, .onclick = action_group1);
356 ui_button(obj, .label = "Disable Group 1", .onclick = action_group1, .onclickdata = "disable");
357 ui_newline(obj);
358 ui_button(obj, .label = "Activate Group 2", .hexpand = TRUE, .onclick = action_group2);
359 ui_button(obj, .label = "Disable Group 2", .onclick = action_group2, .onclickdata = "disable");
360 ui_newline(obj);
361
362 ui_button(obj, .label = "Groups 1,2", .colspan = 2, .groups = UI_GROUPS(1, 2));
363 ui_newline(obj);
364
365 ui_label(obj, .label = "Label Col 1", .align = UI_ALIGN_LEFT);
366 ui_label(obj, .label = "Label Col 2", .style = UI_LABEL_STYLE_TITLE, .align = UI_ALIGN_RIGHT);
367 ui_newline(obj);
368
369 ui_spinner(obj, .step = 5);
370 ui_newline(obj);
371
372 ui_progressbar(obj, .colspan = 2, .varname = "progress");
373 ui_set(doc->progress, 0.75);
374 ui_newline(obj);
375
376 ui_textfield(obj, .value = doc->str1);
377 ui_newline(obj);
378
379 //ui_button(obj, .label="Test");
380 ui_path_textfield(obj, .varname = "path", .hfill = TRUE, .hexpand = TRUE);
381 ui_set(doc->path, "/test/path/longdirectoryname/123");
382 ui_newline(obj);
383
384 //UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1);
385 //model->getvalue = list_getvalue;
386 ui_combobox(obj, .hexpand = true, .vexpand = false, .colspan = 2, .varname = "list", .getvalue = list_getvalue);
387 ui_newline(obj);
388
389 ui_hbox0(obj) {
390 ui_radiobutton(obj, .label = "Radio 1", .varname = "radio");
391 ui_radiobutton(obj, .label = "Radio 2", .varname = "radio");
392 ui_radiobutton(obj, .label = "Radio 3", .varname = "radio");
393 }
394 ui_newline(obj);
395
396 UiModel *model = ui_model(obj->ctx, UI_STRING, "col1", -1);
397 model->getvalue = table_getvalue;
398 ui_table(obj, .model = model, .list = doc->list2, .colspan = 2, .hexpand = TRUE, .contextmenu = menubuilder);
399 }
400 }
401 ui_tab(obj, "Tab 2") {
402 ui_button(obj, .label = "Button 1 Start Thread", .onclick=action_start_thread);
403 ui_button(obj, .label = "Button 2 Notify Thread", .onclick=action_notify_thread);
404 ui_button(obj, .label = "Obj Ref", .onclick=action_button_ref);
405 ui_button(obj, .label = "Obj Unref", .onclick=action_button_unref, .onclickdata = obj);
406 ui_button(obj, .label = "Button 5", .onclick=action_tab2_button);
407 ui_button(obj, .label = "Button 6", .onclick=action_tab2_button);
408 }
409 ui_tab(obj, "Tab 3") {
410 UiTabViewArgs args = {0};
411 UI_CTN(obj, tabview=ui_tabview_create(obj, args)) {
412 UiObject *tab1 = ui_tabview_add(tabview, "Sub 1", -1);
413 ui_button(tab1, .label = "Button 1");
414
415
416 UiObject *tab2 = ui_tabview_add(tabview, "Sub 2", -1);
417 ui_button(tab2, .label = "Button 2");
418 }
419 }
420 ui_tab(obj, "Tab 4") {
421 ui_textarea(obj, .varname = "text");
422 }
423 ui_tab(obj, "Tab 5") {
424 ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button);
425 ui_imageviewer(obj, .varname = "image", .style_class = "imageviewer", .contextmenu = menubuilder);
426 }
427
428 ui_tab(obj, "Tab 6") {
429 ui_scrolledwindow(obj, .fill = UI_ON) {
430 ui_expander(obj, .label = "Expander", .margin = 10, .spacing = 10) {
431 ui_label(obj, .label = "Test");
432 ui_button(obj, .label = "Button");
433 }
434
435 ui_frame(obj, .label = "Frame", .margin = 10, .spacing = 10) {
436 ui_label(obj, .label = "Title", .style = UI_LABEL_STYLE_TITLE);
437 ui_label(obj, .label = "Sub-Title", .style = UI_LABEL_STYLE_SUBTITLE);
438 ui_label(obj, .label = "Dim Label", .style = UI_LABEL_STYLE_DIM);
439 ui_label(obj, .label = "No Style");
440 }
441
442 for(int i=0;i<100;i++) {
443 char labelstr[32];
444 snprintf(labelstr, 32, "button %d", i);
445 ui_button(obj, .label = labelstr);
446 }
447 }
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 }
453 }
454
455 /*
456
457 */
87 458
88 ui_show(obj); 459 ui_show(obj);
89 } 460 }
90 461
91 int main(int argc, char** argv) { 462 int main(int argc, char** argv) {
92 ui_init("app1", argc, argv); 463 ui_init("app1", argc, argv);
93 ui_onstartup(application_startup, NULL); 464 ui_onstartup(application_startup, NULL);
94 465
95 // menu 466 // menu
96 ui_menu("_File"); 467 ui_menu("File") {
97 ui_menuitem("_Hello", action_menu, NULL); 468 ui_menuitem(.label = "Test");
98 ui_submenu("Submenu1"); 469 }
99 ui_submenu("Submenu2"); 470
100 ui_menuitem("item2", action_menu, NULL); 471 ui_contextmenu(&menubuilder) {
101 ui_submenu_end(); 472 ui_menuitem(.label = "Context Item 1");
102 ui_menuitem("item3", action_menu, NULL); 473 ui_menuitem(.label = "Context Item 2");
103 ui_submenu_end(); 474 ui_menu("Context Submenu") {
104 ui_menuitem("item4", action_menu, NULL); 475 ui_menuitem(.label = "Context Sub Item");
105 476 }
477 }
478
479 ui_menu("Edit") {
480 ui_menuitem(.label = "Undo");
481 ui_menuseparator();
482 ui_menu("Submenu") {
483 ui_menuitem(.label = "Subitem");
484 }
485 }
486
487 ui_toolbar_item("Test", .label = "Test", .onclick = action_toolbar_button);
488 ui_toolbar_item("Test2", .label = "New Window", .onclick = action_toolbar_newwindow);
489 ui_toolbar_item("Test3", .label = "Dialog", .onclick = action_toolbar_dialog);
490 ui_toolbar_item("Test4", .label = "Unref Window", .onclick = action_toolbar_unrefwindow);
491 ui_toolbar_item("Test5", .label = "Test 5", .onclick = action_toolbar_button);
492 ui_toolbar_item("Test6", .label = "Test 6", .onclick = action_toolbar_button);
493 ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button);
494 ui_toolbar_menu("Menu", .label = "Menu") {
495 ui_menuitem("Secondary Test", .onclick = action_toolbar_button, NULL);
496 ui_menu("Secondary Sub") {
497 ui_menuitem("Secondary subitem", NULL, NULL);
498 }
499 ui_menuseparator();
500 ui_menu_itemlist(.varname = "menulist", .onselect=action_menu_list);
501 ui_menuseparator();
502 ui_menuitem("last", .onclick = action_add_menu_item);
503 }
504
505 ui_toolbar_appmenu() {
506 ui_menuitem("New");
507 ui_menuitem("Open");
508 ui_menuitem("Save");
509
510 ui_menuseparator();
511
512 ui_menuitem("Close");
513 }
514
515 ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT);
516 ui_toolbar_add_default("Test6", UI_TOOLBAR_LEFT);
517 ui_toolbar_add_default("Toggle", UI_TOOLBAR_LEFT);
518 ui_toolbar_add_default("Menu", UI_TOOLBAR_LEFT);
519
520 ui_toolbar_add_default("Test2", UI_TOOLBAR_CENTER);
521 ui_toolbar_add_default("Test3", UI_TOOLBAR_CENTER);
522
523 ui_toolbar_add_default("Test4", UI_TOOLBAR_RIGHT);
524 ui_toolbar_add_default("Test5", UI_TOOLBAR_RIGHT);
106 525
107 ui_main(); 526 ui_main();
108 527
109 return (EXIT_SUCCESS); 528 return (EXIT_SUCCESS);
110 } 529 }
530
531 #endif
532
533 #if defined(UI_COCOA) || defined(UI_MOTIF)
534
535 static UiList *menulist;
536 int items = 4;
537
538 void action_button(UiEvent *event, void *data) {
539 printf("action_button\n");
540
541 char *newitem = malloc(32);
542 snprintf(newitem, 32, "Item %d", ++items);
543 ui_list_append(menulist, newitem);
544 ui_list_notify(menulist);
545 }
546
547 typedef struct WData {
548 UiString *path;
549 UiList *list;
550 } WData;
551
552
553 int lsitems = 4;
554
555 void action_button2(UiEvent *event, void *data) {
556 WData *wdata = event->window;
557 char *newitem = malloc(32);
558 snprintf(newitem, 32, "List Item %d", ++lsitems);
559 ui_list_append(wdata->list, newitem);
560 ui_list_update(wdata->list);
561 UiListSelection sel;
562 int index = lsitems-1;
563 sel.count = 1;
564 sel.rows = &index;
565 wdata->list->setselection(wdata->list, sel);
566 }
567
568 void action_listevent(UiEvent *event, void *data) {
569 printf("%s: %d\n", data, event->intval);
570 UiListSelection *sel = event->eventdata;
571 for(int i=0;i<sel->count;i++) {
572 printf("sel: %d\n", sel->rows[i]);
573 }
574 printf("\n");
575 }
576
577 void application_startup(UiEvent *event, void *data) {
578
579 menulist = ui_list_new(ui_global_context(), "menulist");
580 ui_list_append(menulist, "Item 1");
581 ui_list_append(menulist, "Item 2");
582 ui_list_append(menulist, "Item 3");
583 ui_list_append(menulist, "Item 4");
584
585 UiObject *obj = ui_window("Test", NULL);
586
587 WData *wdata = ui_malloc(obj->ctx, sizeof(WData));
588 wdata->path = ui_string_new(obj->ctx, NULL);
589 wdata->list = ui_list_new(obj->ctx, NULL);
590 obj->window = wdata;
591
592 ui_list_append(wdata->list, "List Item 1");
593 ui_list_append(wdata->list, "List Item 2");
594 ui_list_append(wdata->list, "List Item 3");
595 ui_list_append(wdata->list, "List Item 4");
596
597 ui_button(obj, .label = "Add Menu Item", .onclick = action_button, .name = "mybutton1");
598 ui_button(obj, .label = "Add List Item", .onclick = action_button2);
599 ui_progressbar(obj, .name = "pb");
600 ui_listview(obj, .list = wdata->list, .fill = UI_ON, .multiselection = TRUE,
601 .onactivate = action_listevent, .onactivatedata = "activate",
602 .onselection = action_listevent, .onselectiondata = "selection");
603
604
605 ui_show(obj);
606 }
607
608 void action_test(UiEvent *event, void *data) {
609 printf("action test\n");
610 }
611
612 int main(int argc, char** argv) {
613 ui_init("app1", argc, argv);
614 ui_onstartup(application_startup, NULL);
615
616 // menu
617 ui_menu("File") {
618 ui_menuitem(.label = "Test 1", .onclick = action_test);
619 ui_menuitem(.label = "Test 2", .onclick = action_test);
620 ui_menuitem(.label = "Test 3", .onclick = action_test);
621 ui_menuseparator();
622 ui_menu_toggleitem(.label = "Toggle 1");
623 ui_menu_toggleitem(.label = "Toggle 2");
624 ui_menuseparator();
625 ui_menu_radioitem(.label = "Radio 1", .varname = "menu_radio");
626 ui_menu_radioitem(.label = "Radio 2", .varname = "menu_radio");
627 ui_menu_radioitem(.label = "Radio 3", .varname = "menu_radio");
628 ui_menu_radioitem(.label = "Radio 4", .varname = "menu_radio");
629 ui_menuseparator();
630 ui_menu_itemlist(.varname = "menulist");
631 ui_menuseparator();
632 ui_menuitem(.label = "Quit");
633 }
634
635 ui_main();
636 return (EXIT_SUCCESS);
637 }
638
639 #endif

mercurial