make/vs/testapp/main.c

changeset 431
bb7da585debc
parent 379
958bae372271
equal deleted inserted replaced
169:fe49cff3c571 431:bb7da585debc
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
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 void action_toolbar_newwindow(UiEvent *event, void *userdata) {
135 UiObject *obj = ui_simple_window("New Window", NULL);
136
137 ui_headerbar0(obj) {
138 ui_headerbar_start(obj) {
139 ui_button(obj, .label = "Open");
140 }
141 ui_headerbar_end(obj) {
142 ui_button(obj, .label = "Test");
143 }
144 }
145
146 ui_textarea(obj, .varname="text");
147
148 ui_show(obj);
149 }
150
151 MyDocument* create_doc(void) {
152 MyDocument *doc = ui_document_new(sizeof(MyDocument));
153 UiContext *docctx = ui_document_context(doc);
154 doc->str1 = ui_string_new(docctx, "str1");
155 doc->str1 = ui_string_new(docctx, "str2");
156 doc->path = ui_string_new(docctx, "path");
157 doc->progress = ui_double_new(docctx, "progress");
158 doc->list = ui_list_new(docctx, "list");
159 ui_list_append(doc->list, "test1");
160 ui_list_append(doc->list, "test2");
161 ui_list_append(doc->list, "test3");
162 doc->radio = ui_int_new(docctx, "radio");
163 doc->tabview = ui_int_new(docctx, "tabview");
164 doc->image = ui_generic_new(docctx, "image");
165 //doc->text = ui_text_new(docctx, "text");
166 return doc;
167 }
168
169 UiIcon *icon = NULL;
170
171 static void* list_getvalue(void *elm, int col) {
172 /*
173 if(col == 0) {
174 if(!icon) {
175 icon = ui_icon("folder", 24);
176 }
177 return icon;
178 }
179 */
180
181 char *str = elm;
182 return col == 0 ? str : "x";
183 }
184
185 static UiList *menu_list;
186 int new_item_count = 0;
187
188 void action_add_menu_item(UiEvent *event, void *userdata) {
189 char str[64];
190 snprintf(str, 64, "new item %d", new_item_count++);
191
192 ui_list_append(menu_list, strdup(str));
193 ui_list_notify(menu_list);
194 }
195
196 void action_menu_list(UiEvent *event, void *userdata) {
197 printf("menu list item: %d\n", event->intval);
198 }
199
200 static int tab_x = 0;
201 void action_tab2_button(UiEvent *event, void *userdata) {
202 MyDocument *doc = event->document;
203 printf("current page: %d\n", (int)ui_get(doc->tabview));
204 ui_set(doc->tabview, 0);
205 }
206
207
208 void action_group1(UiEvent *event, void *userdata) {
209 UiContext *ctx = event->obj->ctx;
210 if(userdata) {
211 ui_unset_group(ctx, 1);
212 } else {
213 ui_set_group(ctx, 1);
214 }
215 }
216
217 void action_group2(UiEvent *event, void *userdata) {
218 UiContext *ctx = event->obj->ctx;
219 if(userdata) {
220 ui_unset_group(ctx, 2);
221 } else {
222 ui_set_group(ctx, 2);
223 }
224 }
225
226 void application_startup(UiEvent *event, void *data) {
227 // global list
228 UiContext *global = ui_global_context();
229 menu_list = ui_list_new(global, "menulist");
230 ui_list_append(menu_list, "menu list item 1");
231 ui_list_append(menu_list, "menu list item 2");
232 ui_list_append(menu_list, "menu list item 3");
233
234
235
236 UiObject *obj = ui_window("Test", NULL);
237
238 MyDocument *doc = create_doc();
239 ui_attach_document(obj->ctx, doc);
240
241 ui_tabview(obj, .spacing=10, .margin=10, .tabview = UI_TABVIEW_NAVIGATION_SIDE, .varname="tabview") {
242 ui_tab(obj, "Tab 1") {
243 ui_vbox(obj, .fill = UI_OFF, .margin = 15, .spacing = 15) {
244 ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button);
245 ui_togglebutton(obj, .label = "Toggle");
246 ui_checkbox(obj, .label = "My Checkbox");
247 }
248 ui_grid(obj, .fill = UI_OFF, .columnspacing = 15, .rowspacing = 15, .margin = 15) {
249 ui_button(obj, .label = "Activate Group 1", .hexpand = TRUE, .onclick = action_group1);
250 ui_button(obj, .label = "Disable Group 1", .onclick = action_group1, .onclickdata = "disable");
251 ui_newline(obj);
252 ui_button(obj, .label = "Activate Group 2", .hexpand = TRUE, .onclick = action_group2);
253 ui_button(obj, .label = "Disable Group 2", .onclick = action_group2, .onclickdata = "disable");
254 ui_newline(obj);
255
256 ui_button(obj, .label = "Groups 1,2", .colspan = 2, .groups = UI_GROUPS(1, 2));
257 ui_newline(obj);
258
259 ui_label(obj, .label = "Label Col 1", .align = UI_ALIGN_LEFT);
260 ui_label(obj, .label = "Label Col 2", .style = UI_LABEL_STYLE_TITLE, .align = UI_ALIGN_RIGHT);
261 ui_newline(obj);
262
263 //ui_spinner(obj, .step = 5);
264 //ui_newline(obj);
265
266 ui_progressbar(obj, .colspan = 2, .varname = "progress");
267 ui_set(doc->progress, 0.75);
268 ui_newline(obj);
269
270 ui_textfield(obj, .value = doc->str1);
271 ui_newline(obj);
272
273 //ui_button(obj, .label="Test");
274 ui_path_textfield(obj, .varname = "path");
275 ui_set(doc->path, "/test/path/longdirectoryname/123");
276 ui_newline(obj);
277
278 //UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1);
279 //model->getvalue = list_getvalue;
280 ui_combobox(obj, .hexpand = true, .vexpand = false, .colspan = 2, .varname = "list", .getvalue = list_getvalue);
281 ui_newline(obj);
282
283 ui_hbox0(obj) {
284 ui_radiobutton(obj, .label = "Radio 1", .varname = "radio");
285 ui_radiobutton(obj, .label = "Radio 2", .varname = "radio");
286 ui_radiobutton(obj, .label = "Radio 3", .varname = "radio");
287 }
288 }
289 }
290 ui_tab(obj, "Tab 2") {
291 ui_button(obj, .label = "Button 1 Start Thread", .onclick=action_start_thread);
292 ui_button(obj, .label = "Button 2 Notify Thread", .onclick=action_notify_thread);
293 ui_button(obj, .label = "Button 3", .onclick=action_tab2_button);
294 ui_button(obj, .label = "Button 4", .onclick=action_tab2_button);
295 ui_button(obj, .label = "Button 5", .onclick=action_tab2_button);
296 ui_button(obj, .label = "Button 6", .onclick=action_tab2_button);
297 }
298 ui_tab(obj, "Tab 3") {
299 UiTabViewArgs args = {0};
300 UI_CTN(obj, tabview=ui_tabview_create(obj, args)) {
301 UiObject *tab1 = ui_tabview_add(tabview, "Sub 1", -1);
302 ui_button(tab1, .label = "Button 1");
303
304
305 UiObject *tab2 = ui_tabview_add(tabview, "Sub 2", -1);
306 ui_button(tab2, .label = "Button 2");
307 }
308 }
309 ui_tab(obj, "Tab 4") {
310 ui_grid0(obj) {
311 ui_button(obj, .label = "test1");
312 ui_newline(obj);
313 ui_textarea(obj, .varname = "text", .vexpand = TRUE, .hexpand = TRUE);
314 }
315 }
316 ui_tab(obj, "Tab 5") {
317 ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button);
318 ui_imageviewer(obj, .varname = "image", .style_class = "imageviewer");
319 }
320
321 ui_tab(obj, "Tab 6") {
322 ui_scrolledwindow(obj, .fill = UI_ON) {
323 ui_expander(obj, .label = "Expander", .margin = 10, .spacing = 10) {
324 ui_label(obj, .label = "Test");
325 ui_button(obj, .label = "Button");
326 }
327
328 ui_frame(obj, .label = "Frame", .margin = 10, .spacing = 10) {
329 ui_label(obj, .label = "Title", .style = UI_LABEL_STYLE_TITLE);
330 ui_label(obj, .label = "Sub-Title", .style = UI_LABEL_STYLE_SUBTITLE);
331 ui_label(obj, .label = "Dim Label", .style = UI_LABEL_STYLE_DIM);
332 ui_label(obj, .label = "No Style");
333 }
334
335 for(int i=0;i<100;i++) {
336 char labelstr[32];
337 snprintf(labelstr, 32, "button %d", i);
338 ui_button(obj, .label = labelstr);
339 }
340 }
341 }
342 }
343
344 /*
345
346 */
347
348 ui_show(obj);
349 }
350
351 /*
352 typedef struct WindowData {
353 UiInteger* check;
354 UiInteger* toggle;
355 UiInteger* radio;
356 UiString* text;
357 UiString* password;
358 UiList* list;
359 UiString* t1;
360 UiString* t2;
361 UiString* t3;
362 UiString* path;
363 UiList* list2;
364 UiList* list3;
365 UiDouble* progress;
366 UiInteger* spinner;
367 } WindowData;
368
369 static UiIcon* folder_icon;
370
371 UiList* menuList;
372
373 void event_mt(UiEvent* event, void* data) {
374 char* mt_str = data;
375
376 printf("%s\n", mt_str);
377 }
378
379 int test_threadfunc(void *data) {
380 char* str = data;
381
382 return 0;
383 }
384
385 void action_thread_test(UiEvent* event, void* data) {
386 ui_job(event->obj, test_threadfunc, "testdata", event_mt, "testdata2");
387 }
388
389 void action1(UiEvent* event, void* data) {
390 char* action = data;
391
392 WindowData* wdata = event->window;
393 int64_t is_checked = ui_get(wdata->check);
394 int64_t radio = ui_get(wdata->radio);
395
396 printf("data: %s %d\n", data, is_checked);
397
398 double d = ui_get(wdata->progress);
399 ui_set(wdata->progress, d + 1);
400
401 int spinner_active = ui_get(wdata->spinner);
402 ui_set(wdata->spinner, !spinner_active);
403
404 ui_list_append(menuList, "List Item X");
405 ui_list_append(menuList, "List Item X");
406 ui_notify(menuList->observers, NULL);
407 }
408
409 void action_set_checkbox(UiEvent* event, void* data) {
410 char* action = data;
411
412 WindowData* wdata = event->window;
413 wdata->check->set(wdata->check, 1);
414 }
415
416 void action_onchange(UiEvent* event, void* data) {
417 printf("onchange: %d\n", event->intval);
418 }
419
420 void action_switch(UiEvent* event, void* data) {
421 printf("onchange: %d\n", event->intval);
422 }
423
424 void action_toolbar_button(UiEvent* event, void *data) {
425 printf("toolbar action\n");
426 }
427
428
429 void action_listselection_changed(UiEvent* event, void* data) {
430 printf("selection changed\n");
431 UiListSelection* sel = event->eventdata;
432 for (int i = 0; i < sel->count; i++) {
433 int row = sel->rows[i];
434 printf("row: %d\n", row);
435 }
436 }
437
438 void action_onactivate(UiEvent* event, void* Data) {
439 printf("activate\n");
440 UiListSelection* sel = event->eventdata;
441 for (int i = 0; i < sel->count; i++) {
442 int row = sel->rows[i];
443 printf("row: %d\n", row);
444 }
445 }
446
447 typedef struct TableData {
448 char* col1;
449 char* col2;
450 char* col3;
451 } TableData;
452
453 void* table_getvalue(void* data, int i) {
454 TableData* t = data;
455 switch (i) {
456 case 0: return folder_icon;
457 case 1: return t->col1;
458 case 2: return t->col2;
459 case 3: return t->col3;
460 }
461 return NULL;
462 }
463
464 void action_add(UiEvent* event, void* data) {
465 WindowData* wdata = event->window;
466 char* t1 = wdata->t1->get(wdata->t1);
467 char* t2 = wdata->t2->get(wdata->t2);
468 char* t3 = wdata->t3->get(wdata->t3);
469
470 TableData* tdat = malloc(sizeof(TableData));
471 tdat->col1 = _strdup(t1);
472 tdat->col2 = _strdup(t2);
473 tdat->col3 = _strdup(t3);
474 ui_list_append(wdata->list2, tdat);
475 wdata->list2->update(wdata->list2, 0);
476
477 }
478
479 void action_breadcrumb(UiEvent* event, void* data) {
480 int i = event->intval;
481 char* c = event->eventdata;
482 printf("index: %d\n", i);
483 }
484
485 void dragstart(UiEvent* event, void* data) {
486 UiListDnd* ldnd = event->eventdata;
487 ui_selection_settext(ldnd->dnd, "Hello World!", -1);
488 }
489
490 void dragcomplete(UiEvent* event, void* data) {
491
492 }
493
494 void dragover(UiEvent* event, void* data) {
495
496 }
497
498 void drop(UiEvent* event, void* data) {
499
500 }
501
502 void dialog_result(UiEvent *evt, void *data) {
503 char *str = evt->eventdata;
504 printf("dialog: %d\n", (int)evt->intval);
505 }
506
507 void btn_dialog(UiEvent *evt, void *data) {
508 ui_dialog(evt->obj, .title = "Title", .input = TRUE, .content = "Hello World", .button1_label = "Yes", .button2_label = "No", .closebutton_label = "Close", .result = dialog_result);
509 }
510
511
512
513
514 void application_startup(UiEvent* event, void* data) {
515 UiContext* gctx = ui_global_context();
516 menuList = ui_list_new(gctx, "menulist");
517 ui_list_append(menuList, "List Item 1");
518 ui_list_append(menuList, "List Item 2");
519 ui_list_append(menuList, "List Item 3");
520 ui_list_append(menuList, "List Item 4");
521 ui_list_append(menuList, "List Item 5");
522 ui_list_append(menuList, "List Item 6");
523
524 UiObject* obj = ui_window("Test", NULL);
525 WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData));
526 obj->window = wdata;
527 wdata->check = ui_int_new(obj->ctx, "check");
528 wdata->toggle = ui_int_new(obj->ctx, "toggle");
529 wdata->radio = ui_int_new(obj->ctx, "radio");
530 wdata->text = ui_string_new(obj->ctx, "text");
531 wdata->password = ui_string_new(obj->ctx, "password");
532 wdata->list = ui_list_new(obj->ctx, "list");
533 wdata->list2 = ui_list_new(obj->ctx, "list2");
534 wdata->list3 = ui_list_new(obj->ctx, "list3");
535 wdata->t1 = ui_string_new(obj->ctx, "t1");
536 wdata->t2 = ui_string_new(obj->ctx, "t2");
537 wdata->t3 = ui_string_new(obj->ctx, "t3");
538 wdata->path = ui_string_new(obj->ctx, "path");
539 wdata->progress = ui_double_new(obj->ctx, "progress");
540 wdata->spinner = ui_int_new(obj->ctx, "spinner");
541
542 ui_list_append(wdata->list, "Hello");
543 ui_list_append(wdata->list, "World");
544 ui_list_append(wdata->list, "Item3");
545 ui_list_append(wdata->list, "Item4");
546 ui_list_append(wdata->list, "Item5");
547 ui_list_append(wdata->list, "Item6");
548
549 ui_list_append(wdata->list3, "usr");
550 ui_list_append(wdata->list3, "share");
551 ui_list_append(wdata->list3, "test");
552 ui_list_append(wdata->list3, "dir");
553
554 //folder_icon = ui_icon("Folder", 32);
555 folder_icon = ui_foldericon(16);
556
557 TableData* td1 = malloc(sizeof(TableData));
558 TableData* td2 = malloc(sizeof(TableData));
559 TableData* td3 = malloc(sizeof(TableData));
560 TableData* td4 = malloc(sizeof(TableData));
561 TableData* td5 = malloc(sizeof(TableData));
562 TableData* td6 = malloc(sizeof(TableData));
563 td1->col1 = "a1";
564 td1->col2 = "b1";
565 td1->col3 = "c1";
566 td2->col1 = "a2";
567 td2->col2 = "b2";
568 td2->col3 = "b3";
569 td3->col1 = "a3";
570 td3->col2 = "b3";
571 td3->col3 = "c3";
572 td4->col1 = "a3";
573 td4->col2 = "b3";
574 td4->col3 = "c3";
575 td5->col1 = "a3";
576 td5->col2 = "b3";
577 td5->col3 = "c3";
578 td6->col1 = "a3";
579 td6->col2 = "b3";
580 td6->col3 = "c3";
581
582 ui_list_append(wdata->list2, td1);
583 ui_list_append(wdata->list2, td2);
584 ui_list_append(wdata->list2, td3);
585 ui_list_append(wdata->list2, td4);
586 ui_list_append(wdata->list2, td5);
587 ui_list_append(wdata->list2, td6);
588
589 ui_scrolledwindow0(obj) {
590 ui_grid(obj, .margin = 10, .columnspacing = 5, .rowspacing = 20) {
591 ui_button(obj, .label = "Thread Test", .onclick = action_thread_test, .onclickdata = "action1");
592 ui_button(obj, .label = "Button2", .icon = "Back", .onclick = action1, .onclickdata = "action2");
593 ui_button(obj, .icon = "Forward", .onclick = action1, .onclickdata = "action3", .hexpand = true);
594 ui_newline(obj);
595
596 ui_button(obj, .label = "Dialog Test", .onclick = btn_dialog, .onclickdata = "action4");
597 ui_button(obj, .label = "Button5", .onclick = action1, .onclickdata = "action5", .colspan = 2);
598 ui_newline(obj);
599
600 ui_button(obj, .label = "Very Long Button Label Text ____________ Test", .onclick = action_set_checkbox);
601 ui_newline(obj);
602
603 ui_checkbox(obj, .label = "Option 1", .value = wdata->check, .onchange = action_onchange);
604 ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle);
605 ui_newline(obj);
606
607 ui_label(obj, .label = "Progress");
608 ui_progressspinner(obj, .value = wdata->spinner);
609 ui_newline(obj);
610
611 ui_hbox(obj, .colspan = 3) {
612 ui_radiobutton(obj, .label = "Radio 1", .value = wdata->radio);
613 ui_radiobutton(obj, .label = "Radio 2", .value = wdata->radio);
614 ui_radiobutton(obj, .label = "Radio 3", .value = wdata->radio);
615 }
616 ui_newline(obj);
617 ui_radiobutton(obj, .label = "Radio 4", .value = wdata->radio);
618 ui_switch(obj, .label = "test", .onchange = action_switch);
619 ui_newline(obj);
620
621 //ui_breadcrumbbar(obj, .list = wdata->list3, .onactivate=action_breadcrumb);
622 ui_textfield(obj, .varname = "newtext");
623 ui_path_textfield(obj, .colspan = 2, .value=wdata->path, .onactivate = action_breadcrumb);
624 ui_newline(obj);
625 wdata->path->set(wdata->path, "/usr/path/test");
626
627 ui_textfield(obj, .value = wdata->text);
628 ui_passwordfield(obj, .value = wdata->password);
629 ui_newline(obj);
630
631 ui_frame(obj, .label = "Test", .colspan = 3) {
632 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
633 }
634 ui_newline(obj);
635
636 ui_expander(obj, .label = "Expand", .colspan = 3, .margin = 10, .spacing = 5, .isexpanded = false) {
637 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
638 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
639 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1");
640 }
641 ui_newline(obj);
642
643 ui_combobox(obj, .list = wdata->list, .onselection= action_listselection_changed, .onactivate= action_onactivate);
644 ui_newline(obj);
645
646 ui_tabview(obj, .colspan = 3, .vexpand = true, .hexpand = true, .tabview = UI_TABVIEW_NAVIGATION_SIDE) {
647 ui_tab(obj, "Tab 1") {
648 ui_button(obj, .label = "Tab 1 Button");
649 }
650 ui_tab(obj, "Tab 2") {
651 ui_button(obj, .label = "Tab 2 Button");
652 }
653 ui_tab(obj, "Tab 3") {
654
655 }
656 }
657 ui_newline(obj);
658
659 ui_label(obj, .label = "Test Label");
660 ui_progressbar(obj, .value = wdata->progress, .colspan = 2);
661 ui_newline(obj);
662
663 ui_newline(obj);
664 ui_textfield(obj, .value = wdata->t1);
665 ui_textfield(obj, .value = wdata->t2);
666 ui_textfield(obj, .value = wdata->t3);
667 ui_newline(obj);
668 ui_button(obj, .label = "Add", .onclick = action_add);
669 ui_newline(obj);
670
671
672 ui_newline(obj);
673
674 UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", UI_STRING, "Col 3", -1);
675 model->getvalue = table_getvalue;
676 ui_table(obj, .colspan = 3, .model = model, .list = wdata->list2, .onactivate = action_onactivate,
677 .onselection = action_listselection_changed,
678 .ondragstart = dragstart, .ondragcomplete = dragcomplete, .ondrop = drop);
679 ui_model_free(obj->ctx, model);
680 }
681 }
682
683 ui_show(obj);
684 }
685
686 */
687
688 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow)
689 {
690 ui_init("app1", NULL, 0);
691 ui_onstartup(application_startup, NULL);
692
693 // menu
694 ui_menu("File") {
695 ui_menuitem(.label = "Test");
696 }
697
698 ui_toolbar_item("Test", .label = "Test", .onclick = action_toolbar_button);
699 ui_toolbar_item("Test2", .label = "New Window", .onclick = action_toolbar_newwindow);
700 ui_toolbar_item("Test3", .label = "Dialog", .onclick = action_toolbar_dialog);
701 ui_toolbar_item("Test4", .label = "Test 4", .onclick = action_toolbar_button);
702 ui_toolbar_item("Test5", .label = "Test 5", .onclick = action_toolbar_button);
703 ui_toolbar_item("Test6", .label = "Test 6", .onclick = action_toolbar_button);
704 ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button);
705 ui_toolbar_menu("Menu", .label = "Menu") {
706 ui_menuitem("Secondary Test", .onclick = action_toolbar_button, NULL);
707 ui_menu("Secondary Sub") {
708 ui_menuitem("Secondary subitem", NULL, NULL);
709 }
710 ui_menuseparator();
711 ui_menu_itemlist(.varname = "menulist", .onselect=action_menu_list);
712 ui_menuseparator();
713 ui_menuitem("last", .onclick = action_add_menu_item);
714 }
715
716 ui_toolbar_appmenu() {
717 ui_menuitem("New");
718 ui_menuitem("Open");
719 ui_menuitem("Save");
720
721 ui_menuseparator();
722
723 ui_menuitem("Close");
724 }
725
726 ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT);
727 ui_toolbar_add_default("Test6", UI_TOOLBAR_LEFT);
728 ui_toolbar_add_default("Toggle", UI_TOOLBAR_LEFT);
729 ui_toolbar_add_default("Menu", UI_TOOLBAR_LEFT);
730
731 ui_toolbar_add_default("Test2", UI_TOOLBAR_CENTER);
732 ui_toolbar_add_default("Test3", UI_TOOLBAR_CENTER);
733
734 ui_toolbar_add_default("Test4", UI_TOOLBAR_RIGHT);
735 ui_toolbar_add_default("Test5", UI_TOOLBAR_RIGHT);
736
737 ui_main();
738
739 return (EXIT_SUCCESS);
740
741 /*
742 ui_init("app1", 0, NULL);
743 ui_onstartup(application_startup, NULL);
744
745 ui_menu("File") {
746 ui_menuitem(.label = "Item 1");
747 ui_menuitem(.label = "Item 2");
748 ui_menuseparator();
749 ui_menu("File Sub") {
750 ui_menuitem(.label = "Sub Item");
751 }
752
753 ui_menuitem(.label = "Exit");
754 }
755
756 ui_toolbar_item("Test", .label = "Home", .icon = "Home", .onclick = action_toolbar_button);
757 ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button);
758 ui_toolbar_toggleitem("Toggle2", .label = "Toggle2", .onchange = action_toolbar_button);
759 ui_toolbar_toggleitem("Toggle3", .label = "Toggle3", .onchange = action_toolbar_button);
760
761 ui_toolbar_menu("Menu", .label = "Menu") {
762
763 ui_menuitem(.label = "x", NULL, NULL);
764 ui_menuitem(.label = "x", NULL, NULL);
765 ui_menu_itemlist(.varname = "menulist");
766 ui_menuitem(.label = "x", NULL, NULL);
767 ui_menuitem(.label = "x", NULL, NULL);
768 ui_menuitem(.label = "x", NULL, NULL);
769 ui_menu("TB Sub") {
770 ui_menuitem("TB subitem", NULL, NULL);
771 }
772 }
773
774 ui_toolbar_menu(NULL, .label = "Menu") {
775 ui_menuitem("Secondary Test", NULL, NULL);
776 ui_menu("Secondary Sub") {
777 ui_menuitem("Secondary subitem", NULL, NULL);
778 }
779 }
780
781 ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT);
782 ui_toolbar_add_default("Toggle", UI_TOOLBAR_LEFT);
783 ui_toolbar_add_default("Toggle2", UI_TOOLBAR_CENTER);
784 ui_toolbar_add_default("Toggle3", UI_TOOLBAR_CENTER);
785 ui_toolbar_add_default("Menu", UI_TOOLBAR_RIGHT);
786
787 ui_main();
788
789 return (EXIT_SUCCESS);
790 */
791 }

mercurial