Changes in uspace/app/uidemo/uidemo.c [db3895d:ef4d684] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rdb3895d ref4d684 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 40 40 #include <str.h> 41 41 #include <ui/entry.h> 42 #include <ui/filedialog.h> 42 43 #include <ui/fixed.h> 43 44 #include <ui/image.h> 44 45 #include <ui/label.h> 46 #include <ui/list.h> 47 #include <ui/menu.h> 45 48 #include <ui/menubar.h> 49 #include <ui/menudd.h> 46 50 #include <ui/menuentry.h> 47 #include <ui/menu.h>48 51 #include <ui/msgdialog.h> 49 52 #include <ui/pbutton.h> 53 #include <ui/promptdialog.h> 50 54 #include <ui/resource.h> 55 #include <ui/selectdialog.h> 56 #include <ui/tab.h> 57 #include <ui/tabset.h> 51 58 #include <ui/ui.h> 52 59 #include <ui/window.h> … … 85 92 }; 86 93 94 static void scrollbar_up(ui_scrollbar_t *, void *); 95 static void scrollbar_down(ui_scrollbar_t *, void *); 96 static void scrollbar_page_up(ui_scrollbar_t *, void *); 97 static void scrollbar_page_down(ui_scrollbar_t *, void *); 98 static void scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t); 99 100 static ui_scrollbar_cb_t scrollbar_cb = { 101 .up = scrollbar_up, 102 .down = scrollbar_down, 103 .page_up = scrollbar_page_up, 104 .page_down = scrollbar_page_down, 105 .moved = scrollbar_moved 106 }; 107 108 static void uidemo_file_load(ui_menu_entry_t *, void *); 87 109 static void uidemo_file_message(ui_menu_entry_t *, void *); 88 110 static void uidemo_file_exit(ui_menu_entry_t *, void *); 111 static void uidemo_edit_modify(ui_menu_entry_t *, void *); 112 static void uidemo_edit_insert_character(ui_menu_entry_t *, void *); 113 114 static void file_dialog_bok(ui_file_dialog_t *, void *, const char *); 115 static void file_dialog_bcancel(ui_file_dialog_t *, void *); 116 static void file_dialog_close(ui_file_dialog_t *, void *); 117 118 static ui_file_dialog_cb_t file_dialog_cb = { 119 .bok = file_dialog_bok, 120 .bcancel = file_dialog_bcancel, 121 .close = file_dialog_close 122 }; 123 124 static void prompt_dialog_bok(ui_prompt_dialog_t *, void *, const char *); 125 static void prompt_dialog_bcancel(ui_prompt_dialog_t *, void *); 126 static void prompt_dialog_close(ui_prompt_dialog_t *, void *); 127 128 static ui_prompt_dialog_cb_t prompt_dialog_cb = { 129 .bok = prompt_dialog_bok, 130 .bcancel = prompt_dialog_bcancel, 131 .close = prompt_dialog_close 132 }; 133 134 static void select_dialog_bok(ui_select_dialog_t *, void *, void *); 135 static void select_dialog_bcancel(ui_select_dialog_t *, void *); 136 static void select_dialog_close(ui_select_dialog_t *, void *); 137 138 static ui_select_dialog_cb_t select_dialog_cb = { 139 .bok = select_dialog_bok, 140 .bcancel = select_dialog_bcancel, 141 .close = select_dialog_close 142 }; 89 143 90 144 static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned); … … 96 150 }; 97 151 152 /** Horizontal alignment selected by each radio button */ 153 static const gfx_halign_t uidemo_halign[3] = { 154 gfx_halign_left, 155 gfx_halign_center, 156 gfx_halign_right 157 }; 158 98 159 /** Window close button was clicked. 99 160 * … … 122 183 if (rc != EOK) 123 184 printf("Error changing entry text.\n"); 124 (void) ui_entry_paint(demo->entry);125 185 } else { 126 186 rc = ui_entry_set_text(demo->entry, "Cancel pressed"); 127 187 if (rc != EOK) 128 188 printf("Error changing entry text.\n"); 129 (void) ui_entry_paint(demo->entry);130 189 } 131 190 } … … 139 198 { 140 199 ui_demo_t *demo = (ui_demo_t *) arg; 141 errno_t rc; 142 143 if (enable) { 144 rc = ui_entry_set_text(demo->entry, "Checked"); 145 if (rc != EOK) 146 printf("Error changing entry text.\n"); 147 (void) ui_entry_paint(demo->entry); 148 } else { 149 rc = ui_entry_set_text(demo->entry, "Unchecked"); 150 if (rc != EOK) 151 printf("Error changing entry text.\n"); 152 (void) ui_entry_paint(demo->entry); 153 } 200 201 ui_entry_set_read_only(demo->entry, enable); 154 202 } 155 203 … … 163 211 { 164 212 ui_demo_t *demo = (ui_demo_t *) garg; 165 const char *text = (const char *) barg; 166 errno_t rc; 167 168 rc = ui_entry_set_text(demo->entry, text); 169 if (rc != EOK) 170 printf("Error changing entry text.\n"); 213 gfx_halign_t halign = *(gfx_halign_t *) barg; 214 215 ui_entry_set_halign(demo->entry, halign); 171 216 (void) ui_entry_paint(demo->entry); 172 217 } … … 200 245 } 201 246 202 /** File/message menu entry selected.203 * 204 * @param mentry Menu entry247 /** Scrollbar up button pressed. 248 * 249 * @param scrollbar Scrollbar 205 250 * @param arg Argument (demo) 206 251 */ 207 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 208 { 209 ui_demo_t *demo = (ui_demo_t *) arg; 252 static void scrollbar_up(ui_scrollbar_t *scrollbar, void *arg) 253 { 254 gfx_coord_t pos; 255 256 pos = ui_scrollbar_get_pos(scrollbar); 257 ui_scrollbar_set_pos(scrollbar, pos - 1); 258 259 pos = ui_scrollbar_get_pos(scrollbar); 260 scrollbar_moved(scrollbar, arg, pos); 261 } 262 263 /** Scrollbar down button pressed. 264 * 265 * @param scrollbar Scrollbar 266 * @param arg Argument (demo) 267 */ 268 static void scrollbar_down(ui_scrollbar_t *scrollbar, void *arg) 269 { 270 gfx_coord_t pos; 271 272 pos = ui_scrollbar_get_pos(scrollbar); 273 ui_scrollbar_set_pos(scrollbar, pos + 1); 274 275 pos = ui_scrollbar_get_pos(scrollbar); 276 scrollbar_moved(scrollbar, arg, pos); 277 } 278 279 /** Scrollbar page up event. 280 * 281 * @param scrollbar Scrollbar 282 * @param arg Argument (demo) 283 */ 284 static void scrollbar_page_up(ui_scrollbar_t *scrollbar, void *arg) 285 { 286 gfx_coord_t pos; 287 288 pos = ui_scrollbar_get_pos(scrollbar); 289 ui_scrollbar_set_pos(scrollbar, pos - 290 ui_scrollbar_trough_length(scrollbar) / 4); 291 292 pos = ui_scrollbar_get_pos(scrollbar); 293 scrollbar_moved(scrollbar, arg, pos); 294 } 295 296 /** Scrollbar page down event. 297 * 298 * @param scrollbar Scrollbar 299 * @param arg Argument (demo) 300 */ 301 static void scrollbar_page_down(ui_scrollbar_t *scrollbar, void *arg) 302 { 303 gfx_coord_t pos; 304 305 pos = ui_scrollbar_get_pos(scrollbar); 306 ui_scrollbar_set_pos(scrollbar, pos + 307 ui_scrollbar_trough_length(scrollbar) / 4); 308 309 pos = ui_scrollbar_get_pos(scrollbar); 310 scrollbar_moved(scrollbar, arg, pos); 311 } 312 313 /** Scrollbar was moved. 314 * 315 * @param scrollbar Scrollbar 316 * @param arg Argument (demo) 317 * @param pos Position 318 */ 319 static void scrollbar_moved(ui_scrollbar_t *scrollbar, void *arg, 320 gfx_coord_t pos) 321 { 322 ui_demo_t *demo = (ui_demo_t *) arg; 323 char *str; 324 errno_t rc; 325 int rv; 326 327 rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos, 328 ui_scrollbar_move_length(scrollbar)); 329 if (rv < 0) { 330 printf("Out of memory.\n"); 331 return; 332 } 333 334 rc = ui_entry_set_text(demo->entry, str); 335 if (rc != EOK) 336 printf("Error changing entry text.\n"); 337 (void) ui_entry_paint(demo->entry); 338 339 free(str); 340 } 341 342 /** Display a message window. 343 * 344 * @param demo UI demo 345 * @param caption Window caption 346 * @param text Message text 347 */ 348 static void uidemo_show_message(ui_demo_t *demo, const char *caption, 349 const char *text) 350 { 210 351 ui_msg_dialog_params_t mdparams; 211 352 ui_msg_dialog_t *dialog; … … 213 354 214 355 ui_msg_dialog_params_init(&mdparams); 356 mdparams.caption = caption; 357 mdparams.text = text; 358 359 rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog); 360 if (rc != EOK) { 361 printf("Error creating message dialog.\n"); 362 return; 363 } 364 365 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 366 } 367 368 /** File / Load menu entry selected. 369 * 370 * @param mentry Menu entry 371 * @param arg Argument (demo) 372 */ 373 static void uidemo_file_load(ui_menu_entry_t *mentry, void *arg) 374 { 375 ui_demo_t *demo = (ui_demo_t *) arg; 376 ui_file_dialog_params_t fdparams; 377 ui_file_dialog_t *dialog; 378 errno_t rc; 379 380 ui_file_dialog_params_init(&fdparams); 381 fdparams.caption = "Load File"; 382 383 rc = ui_file_dialog_create(demo->ui, &fdparams, &dialog); 384 if (rc != EOK) { 385 printf("Error creating message dialog.\n"); 386 return; 387 } 388 389 ui_file_dialog_set_cb(dialog, &file_dialog_cb, demo); 390 } 391 392 /** File / Message menu entry selected. 393 * 394 * @param mentry Menu entry 395 * @param arg Argument (demo) 396 */ 397 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 398 { 399 ui_demo_t *demo = (ui_demo_t *) arg; 400 ui_msg_dialog_params_t mdparams; 401 ui_msg_dialog_t *dialog; 402 errno_t rc; 403 404 ui_msg_dialog_params_init(&mdparams); 215 405 mdparams.caption = "Message For You"; 216 406 mdparams.text = "Hello, world!"; … … 223 413 224 414 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 225 226 } 227 228 /** File/exit menu entry selected. 415 } 416 417 /** File / Exit menu entry selected. 229 418 * 230 419 * @param mentry Menu entry … … 236 425 237 426 ui_quit(demo->ui); 427 } 428 429 /** Edit / Modify menu entry selected. 430 * 431 * @param mentry Menu entry 432 * @param arg Argument (demo) 433 */ 434 static void uidemo_edit_modify(ui_menu_entry_t *mentry, void *arg) 435 { 436 ui_demo_t *demo = (ui_demo_t *) arg; 437 ui_prompt_dialog_params_t pdparams; 438 ui_prompt_dialog_t *dialog; 439 errno_t rc; 440 441 ui_prompt_dialog_params_init(&pdparams); 442 pdparams.caption = "Modify Entry Text"; 443 pdparams.prompt = "Enter New Text"; 444 445 rc = ui_prompt_dialog_create(demo->ui, &pdparams, &dialog); 446 if (rc != EOK) { 447 printf("Error creating prompt dialog.\n"); 448 return; 449 } 450 451 ui_prompt_dialog_set_cb(dialog, &prompt_dialog_cb, demo); 452 } 453 454 /** Edit / Insert Character menu entry selected. 455 * 456 * @param mentry Menu entry 457 * @param arg Argument (demo) 458 */ 459 static void uidemo_edit_insert_character(ui_menu_entry_t *mentry, void *arg) 460 { 461 ui_demo_t *demo = (ui_demo_t *) arg; 462 ui_select_dialog_params_t sdparams; 463 ui_select_dialog_t *dialog; 464 ui_list_entry_attr_t attr; 465 errno_t rc; 466 467 ui_select_dialog_params_init(&sdparams); 468 sdparams.caption = "Insert Character"; 469 sdparams.prompt = "Select character to insert"; 470 471 rc = ui_select_dialog_create(demo->ui, &sdparams, &dialog); 472 if (rc != EOK) { 473 printf("Error creating select dialog.\n"); 474 return; 475 } 476 477 ui_list_entry_attr_init(&attr); 478 attr.caption = "Dollar sign ($)"; 479 attr.arg = (void *)'$'; 480 rc = ui_select_dialog_append(dialog, &attr); 481 if (rc != EOK) { 482 printf("Error appending entry to list.\n"); 483 return; 484 } 485 486 ui_list_entry_attr_init(&attr); 487 attr.caption = "Hash sign (#)"; 488 attr.arg = (void *)'#'; 489 rc = ui_select_dialog_append(dialog, &attr); 490 if (rc != EOK) { 491 printf("Error appending entry to list.\n"); 492 return; 493 } 494 495 ui_list_entry_attr_init(&attr); 496 attr.caption = "Question mark (?)"; 497 attr.arg = (void *)'?'; 498 rc = ui_select_dialog_append(dialog, &attr); 499 if (rc != EOK) { 500 printf("Error appending entry to list.\n"); 501 return; 502 } 503 504 ui_select_dialog_set_cb(dialog, &select_dialog_cb, demo); 505 506 (void) ui_select_dialog_paint(dialog); 507 } 508 509 /** File dialog OK button press. 510 * 511 * @param dialog File dialog 512 * @param arg Argument (ui_demo_t *) 513 * @param fname File name 514 */ 515 static void file_dialog_bok(ui_file_dialog_t *dialog, void *arg, 516 const char *fname) 517 { 518 ui_demo_t *demo = (ui_demo_t *) arg; 519 char buf[128]; 520 char *p; 521 FILE *f; 522 523 ui_file_dialog_destroy(dialog); 524 525 f = fopen(fname, "rt"); 526 if (f == NULL) { 527 uidemo_show_message(demo, "Error", "Error opening file."); 528 return; 529 } 530 531 p = fgets(buf, sizeof(buf), f); 532 if (p == NULL) { 533 uidemo_show_message(demo, "Error", "Error reading file."); 534 fclose(f); 535 return; 536 } 537 538 /* Cut string off at the first non-printable character */ 539 p = buf; 540 while (*p != '\0') { 541 if (*p < ' ') { 542 *p = '\0'; 543 break; 544 } 545 ++p; 546 } 547 548 ui_entry_set_text(demo->entry, buf); 549 fclose(f); 550 } 551 552 /** File dialog cancel button press. 553 * 554 * @param dialog File dialog 555 * @param arg Argument (ui_demo_t *) 556 */ 557 static void file_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 558 { 559 ui_demo_t *demo = (ui_demo_t *) arg; 560 561 (void) demo; 562 ui_file_dialog_destroy(dialog); 563 } 564 565 /** File dialog close request. 566 * 567 * @param dialog File dialog 568 * @param arg Argument (ui_demo_t *) 569 */ 570 static void file_dialog_close(ui_file_dialog_t *dialog, void *arg) 571 { 572 ui_demo_t *demo = (ui_demo_t *) arg; 573 574 (void) demo; 575 ui_file_dialog_destroy(dialog); 576 } 577 578 /** Prompt dialog OK button press. 579 * 580 * @param dialog Prompt dialog 581 * @param arg Argument (ui_demo_t *) 582 * @param text Submitted text 583 */ 584 static void prompt_dialog_bok(ui_prompt_dialog_t *dialog, void *arg, 585 const char *text) 586 { 587 ui_demo_t *demo = (ui_demo_t *) arg; 588 589 ui_prompt_dialog_destroy(dialog); 590 ui_entry_set_text(demo->entry, text); 591 } 592 593 /** Prompt dialog cancel button press. 594 * 595 * @param dialog Prompt dialog 596 * @param arg Argument (ui_demo_t *) 597 */ 598 static void prompt_dialog_bcancel(ui_prompt_dialog_t *dialog, void *arg) 599 { 600 ui_demo_t *demo = (ui_demo_t *) arg; 601 602 (void) demo; 603 ui_prompt_dialog_destroy(dialog); 604 } 605 606 /** Prompt dialog close request. 607 * 608 * @param dialog Prompt dialog 609 * @param arg Argument (ui_demo_t *) 610 */ 611 static void prompt_dialog_close(ui_prompt_dialog_t *dialog, void *arg) 612 { 613 ui_demo_t *demo = (ui_demo_t *) arg; 614 615 (void) demo; 616 ui_prompt_dialog_destroy(dialog); 617 } 618 619 /** Select dialog OK button press. 620 * 621 * @param dialog Select dialog 622 * @param arg Argument (ui_demo_t *) 623 * @param text Submitted text 624 */ 625 static void select_dialog_bok(ui_select_dialog_t *dialog, void *arg, 626 void *earg) 627 { 628 ui_demo_t *demo = (ui_demo_t *) arg; 629 char str[2]; 630 631 ui_select_dialog_destroy(dialog); 632 str[0] = (char)(intptr_t)earg; 633 str[1] = '\0'; 634 (void) ui_entry_insert_str(demo->entry, str); 635 } 636 637 /** Select dialog cancel button press. 638 * 639 * @param dialog Select dialog 640 * @param arg Argument (ui_demo_t *) 641 */ 642 static void select_dialog_bcancel(ui_select_dialog_t *dialog, void *arg) 643 { 644 ui_demo_t *demo = (ui_demo_t *) arg; 645 646 (void) demo; 647 ui_select_dialog_destroy(dialog); 648 } 649 650 /** Select dialog close request. 651 * 652 * @param dialog Select dialog 653 * @param arg Argument (ui_demo_t *) 654 */ 655 static void select_dialog_close(ui_select_dialog_t *dialog, void *arg) 656 { 657 ui_demo_t *demo = (ui_demo_t *) arg; 658 659 (void) demo; 660 ui_select_dialog_destroy(dialog); 238 661 } 239 662 … … 280 703 gfx_coord2_t off; 281 704 ui_menu_entry_t *mmsg; 705 ui_menu_entry_t *mload; 282 706 ui_menu_entry_t *mfoo; 283 707 ui_menu_entry_t *mbar; 284 708 ui_menu_entry_t *mfoobar; 709 ui_menu_entry_t *msep; 285 710 ui_menu_entry_t *mexit; 711 ui_menu_entry_t *mmodify; 712 ui_menu_entry_t *minsert_char; 286 713 ui_menu_entry_t *mabout; 714 ui_list_entry_attr_t eattr; 287 715 errno_t rc; 288 716 … … 298 726 ui_wnd_params_init(¶ms); 299 727 params.caption = "UI Demo"; 300 params.style |= ui_wds_ resizable;728 params.style |= ui_wds_maximize_btn | ui_wds_resizable; 301 729 302 730 /* FIXME: Auto layout */ … … 304 732 params.rect.p0.x = 0; 305 733 params.rect.p0.y = 0; 306 params.rect.p1.x = 80;734 params.rect.p1.x = 46; 307 735 params.rect.p1.y = 25; 308 736 } else { 309 737 params.rect.p0.x = 0; 310 738 params.rect.p0.y = 0; 311 params.rect.p1.x = 2 20;312 params.rect.p1.y = 350;739 params.rect.p1.x = 255; 740 params.rect.p1.y = 410; 313 741 } 314 742 … … 337 765 } 338 766 339 rc = ui_menu_ create(demo.mbar, "File", &demo.mfile);767 rc = ui_menu_dd_create(demo.mbar, "~F~ile", NULL, &demo.mfile); 340 768 if (rc != EOK) { 341 769 printf("Error creating menu.\n"); … … 343 771 } 344 772 345 rc = ui_menu_entry_create(demo.mfile, " Message", "", &mmsg);773 rc = ui_menu_entry_create(demo.mfile, "~M~essage", "", &mmsg); 346 774 if (rc != EOK) { 347 775 printf("Error creating menu.\n"); … … 351 779 ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo); 352 780 353 rc = ui_menu_entry_create(demo.mfile, " Foo", "Ctrl-Alt-Del", &mfoo);781 rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload); 354 782 if (rc != EOK) { 355 783 printf("Error creating menu.\n"); … … 357 785 } 358 786 359 rc = ui_menu_entry_create(demo.mfile, "Bar", "", &mbar); 787 ui_menu_entry_set_cb(mload, uidemo_file_load, (void *) &demo); 788 789 rc = ui_menu_entry_create(demo.mfile, "~F~oo", "Ctrl-Alt-Del", &mfoo); 360 790 if (rc != EOK) { 361 791 printf("Error creating menu.\n"); … … 363 793 } 364 794 365 rc = ui_menu_entry_create(demo.mfile, " Foobar", "", &mfoobar);795 rc = ui_menu_entry_create(demo.mfile, "~B~ar", "", &mbar); 366 796 if (rc != EOK) { 367 797 printf("Error creating menu.\n"); … … 369 799 } 370 800 371 rc = ui_menu_entry_ sep_create(demo.mfile, &mexit);801 rc = ui_menu_entry_create(demo.mfile, "F~o~obar", "", &mfoobar); 372 802 if (rc != EOK) { 373 803 printf("Error creating menu.\n"); … … 375 805 } 376 806 377 rc = ui_menu_entry_create(demo.mfile, "Exit", "Alt-F4", &mexit); 807 ui_menu_entry_set_disabled(mfoobar, true); 808 809 rc = ui_menu_entry_sep_create(demo.mfile, &msep); 378 810 if (rc != EOK) { 379 811 printf("Error creating menu.\n"); … … 381 813 } 382 814 815 rc = ui_menu_entry_create(demo.mfile, "E~x~it", "Alt-F4", &mexit); 816 if (rc != EOK) { 817 printf("Error creating menu.\n"); 818 return rc; 819 } 820 383 821 ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo); 384 822 385 rc = ui_menu_ create(demo.mbar, "Edit", &demo.medit);823 rc = ui_menu_dd_create(demo.mbar, "~E~dit", NULL, &demo.medit); 386 824 if (rc != EOK) { 387 825 printf("Error creating menu.\n"); … … 389 827 } 390 828 391 rc = ui_menu_ create(demo.mbar, "Preferences", &demo.mpreferences);829 rc = ui_menu_entry_create(demo.medit, "~M~odify", "", &mmodify); 392 830 if (rc != EOK) { 393 831 printf("Error creating menu.\n"); … … 395 833 } 396 834 397 rc = ui_menu_create(demo.mbar, "Help", &demo.mhelp); 835 ui_menu_entry_set_cb(mmodify, uidemo_edit_modify, (void *) &demo); 836 837 rc = ui_menu_entry_create(demo.medit, "~I~nsert Character", 838 "", &minsert_char); 398 839 if (rc != EOK) { 399 840 printf("Error creating menu.\n"); … … 401 842 } 402 843 403 rc = ui_menu_entry_create(demo.mhelp, "About", "Ctrl-H, F1", &mabout); 844 ui_menu_entry_set_cb(minsert_char, uidemo_edit_insert_character, 845 (void *) &demo); 846 847 rc = ui_menu_dd_create(demo.mbar, "~P~references", NULL, 848 &demo.mpreferences); 404 849 if (rc != EOK) { 405 850 printf("Error creating menu.\n"); … … 407 852 } 408 853 854 rc = ui_menu_dd_create(demo.mbar, "~H~elp", NULL, &demo.mhelp); 855 if (rc != EOK) { 856 printf("Error creating menu.\n"); 857 return rc; 858 } 859 860 rc = ui_menu_entry_create(demo.mhelp, "~A~bout", "Ctrl-H, F1", &mabout); 861 if (rc != EOK) { 862 printf("Error creating menu.\n"); 863 return rc; 864 } 865 409 866 /* FIXME: Auto layout */ 410 867 if (ui_is_textmode(ui)) { 411 868 rect.p0.x = 1; 412 rect.p0.y = 2;413 rect.p1.x = 79;414 rect.p1.y = 3;869 rect.p0.y = 1; 870 rect.p1.x = 43; 871 rect.p1.y = 2; 415 872 } else { 416 873 rect.p0.x = 4; 417 874 rect.p0.y = 30; 418 rect.p1.x = 2 16;875 rect.p1.x = 251; 419 876 rect.p1.y = 52; 420 877 } 878 421 879 ui_menu_bar_set_rect(demo.mbar, &rect); 422 880 … … 427 885 } 428 886 887 rc = ui_tab_set_create(ui_res, &demo.tabset); 888 if (rc != EOK) { 889 printf("Error creating tab set.\n"); 890 return rc; 891 } 892 893 /* FIXME: Auto layout */ 894 if (ui_is_textmode(ui)) { 895 rect.p0.x = 2; 896 rect.p0.y = 2; 897 rect.p1.x = 44; 898 rect.p1.y = 24; 899 } else { 900 rect.p0.x = 8; 901 rect.p0.y = 53; 902 rect.p1.x = 250; 903 rect.p1.y = 405; 904 } 905 906 ui_tab_set_set_rect(demo.tabset, &rect); 907 908 rc = ui_tab_create(demo.tabset, "Basic", &demo.tbasic); 909 if (rc != EOK) { 910 printf("Error creating tab.\n"); 911 return rc; 912 } 913 914 rc = ui_tab_create(demo.tabset, "Lists", &demo.tlists); 915 if (rc != EOK) { 916 printf("Error creating tab.\n"); 917 return rc; 918 } 919 920 rc = ui_fixed_add(demo.fixed, ui_tab_set_ctl(demo.tabset)); 921 if (rc != EOK) { 922 printf("Error adding control to layout.\n"); 923 return rc; 924 } 925 926 rc = ui_fixed_create(&demo.bfixed); 927 if (rc != EOK) { 928 printf("Error creating fixed layout.\n"); 929 return rc; 930 } 931 429 932 rc = ui_entry_create(window, "", &demo.entry); 430 933 if (rc != EOK) { … … 433 936 } 434 937 435 rect.p0.x = 15; 436 rect.p0.y = 53; 437 rect.p1.x = 205; 438 rect.p1.y = 78; 938 /* FIXME: Auto layout */ 939 if (ui_is_textmode(ui)) { 940 rect.p0.x = 4; 941 rect.p0.y = 5; 942 rect.p1.x = 41; 943 rect.p1.y = 6; 944 } else { 945 rect.p0.x = 15; 946 rect.p0.y = 88; 947 rect.p1.x = 205; 948 rect.p1.y = 113; 949 } 950 439 951 ui_entry_set_rect(demo.entry, &rect); 440 952 ui_entry_set_halign(demo.entry, gfx_halign_center); 441 953 442 rc = ui_fixed_add(demo. fixed, ui_entry_ctl(demo.entry));954 rc = ui_fixed_add(demo.bfixed, ui_entry_ctl(demo.entry)); 443 955 if (rc != EOK) { 444 956 printf("Error adding control to layout.\n"); … … 452 964 } 453 965 454 rect.p0.x = 60; 455 rect.p0.y = 88; 456 rect.p1.x = 160; 457 rect.p1.y = 101; 966 /* FIXME: Auto layout */ 967 if (ui_is_textmode(ui)) { 968 rect.p0.x = 4; 969 rect.p0.y = 7; 970 rect.p1.x = 41; 971 rect.p1.y = 8; 972 } else { 973 rect.p0.x = 60; 974 rect.p0.y = 123; 975 rect.p1.x = 160; 976 rect.p1.y = 136; 977 } 978 458 979 ui_label_set_rect(demo.label, &rect); 459 980 ui_label_set_halign(demo.label, gfx_halign_center); 460 981 461 rc = ui_fixed_add(demo. fixed, ui_label_ctl(demo.label));982 rc = ui_fixed_add(demo.bfixed, ui_label_ctl(demo.label)); 462 983 if (rc != EOK) { 463 984 printf("Error adding control to layout.\n"); … … 473 994 ui_pbutton_set_cb(demo.pb1, &pbutton_cb, (void *) &demo); 474 995 475 rect.p0.x = 15; 476 rect.p0.y = 111; 477 rect.p1.x = 105; 478 rect.p1.y = 139; 996 /* FIXME: Auto layout */ 997 if (ui_is_textmode(ui)) { 998 rect.p0.x = 4; 999 rect.p0.y = 9; 1000 rect.p1.x = 15; 1001 rect.p1.y = 10; 1002 } else { 1003 rect.p0.x = 15; 1004 rect.p0.y = 146; 1005 rect.p1.x = 105; 1006 rect.p1.y = 174; 1007 } 1008 479 1009 ui_pbutton_set_rect(demo.pb1, &rect); 480 1010 481 1011 ui_pbutton_set_default(demo.pb1, true); 482 1012 483 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb1));1013 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb1)); 484 1014 if (rc != EOK) { 485 1015 printf("Error adding control to layout.\n"); … … 495 1025 ui_pbutton_set_cb(demo.pb2, &pbutton_cb, (void *) &demo); 496 1026 497 rect.p0.x = 115; 498 rect.p0.y = 111; 499 rect.p1.x = 205; 500 rect.p1.y = 139; 1027 if (ui_is_textmode(ui)) { 1028 rect.p0.x = 30; 1029 rect.p0.y = 9; 1030 rect.p1.x = 41; 1031 rect.p1.y = 10; 1032 } else { 1033 rect.p0.x = 115; 1034 rect.p0.y = 146; 1035 rect.p1.x = 205; 1036 rect.p1.y = 174; 1037 } 1038 501 1039 ui_pbutton_set_rect(demo.pb2, &rect); 502 1040 503 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb2));1041 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb2)); 504 1042 if (rc != EOK) { 505 1043 printf("Error adding control to layout.\n"); … … 508 1046 509 1047 gfx_bitmap_params_init(&bparams); 510 bparams.rect.p0.x = 0; 511 bparams.rect.p0.y = 0; 512 bparams.rect.p1.x = 188; 513 bparams.rect.p1.y = 24; 1048 if (ui_is_textmode(ui)) { 1049 bparams.rect.p0.x = 0; 1050 bparams.rect.p0.y = 0; 1051 bparams.rect.p1.x = 37; 1052 bparams.rect.p1.y = 2; 1053 } else { 1054 bparams.rect.p0.x = 0; 1055 bparams.rect.p0.y = 0; 1056 bparams.rect.p1.x = 188; 1057 bparams.rect.p1.y = 24; 1058 } 514 1059 515 1060 rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap); … … 527 1072 } 528 1073 529 off.x = 15; 530 off.y = 155; 1074 if (ui_is_textmode(ui)) { 1075 off.x = 4; 1076 off.y = 11; 1077 } else { 1078 off.x = 15; 1079 off.y = 190; 1080 } 1081 531 1082 gfx_rect_translate(&off, &bparams.rect, &rect); 532 1083 533 1084 /* Adjust for frame width (2 x 1 pixel) */ 534 rect.p1.x += 2; 535 rect.p1.y += 2; 1085 if (!ui_is_textmode(ui)) { 1086 ui_image_set_flags(demo.image, ui_imgf_frame); 1087 rect.p1.x += 2; 1088 rect.p1.y += 2; 1089 } 1090 536 1091 ui_image_set_rect(demo.image, &rect); 537 ui_image_set_flags(demo.image, ui_imgf_frame); 538 539 rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image)); 1092 1093 rc = ui_fixed_add(demo.bfixed, ui_image_ctl(demo.image)); 540 1094 if (rc != EOK) { 541 1095 printf("Error adding control to layout.\n"); … … 543 1097 } 544 1098 545 rc = ui_checkbox_create(ui_res, " Check me", &demo.checkbox);1099 rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox); 546 1100 if (rc != EOK) { 547 1101 printf("Error creating check box.\n"); … … 551 1105 ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo); 552 1106 553 rect.p0.x = 15; 554 rect.p0.y = 190; 555 rect.p1.x = 140; 556 rect.p1.y = 210; 1107 /* FIXME: Auto layout */ 1108 if (ui_is_textmode(ui)) { 1109 rect.p0.x = 4; 1110 rect.p0.y = 14; 1111 rect.p1.x = 14; 1112 rect.p1.y = 15; 1113 } else { 1114 rect.p0.x = 15; 1115 rect.p0.y = 225; 1116 rect.p1.x = 140; 1117 rect.p1.y = 245; 1118 } 1119 557 1120 ui_checkbox_set_rect(demo.checkbox, &rect); 558 1121 559 rc = ui_fixed_add(demo. fixed, ui_checkbox_ctl(demo.checkbox));1122 rc = ui_fixed_add(demo.bfixed, ui_checkbox_ctl(demo.checkbox)); 560 1123 if (rc != EOK) { 561 1124 printf("Error adding control to layout.\n"); … … 569 1132 } 570 1133 571 rc = ui_rbutton_create(demo.rbgroup, " Option 1", (void *) "First",572 &demo.rb 1);1134 rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0], 1135 &demo.rbleft); 573 1136 if (rc != EOK) { 574 1137 printf("Error creating radio button.\n"); … … 579 1142 (void *) &demo); 580 1143 581 rect.p0.x = 15; 582 rect.p0.y = 220; 583 rect.p1.x = 140; 584 rect.p1.y = 240; 585 ui_rbutton_set_rect(demo.rb1, &rect); 586 587 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb1)); 1144 /* FIXME: Auto layout */ 1145 if (ui_is_textmode(ui)) { 1146 rect.p0.x = 4; 1147 rect.p0.y = 16; 1148 rect.p1.x = 14; 1149 rect.p1.y = 17; 1150 } else { 1151 rect.p0.x = 15; 1152 rect.p0.y = 255; 1153 rect.p1.x = 140; 1154 rect.p1.y = 275; 1155 } 1156 ui_rbutton_set_rect(demo.rbleft, &rect); 1157 1158 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbleft)); 588 1159 if (rc != EOK) { 589 1160 printf("Error adding control to layout.\n"); … … 591 1162 } 592 1163 593 rc = ui_rbutton_create(demo.rbgroup, " Option 2", (void *) "Second",594 &demo.rb 2);1164 rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1], 1165 &demo.rbcenter); 595 1166 if (rc != EOK) { 596 1167 printf("Error creating radio button.\n"); … … 598 1169 } 599 1170 600 rect.p0.x = 15; 601 rect.p0.y = 250; 602 rect.p1.x = 140; 603 rect.p1.y = 270; 604 ui_rbutton_set_rect(demo.rb2, &rect); 605 606 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb2)); 1171 /* FIXME: Auto layout */ 1172 if (ui_is_textmode(ui)) { 1173 rect.p0.x = 4; 1174 rect.p0.y = 17; 1175 rect.p1.x = 14; 1176 rect.p1.y = 18; 1177 } else { 1178 rect.p0.x = 15; 1179 rect.p0.y = 285; 1180 rect.p1.x = 140; 1181 rect.p1.y = 305; 1182 } 1183 ui_rbutton_set_rect(demo.rbcenter, &rect); 1184 ui_rbutton_select(demo.rbcenter); 1185 1186 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbcenter)); 607 1187 if (rc != EOK) { 608 1188 printf("Error adding control to layout.\n"); … … 610 1190 } 611 1191 612 rc = ui_rbutton_create(demo.rbgroup, " Option 3", (void *) "Third",613 &demo.rb 3);1192 rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2], 1193 &demo.rbright); 614 1194 if (rc != EOK) { 615 1195 printf("Error creating radio button.\n"); … … 617 1197 } 618 1198 619 rect.p0.x = 15; 620 rect.p0.y = 280; 621 rect.p1.x = 140; 622 rect.p1.y = 300; 623 ui_rbutton_set_rect(demo.rb3, &rect); 624 625 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb3)); 1199 /* FIXME: Auto layout */ 1200 if (ui_is_textmode(ui)) { 1201 rect.p0.x = 4; 1202 rect.p0.y = 18; 1203 rect.p1.x = 14; 1204 rect.p1.y = 19; 1205 } else { 1206 rect.p0.x = 15; 1207 rect.p0.y = 315; 1208 rect.p1.x = 140; 1209 rect.p1.y = 335; 1210 } 1211 ui_rbutton_set_rect(demo.rbright, &rect); 1212 1213 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbright)); 626 1214 if (rc != EOK) { 627 1215 printf("Error adding control to layout.\n"); … … 629 1217 } 630 1218 631 rc = ui_slider_create(ui_res, "Slide!",&demo.slider);1219 rc = ui_slider_create(ui_res, &demo.slider); 632 1220 if (rc != EOK) { 633 1221 printf("Error creating button.\n"); … … 637 1225 ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo); 638 1226 639 rect.p0.x = 15; 640 rect.p0.y = 310; 641 rect.p1.x = 130; 642 rect.p1.y = 330; 1227 /* FIXME: Auto layout */ 1228 if (ui_is_textmode(ui)) { 1229 rect.p0.x = 4; 1230 rect.p0.y = 20; 1231 rect.p1.x = 32; 1232 rect.p1.y = 21; 1233 } else { 1234 rect.p0.x = 15; 1235 rect.p0.y = 345; 1236 rect.p1.x = 130; 1237 rect.p1.y = 365; 1238 } 1239 643 1240 ui_slider_set_rect(demo.slider, &rect); 644 1241 645 rc = ui_fixed_add(demo. fixed, ui_slider_ctl(demo.slider));1242 rc = ui_fixed_add(demo.bfixed, ui_slider_ctl(demo.slider)); 646 1243 if (rc != EOK) { 647 1244 printf("Error adding control to layout.\n"); 648 1245 return rc; 649 1246 } 1247 1248 rc = ui_scrollbar_create(ui, window, ui_sbd_horiz, &demo.hscrollbar); 1249 if (rc != EOK) { 1250 printf("Error creating scrollbar.\n"); 1251 return rc; 1252 } 1253 1254 ui_scrollbar_set_cb(demo.hscrollbar, &scrollbar_cb, (void *) &demo); 1255 1256 /* FIXME: Auto layout */ 1257 if (ui_is_textmode(ui)) { 1258 rect.p0.x = 4; 1259 rect.p0.y = 22; 1260 rect.p1.x = 42; 1261 rect.p1.y = 23; 1262 } else { 1263 rect.p0.x = 15; 1264 rect.p0.y = 375; 1265 rect.p1.x = 220; 1266 rect.p1.y = 398; 1267 } 1268 1269 ui_scrollbar_set_rect(demo.hscrollbar, &rect); 1270 1271 ui_scrollbar_set_thumb_length(demo.hscrollbar, 1272 ui_scrollbar_trough_length(demo.hscrollbar) / 4); 1273 1274 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.hscrollbar)); 1275 if (rc != EOK) { 1276 printf("Error adding control to layout.\n"); 1277 return rc; 1278 } 1279 1280 rc = ui_scrollbar_create(ui, window, ui_sbd_vert, &demo.vscrollbar); 1281 if (rc != EOK) { 1282 printf("Error creating button.\n"); 1283 return rc; 1284 } 1285 1286 ui_scrollbar_set_cb(demo.vscrollbar, &scrollbar_cb, (void *) &demo); 1287 1288 /* FIXME: Auto layout */ 1289 if (ui_is_textmode(ui)) { 1290 rect.p0.x = 42; 1291 rect.p0.y = 5; 1292 rect.p1.x = 43; 1293 rect.p1.y = 22; 1294 } else { 1295 rect.p0.x = 220; 1296 rect.p0.y = 88; 1297 rect.p1.x = 243; 1298 rect.p1.y = 375; 1299 } 1300 1301 ui_scrollbar_set_rect(demo.vscrollbar, &rect); 1302 1303 ui_scrollbar_set_thumb_length(demo.vscrollbar, 1304 ui_scrollbar_trough_length(demo.vscrollbar) / 4); 1305 1306 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.vscrollbar)); 1307 if (rc != EOK) { 1308 printf("Error adding control to layout.\n"); 1309 return rc; 1310 } 1311 1312 ui_tab_add(demo.tbasic, ui_fixed_ctl(demo.bfixed)); 1313 1314 rc = ui_fixed_create(&demo.lfixed); 1315 if (rc != EOK) { 1316 printf("Error creating fixed layout.\n"); 1317 return rc; 1318 } 1319 1320 rc = ui_list_create(window, false, &demo.list); 1321 if (rc != EOK) { 1322 printf("Error creating list.\n"); 1323 return rc; 1324 } 1325 1326 ui_list_entry_attr_init(&eattr); 1327 1328 eattr.caption = "One"; 1329 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1330 if (rc != EOK) { 1331 printf("Error adding list entry.\n"); 1332 return rc; 1333 } 1334 1335 eattr.caption = "Two"; 1336 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1337 if (rc != EOK) { 1338 printf("Error adding list entry.\n"); 1339 return rc; 1340 } 1341 1342 eattr.caption = "Three"; 1343 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1344 if (rc != EOK) { 1345 printf("Error adding list entry.\n"); 1346 return rc; 1347 } 1348 1349 eattr.caption = "Four"; 1350 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1351 if (rc != EOK) { 1352 printf("Error adding list entry.\n"); 1353 return rc; 1354 } 1355 1356 eattr.caption = "Five"; 1357 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1358 if (rc != EOK) { 1359 printf("Error adding list entry.\n"); 1360 return rc; 1361 } 1362 1363 eattr.caption = "Six"; 1364 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1365 if (rc != EOK) { 1366 printf("Error adding list entry.\n"); 1367 return rc; 1368 } 1369 1370 /* FIXME: Auto layout */ 1371 if (ui_is_textmode(ui)) { 1372 rect.p0.x = 4; 1373 rect.p0.y = 5; 1374 rect.p1.x = 41; 1375 rect.p1.y = 10; 1376 } else { 1377 rect.p0.x = 15; 1378 rect.p0.y = 88; 1379 rect.p1.x = 245; 1380 rect.p1.y = 173; 1381 } 1382 1383 ui_list_set_rect(demo.list, &rect); 1384 1385 rc = ui_fixed_add(demo.lfixed, ui_list_ctl(demo.list)); 1386 if (rc != EOK) { 1387 printf("Error adding control to layout.\n"); 1388 return rc; 1389 } 1390 1391 ui_tab_add(demo.tlists, ui_fixed_ctl(demo.lfixed)); 650 1392 651 1393 ui_window_add(window, ui_fixed_ctl(demo.fixed)); … … 693 1435 k = i * i + j * j; 694 1436 pixelmap_put_pixel(&pixelmap, i, j, 695 PIXEL( 255, k, k, 255 - k));1437 PIXEL(0, k, k, 255 - k)); 696 1438 } 697 1439 } … … 707 1449 int main(int argc, char *argv[]) 708 1450 { 709 const char *display_spec = UI_ DISPLAY_DEFAULT;1451 const char *display_spec = UI_ANY_DEFAULT; 710 1452 errno_t rc; 711 1453 int i;
Note:
See TracChangeset
for help on using the changeset viewer.