UNIXworkcode

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 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 //doc->text = ui_text_new(docctx, "text"); 180 return doc; 181 } 182 183 UiIcon *icon = NULL; 184 185 static void* list_getvalue(void *elm, int col) { 186 /* 187 if(col == 0) { 188 if(!icon) { 189 icon = ui_icon("folder", 24); 190 } 191 return icon; 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 // global list 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 //ui_spinner(obj, .step = 5); 278 //ui_newline(obj); 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 //ui_button(obj, .label="Test"); 288 ui_path_textfield(obj, .varname = "path"); 289 ui_set(doc->path, "/test/path/longdirectoryname/123"); 290 ui_newline(obj); 291 292 //UiModel *model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", -1); 293 //model->getvalue = list_getvalue; 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 typedef struct WindowData { 367 UiInteger* check; 368 UiInteger* toggle; 369 UiInteger* radio; 370 UiString* text; 371 UiString* password; 372 UiList* list; 373 UiString* t1; 374 UiString* t2; 375 UiString* t3; 376 UiString* path; 377 UiList* list2; 378 UiList* list3; 379 UiDouble* progress; 380 UiInteger* spinner; 381 } WindowData; 382 383 static UiIcon* folder_icon; 384 385 UiList* menuList; 386 387 void event_mt(UiEvent* event, void* data) { 388 char* mt_str = data; 389 390 printf("%s\n", mt_str); 391 } 392 393 int test_threadfunc(void *data) { 394 char* str = data; 395 396 return 0; 397 } 398 399 void action_thread_test(UiEvent* event, void* data) { 400 ui_job(event->obj, test_threadfunc, "testdata", event_mt, "testdata2"); 401 } 402 403 void action1(UiEvent* event, void* data) { 404 char* action = data; 405 406 WindowData* wdata = event->window; 407 int64_t is_checked = ui_get(wdata->check); 408 int64_t radio = ui_get(wdata->radio); 409 410 printf("data: %s %d\n", data, is_checked); 411 412 double d = ui_get(wdata->progress); 413 ui_set(wdata->progress, d + 1); 414 415 int spinner_active = ui_get(wdata->spinner); 416 ui_set(wdata->spinner, !spinner_active); 417 418 ui_list_append(menuList, "List Item X"); 419 ui_list_append(menuList, "List Item X"); 420 ui_notify(menuList->observers, NULL); 421 } 422 423 void action_set_checkbox(UiEvent* event, void* data) { 424 char* action = data; 425 426 WindowData* wdata = event->window; 427 wdata->check->set(wdata->check, 1); 428 } 429 430 void action_onchange(UiEvent* event, void* data) { 431 printf("onchange: %d\n", event->intval); 432 } 433 434 void action_switch(UiEvent* event, void* data) { 435 printf("onchange: %d\n", event->intval); 436 } 437 438 void action_toolbar_button(UiEvent* event, void *data) { 439 printf("toolbar action\n"); 440 } 441 442 443 void action_listselection_changed(UiEvent* event, void* data) { 444 printf("selection changed\n"); 445 UiListSelection* sel = event->eventdata; 446 for (int i = 0; i < sel->count; i++) { 447 int row = sel->rows[i]; 448 printf("row: %d\n", row); 449 } 450 } 451 452 void action_onactivate(UiEvent* event, void* Data) { 453 printf("activate\n"); 454 UiListSelection* sel = event->eventdata; 455 for (int i = 0; i < sel->count; i++) { 456 int row = sel->rows[i]; 457 printf("row: %d\n", row); 458 } 459 } 460 461 typedef struct TableData { 462 char* col1; 463 char* col2; 464 char* col3; 465 } TableData; 466 467 void* table_getvalue(void* data, int i) { 468 TableData* t = data; 469 switch (i) { 470 case 0: return folder_icon; 471 case 1: return t->col1; 472 case 2: return t->col2; 473 case 3: return t->col3; 474 } 475 return NULL; 476 } 477 478 void action_add(UiEvent* event, void* data) { 479 WindowData* wdata = event->window; 480 char* t1 = wdata->t1->get(wdata->t1); 481 char* t2 = wdata->t2->get(wdata->t2); 482 char* t3 = wdata->t3->get(wdata->t3); 483 484 TableData* tdat = malloc(sizeof(TableData)); 485 tdat->col1 = _strdup(t1); 486 tdat->col2 = _strdup(t2); 487 tdat->col3 = _strdup(t3); 488 ui_list_append(wdata->list2, tdat); 489 wdata->list2->update(wdata->list2, 0); 490 491 } 492 493 void action_breadcrumb(UiEvent* event, void* data) { 494 int i = event->intval; 495 char* c = event->eventdata; 496 printf("index: %d\n", i); 497 } 498 499 void dragstart(UiEvent* event, void* data) { 500 UiListDnd* ldnd = event->eventdata; 501 ui_selection_settext(ldnd->dnd, "Hello World!", -1); 502 } 503 504 void dragcomplete(UiEvent* event, void* data) { 505 506 } 507 508 void dragover(UiEvent* event, void* data) { 509 510 } 511 512 void drop(UiEvent* event, void* data) { 513 514 } 515 516 void dialog_result(UiEvent *evt, void *data) { 517 char *str = evt->eventdata; 518 printf("dialog: %d\n", (int)evt->intval); 519 } 520 521 void btn_dialog(UiEvent *evt, void *data) { 522 ui_dialog(evt->obj, .title = "Title", .input = TRUE, .content = "Hello World", .button1_label = "Yes", .button2_label = "No", .closebutton_label = "Close", .result = dialog_result); 523 } 524 525 526 527 528 void application_startup(UiEvent* event, void* data) { 529 UiContext* gctx = ui_global_context(); 530 menuList = ui_list_new(gctx, "menulist"); 531 ui_list_append(menuList, "List Item 1"); 532 ui_list_append(menuList, "List Item 2"); 533 ui_list_append(menuList, "List Item 3"); 534 ui_list_append(menuList, "List Item 4"); 535 ui_list_append(menuList, "List Item 5"); 536 ui_list_append(menuList, "List Item 6"); 537 538 UiObject* obj = ui_window("Test", NULL); 539 WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData)); 540 obj->window = wdata; 541 wdata->check = ui_int_new(obj->ctx, "check"); 542 wdata->toggle = ui_int_new(obj->ctx, "toggle"); 543 wdata->radio = ui_int_new(obj->ctx, "radio"); 544 wdata->text = ui_string_new(obj->ctx, "text"); 545 wdata->password = ui_string_new(obj->ctx, "password"); 546 wdata->list = ui_list_new(obj->ctx, "list"); 547 wdata->list2 = ui_list_new(obj->ctx, "list2"); 548 wdata->list3 = ui_list_new(obj->ctx, "list3"); 549 wdata->t1 = ui_string_new(obj->ctx, "t1"); 550 wdata->t2 = ui_string_new(obj->ctx, "t2"); 551 wdata->t3 = ui_string_new(obj->ctx, "t3"); 552 wdata->path = ui_string_new(obj->ctx, "path"); 553 wdata->progress = ui_double_new(obj->ctx, "progress"); 554 wdata->spinner = ui_int_new(obj->ctx, "spinner"); 555 556 ui_list_append(wdata->list, "Hello"); 557 ui_list_append(wdata->list, "World"); 558 ui_list_append(wdata->list, "Item3"); 559 ui_list_append(wdata->list, "Item4"); 560 ui_list_append(wdata->list, "Item5"); 561 ui_list_append(wdata->list, "Item6"); 562 563 ui_list_append(wdata->list3, "usr"); 564 ui_list_append(wdata->list3, "share"); 565 ui_list_append(wdata->list3, "test"); 566 ui_list_append(wdata->list3, "dir"); 567 568 //folder_icon = ui_icon("Folder", 32); 569 folder_icon = ui_foldericon(16); 570 571 TableData* td1 = malloc(sizeof(TableData)); 572 TableData* td2 = malloc(sizeof(TableData)); 573 TableData* td3 = malloc(sizeof(TableData)); 574 TableData* td4 = malloc(sizeof(TableData)); 575 TableData* td5 = malloc(sizeof(TableData)); 576 TableData* td6 = malloc(sizeof(TableData)); 577 td1->col1 = "a1"; 578 td1->col2 = "b1"; 579 td1->col3 = "c1"; 580 td2->col1 = "a2"; 581 td2->col2 = "b2"; 582 td2->col3 = "b3"; 583 td3->col1 = "a3"; 584 td3->col2 = "b3"; 585 td3->col3 = "c3"; 586 td4->col1 = "a3"; 587 td4->col2 = "b3"; 588 td4->col3 = "c3"; 589 td5->col1 = "a3"; 590 td5->col2 = "b3"; 591 td5->col3 = "c3"; 592 td6->col1 = "a3"; 593 td6->col2 = "b3"; 594 td6->col3 = "c3"; 595 596 ui_list_append(wdata->list2, td1); 597 ui_list_append(wdata->list2, td2); 598 ui_list_append(wdata->list2, td3); 599 ui_list_append(wdata->list2, td4); 600 ui_list_append(wdata->list2, td5); 601 ui_list_append(wdata->list2, td6); 602 603 ui_scrolledwindow0(obj) { 604 ui_grid(obj, .margin = 10, .columnspacing = 5, .rowspacing = 20) { 605 ui_button(obj, .label = "Thread Test", .onclick = action_thread_test, .onclickdata = "action1"); 606 ui_button(obj, .label = "Button2", .icon = "Back", .onclick = action1, .onclickdata = "action2"); 607 ui_button(obj, .icon = "Forward", .onclick = action1, .onclickdata = "action3", .hexpand = true); 608 ui_newline(obj); 609 610 ui_button(obj, .label = "Dialog Test", .onclick = btn_dialog, .onclickdata = "action4"); 611 ui_button(obj, .label = "Button5", .onclick = action1, .onclickdata = "action5", .colspan = 2); 612 ui_newline(obj); 613 614 ui_button(obj, .label = "Very Long Button Label Text ____________ Test", .onclick = action_set_checkbox); 615 ui_newline(obj); 616 617 ui_checkbox(obj, .label = "Option 1", .value = wdata->check, .onchange = action_onchange); 618 ui_togglebutton(obj, .label = "Option 2", .value = wdata->toggle); 619 ui_newline(obj); 620 621 ui_label(obj, .label = "Progress"); 622 ui_progressspinner(obj, .value = wdata->spinner); 623 ui_newline(obj); 624 625 ui_hbox(obj, .colspan = 3) { 626 ui_radiobutton(obj, .label = "Radio 1", .value = wdata->radio); 627 ui_radiobutton(obj, .label = "Radio 2", .value = wdata->radio); 628 ui_radiobutton(obj, .label = "Radio 3", .value = wdata->radio); 629 } 630 ui_newline(obj); 631 ui_radiobutton(obj, .label = "Radio 4", .value = wdata->radio); 632 ui_switch(obj, .label = "test", .onchange = action_switch); 633 ui_newline(obj); 634 635 //ui_breadcrumbbar(obj, .list = wdata->list3, .onactivate=action_breadcrumb); 636 ui_textfield(obj, .varname = "newtext"); 637 ui_path_textfield(obj, .colspan = 2, .value=wdata->path, .onactivate = action_breadcrumb); 638 ui_newline(obj); 639 wdata->path->set(wdata->path, "/usr/path/test"); 640 641 ui_textfield(obj, .value = wdata->text); 642 ui_passwordfield(obj, .value = wdata->password); 643 ui_newline(obj); 644 645 ui_frame(obj, .label = "Test", .colspan = 3) { 646 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); 647 } 648 ui_newline(obj); 649 650 ui_expander(obj, .label = "Expand", .colspan = 3, .margin = 10, .spacing = 5, .isexpanded = false) { 651 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); 652 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); 653 ui_button(obj, .label = "Button1", .onclick = action1, .onclickdata = "action1"); 654 } 655 ui_newline(obj); 656 657 ui_combobox(obj, .list = wdata->list, .onselection= action_listselection_changed, .onactivate= action_onactivate); 658 ui_newline(obj); 659 660 ui_tabview(obj, .colspan = 3, .vexpand = true, .hexpand = true, .tabview = UI_TABVIEW_NAVIGATION_SIDE) { 661 ui_tab(obj, "Tab 1") { 662 ui_button(obj, .label = "Tab 1 Button"); 663 } 664 ui_tab(obj, "Tab 2") { 665 ui_button(obj, .label = "Tab 2 Button"); 666 } 667 ui_tab(obj, "Tab 3") { 668 669 } 670 } 671 ui_newline(obj); 672 673 ui_label(obj, .label = "Test Label"); 674 ui_progressbar(obj, .value = wdata->progress, .colspan = 2); 675 ui_newline(obj); 676 677 ui_newline(obj); 678 ui_textfield(obj, .value = wdata->t1); 679 ui_textfield(obj, .value = wdata->t2); 680 ui_textfield(obj, .value = wdata->t3); 681 ui_newline(obj); 682 ui_button(obj, .label = "Add", .onclick = action_add); 683 ui_newline(obj); 684 685 686 ui_newline(obj); 687 688 UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Col 1", UI_STRING, "Col 2", UI_STRING, "Col 3", -1); 689 model->getvalue = table_getvalue; 690 ui_table(obj, .colspan = 3, .model = model, .list = wdata->list2, .onactivate = action_onactivate, 691 .onselection = action_listselection_changed, 692 .ondragstart = dragstart, .ondragcomplete = dragcomplete, .ondrop = drop); 693 ui_model_free(obj->ctx, model); 694 } 695 } 696 697 ui_show(obj); 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 // menu 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 ui_init("app1", 0, NULL); 757 ui_onstartup(application_startup, NULL); 758 759 ui_menu("File") { 760 ui_menuitem(.label = "Item 1"); 761 ui_menuitem(.label = "Item 2"); 762 ui_menuseparator(); 763 ui_menu("File Sub") { 764 ui_menuitem(.label = "Sub Item"); 765 } 766 767 ui_menuitem(.label = "Exit"); 768 } 769 770 ui_toolbar_item("Test", .label = "Home", .icon = "Home", .onclick = action_toolbar_button); 771 ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button); 772 ui_toolbar_toggleitem("Toggle2", .label = "Toggle2", .onchange = action_toolbar_button); 773 ui_toolbar_toggleitem("Toggle3", .label = "Toggle3", .onchange = action_toolbar_button); 774 775 ui_toolbar_menu("Menu", .label = "Menu") { 776 777 ui_menuitem(.label = "x", NULL, NULL); 778 ui_menuitem(.label = "x", NULL, NULL); 779 ui_menu_itemlist(.varname = "menulist"); 780 ui_menuitem(.label = "x", NULL, NULL); 781 ui_menuitem(.label = "x", NULL, NULL); 782 ui_menuitem(.label = "x", NULL, NULL); 783 ui_menu("TB Sub") { 784 ui_menuitem("TB subitem", NULL, NULL); 785 } 786 } 787 788 ui_toolbar_menu(NULL, .label = "Menu") { 789 ui_menuitem("Secondary Test", NULL, NULL); 790 ui_menu("Secondary Sub") { 791 ui_menuitem("Secondary subitem", NULL, NULL); 792 } 793 } 794 795 ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT); 796 ui_toolbar_add_default("Toggle", UI_TOOLBAR_LEFT); 797 ui_toolbar_add_default("Toggle2", UI_TOOLBAR_CENTER); 798 ui_toolbar_add_default("Toggle3", UI_TOOLBAR_CENTER); 799 ui_toolbar_add_default("Menu", UI_TOOLBAR_RIGHT); 800 801 ui_main(); 802 803 return (EXIT_SUCCESS); 804 */ 805 } 806