1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <Windows.h>
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <stdbool.h>
34
35 #include <ui/ui.h>
36
37 #include <stdio.h>
38 #include <stdlib.h>
39
40 #include <ui/ui.h>
41
42
43 typedef struct {
44 UiString *str1;
45 UiString *str2;
46 UiString *path;
47 UiText *text;
48 UiDouble *progress;
49 UiList *list;
50 UiList *menulist;
51 UiInteger *radio;
52 UiInteger *tabview;
53 UiGeneric *image;
54 } MyDocument;
55
56 MyDocument *doc1;
57 MyDocument *doc2;
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 }
89
90 void action_menu(UiEvent *event,
void *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 }
102 }
103
104 void action_button(UiEvent *event,
void *userdata) {
105 ui_openfiledialog(event->obj,
UI_FILEDIALOG_SELECT_SINGLE, action_file_selected,
NULL);
106 }
107
108 void action_switch(UiEvent *event,
void *userdata) {
109
110 }
111
112 void action_toolbar_button(UiEvent *event,
void *userdata) {
113 printf(
"toolbar button\n");
114
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_toolbar_dialog(UiEvent *event,
void *userdata) {
123
124 UiObject *dialog = ui_dialog_window(event->obj, .title =
"Dialog Window", .lbutton1 =
"Cancel 1", .lbutton2 =
"Btn 2", .rbutton3 =
"Btn3", .rbutton4 =
"Login 4", .onclick = action_dialog_button, .default_button =
4, .show_closebutton =
UI_OFF);
125
126 ui_vbox(dialog, .margin =
10, .spacing =
10) {
127 ui_label(dialog, .label =
"Enter password:");
128 ui_passwordfield(dialog, .varname =
"password");
129 }
130
131 ui_show(dialog);
132 }
133
134 UiObject *new_window;
135
136 static void action_unref_newwindow(UiEvent *event,
void *userdata) {
137 ui_object_unref(event->obj);
138 new_window =
NULL;
139 }
140
141 void action_toolbar_newwindow(UiEvent *event,
void *userdata) {
142 if (new_window) {
143 ui_show(new_window);
144 return;
145 }
146
147 UiObject *obj = ui_simple_window(
"New Window",
NULL);
148 new_window = obj;
149 ui_object_ref(obj);
150
151 ui_headerbar0(obj) {
152 ui_headerbar_start(obj) {
153 ui_button(obj, .label =
"Open");
154 }
155 ui_headerbar_end(obj) {
156 ui_button(obj, .label =
"Unref", .onclick = action_unref_newwindow);
157 }
158 }
159
160 ui_textarea(obj, .varname=
"text");
161
162 ui_show(obj);
163 }
164
165 MyDocument* create_doc(
void) {
166 MyDocument *doc = ui_document_new(
sizeof(MyDocument));
167 UiContext *docctx = ui_document_context(doc);
168 doc->str1 = ui_string_new(docctx,
"str1");
169 doc->str1 = ui_string_new(docctx,
"str2");
170 doc->path = ui_string_new(docctx,
"path");
171 doc->progress = ui_double_new(docctx,
"progress");
172 doc->list = ui_list_new(docctx,
"list");
173 ui_list_append(doc->list,
"test1");
174 ui_list_append(doc->list,
"test2");
175 ui_list_append(doc->list,
"test3");
176 doc->radio = ui_int_new(docctx,
"radio");
177 doc->tabview = ui_int_new(docctx,
"tabview");
178 doc->image = ui_generic_new(docctx,
"image");
179
180 return doc;
181 }
182
183 UiIcon *icon =
NULL;
184
185 static void* list_getvalue(
void *elm,
int col) {
186
187
188
189
190
191
192
193
194
195 char *str = elm;
196 return col ==
0 ? str :
"x";
197 }
198
199 static UiList *menu_list;
200 int new_item_count =
0;
201
202 void action_add_menu_item(UiEvent *event,
void *userdata) {
203 char str[
64];
204 snprintf(str,
64,
"new item %d", new_item_count++);
205
206 ui_list_append(menu_list, strdup(str));
207 ui_list_notify(menu_list);
208 }
209
210 void action_menu_list(UiEvent *event,
void *userdata) {
211 printf(
"menu list item: %d\n", event->intval);
212 }
213
214 static int tab_x =
0;
215 void action_tab2_button(UiEvent *event,
void *userdata) {
216 MyDocument *doc = event->document;
217 printf(
"current page: %d\n", (
int)ui_get(doc->tabview));
218 ui_set(doc->tabview,
0);
219 }
220
221
222 void action_group1(UiEvent *event,
void *userdata) {
223 UiContext *ctx = event->obj->ctx;
224 if(userdata) {
225 ui_unset_group(ctx,
1);
226 }
else {
227 ui_set_group(ctx,
1);
228 }
229 }
230
231 void action_group2(UiEvent *event,
void *userdata) {
232 UiContext *ctx = event->obj->ctx;
233 if(userdata) {
234 ui_unset_group(ctx,
2);
235 }
else {
236 ui_set_group(ctx,
2);
237 }
238 }
239
240 void application_startup(UiEvent *event,
void *data) {
241
242 UiContext *global = ui_global_context();
243 menu_list = ui_list_new(global,
"menulist");
244 ui_list_append(menu_list,
"menu list item 1");
245 ui_list_append(menu_list,
"menu list item 2");
246 ui_list_append(menu_list,
"menu list item 3");
247
248
249
250 UiObject *obj = ui_window(
"Test",
NULL);
251
252 MyDocument *doc = create_doc();
253 ui_attach_document(obj->ctx, doc);
254
255 ui_tabview(obj, .spacing=
10, .margin=
10, .tabview =
UI_TABVIEW_NAVIGATION_SIDE, .varname=
"tabview") {
256 ui_tab(obj,
"Tab 1") {
257 ui_vbox(obj, .fill =
UI_OFF, .margin =
15, .spacing =
15) {
258 ui_button(obj, .label =
"Test Button", .icon =
"application-x-generic", .onclick = action_button);
259 ui_togglebutton(obj, .label =
"Toggle");
260 ui_checkbox(obj, .label =
"My Checkbox");
261 }
262 ui_grid(obj, .fill =
UI_OFF, .columnspacing =
15, .rowspacing =
15, .margin =
15) {
263 ui_button(obj, .label =
"Activate Group 1", .hexpand =
TRUE, .onclick = action_group1);
264 ui_button(obj, .label =
"Disable Group 1", .onclick = action_group1, .onclickdata =
"disable");
265 ui_newline(obj);
266 ui_button(obj, .label =
"Activate Group 2", .hexpand =
TRUE, .onclick = action_group2);
267 ui_button(obj, .label =
"Disable Group 2", .onclick = action_group2, .onclickdata =
"disable");
268 ui_newline(obj);
269
270 ui_button(obj, .label =
"Groups 1,2", .colspan =
2, .groups =
UI_GROUPS(
1,
2));
271 ui_newline(obj);
272
273 ui_label(obj, .label =
"Label Col 1", .align =
UI_ALIGN_LEFT);
274 ui_label(obj, .label =
"Label Col 2", .style =
UI_LABEL_STYLE_TITLE, .align =
UI_ALIGN_RIGHT);
275 ui_newline(obj);
276
277
278
279
280 ui_progressbar(obj, .colspan =
2, .varname =
"progress");
281 ui_set(doc->progress,
0.75);
282 ui_newline(obj);
283
284 ui_textfield(obj, .value = doc->str1);
285 ui_newline(obj);
286
287
288 ui_path_textfield(obj, .varname =
"path");
289 ui_set(doc->path,
"/test/path/longdirectoryname/123");
290 ui_newline(obj);
291
292
293
294 ui_combobox(obj, .hexpand = true, .vexpand = false, .colspan =
2, .varname =
"list", .getvalue = list_getvalue);
295 ui_newline(obj);
296
297 ui_hbox0(obj) {
298 ui_radiobutton(obj, .label =
"Radio 1", .varname =
"radio");
299 ui_radiobutton(obj, .label =
"Radio 2", .varname =
"radio");
300 ui_radiobutton(obj, .label =
"Radio 3", .varname =
"radio");
301 }
302 }
303 }
304 ui_tab(obj,
"Tab 2") {
305 ui_button(obj, .label =
"Button 1 Start Thread", .onclick=action_start_thread);
306 ui_button(obj, .label =
"Button 2 Notify Thread", .onclick=action_notify_thread);
307 ui_button(obj, .label =
"Button 3", .onclick=action_tab2_button);
308 ui_button(obj, .label =
"Button 4", .onclick=action_tab2_button);
309 ui_button(obj, .label =
"Button 5", .onclick=action_tab2_button);
310 ui_button(obj, .label =
"Button 6", .onclick=action_tab2_button);
311 }
312 ui_tab(obj,
"Tab 3") {
313 UiTabViewArgs args = {
0};
314 UI_CTN(obj, tabview=ui_tabview_create(obj, &args)) {
315 UiObject *tab1 = ui_tabview_add(tabview,
"Sub 1",
-1);
316 ui_button(tab1, .label =
"Button 1");
317
318
319 UiObject *tab2 = ui_tabview_add(tabview,
"Sub 2",
-1);
320 ui_button(tab2, .label =
"Button 2");
321 }
322 }
323 ui_tab(obj,
"Tab 4") {
324 ui_grid0(obj) {
325 ui_button(obj, .label =
"test1");
326 ui_newline(obj);
327 ui_textarea(obj, .varname =
"text", .vexpand =
TRUE, .hexpand =
TRUE);
328 }
329 }
330 ui_tab(obj,
"Tab 5") {
331 ui_button(obj, .label =
"Test Button", .icon =
"application-x-generic", .onclick = action_button);
332 ui_imageviewer(obj, .varname =
"image", .style_class =
"imageviewer");
333 }
334
335 ui_tab(obj,
"Tab 6") {
336 ui_scrolledwindow(obj, .fill =
UI_ON) {
337 ui_expander(obj, .label =
"Expander", .margin =
10, .spacing =
10) {
338 ui_label(obj, .label =
"Test");
339 ui_button(obj, .label =
"Button");
340 }
341
342 ui_frame(obj, .label =
"Frame", .margin =
10, .spacing =
10) {
343 ui_label(obj, .label =
"Title", .style =
UI_LABEL_STYLE_TITLE);
344 ui_label(obj, .label =
"Sub-Title", .style =
UI_LABEL_STYLE_SUBTITLE);
345 ui_label(obj, .label =
"Dim Label", .style =
UI_LABEL_STYLE_DIM);
346 ui_label(obj, .label =
"No Style");
347 }
348
349 for(
int i=
0;i<
100;i++) {
350 char labelstr[
32];
351 snprintf(labelstr,
32,
"button %d", i);
352 ui_button(obj, .label = labelstr);
353 }
354 }
355 }
356 }
357
358
359
360
361
362 ui_show(obj);
363 }
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702 int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow)
703 {
704 ui_init(
"app1",
NULL,
0);
705 ui_onstartup(application_startup,
NULL);
706
707
708 ui_menu(
"File") {
709 ui_menuitem(.label =
"Test");
710 }
711
712 ui_toolbar_item(
"Test", .label =
"Test", .onclick = action_toolbar_button);
713 ui_toolbar_item(
"Test2", .label =
"New Window", .onclick = action_toolbar_newwindow);
714 ui_toolbar_item(
"Test3", .label =
"Dialog", .onclick = action_toolbar_dialog);
715 ui_toolbar_item(
"Test4", .label =
"Test 4", .onclick = action_toolbar_button);
716 ui_toolbar_item(
"Test5", .label =
"Test 5", .onclick = action_toolbar_button);
717 ui_toolbar_item(
"Test6", .label =
"Test 6", .onclick = action_toolbar_button);
718 ui_toolbar_toggleitem(
"Toggle", .label =
"Toggle", .onchange = action_toolbar_button);
719 ui_toolbar_menu(
"Menu", .label =
"Menu") {
720 ui_menuitem(
"Secondary Test", .onclick = action_toolbar_button,
NULL);
721 ui_menu(
"Secondary Sub") {
722 ui_menuitem(
"Secondary subitem",
NULL,
NULL);
723 }
724 ui_menuseparator();
725 ui_menu_itemlist(.varname =
"menulist", .onselect=action_menu_list);
726 ui_menuseparator();
727 ui_menuitem(
"last", .onclick = action_add_menu_item);
728 }
729
730 ui_toolbar_appmenu() {
731 ui_menuitem(
"New");
732 ui_menuitem(
"Open");
733 ui_menuitem(
"Save");
734
735 ui_menuseparator();
736
737 ui_menuitem(
"Close");
738 }
739
740 ui_toolbar_add_default(
"Test",
UI_TOOLBAR_LEFT);
741 ui_toolbar_add_default(
"Test6",
UI_TOOLBAR_LEFT);
742 ui_toolbar_add_default(
"Toggle",
UI_TOOLBAR_LEFT);
743 ui_toolbar_add_default(
"Menu",
UI_TOOLBAR_LEFT);
744
745 ui_toolbar_add_default(
"Test2",
UI_TOOLBAR_CENTER);
746 ui_toolbar_add_default(
"Test3",
UI_TOOLBAR_CENTER);
747
748 ui_toolbar_add_default(
"Test4",
UI_TOOLBAR_RIGHT);
749 ui_toolbar_add_default(
"Test5",
UI_TOOLBAR_RIGHT);
750
751 ui_main();
752
753 return (
EXIT_SUCCESS);
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805 }
806