Changes in uspace/app/uidemo/uidemo.c [a977e37:ef4d684] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
ra977e37 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) { … … 435 938 /* FIXME: Auto layout */ 436 939 if (ui_is_textmode(ui)) { 437 rect.p0.x = 20;438 rect.p0.y = 4;439 rect.p1.x = 60;440 rect.p1.y = 5;940 rect.p0.x = 4; 941 rect.p0.y = 5; 942 rect.p1.x = 41; 943 rect.p1.y = 6; 441 944 } else { 442 945 rect.p0.x = 15; 443 rect.p0.y = 53;946 rect.p0.y = 88; 444 947 rect.p1.x = 205; 445 rect.p1.y = 78;948 rect.p1.y = 113; 446 949 } 447 950 … … 449 952 ui_entry_set_halign(demo.entry, gfx_halign_center); 450 953 451 rc = ui_fixed_add(demo. fixed, ui_entry_ctl(demo.entry));954 rc = ui_fixed_add(demo.bfixed, ui_entry_ctl(demo.entry)); 452 955 if (rc != EOK) { 453 956 printf("Error adding control to layout.\n"); … … 463 966 /* FIXME: Auto layout */ 464 967 if (ui_is_textmode(ui)) { 465 rect.p0.x = 20;466 rect.p0.y = 6;467 rect.p1.x = 60;468 rect.p1.y = 7;968 rect.p0.x = 4; 969 rect.p0.y = 7; 970 rect.p1.x = 41; 971 rect.p1.y = 8; 469 972 } else { 470 973 rect.p0.x = 60; 471 rect.p0.y = 88;974 rect.p0.y = 123; 472 975 rect.p1.x = 160; 473 rect.p1.y = 1 01;976 rect.p1.y = 136; 474 977 } 475 978 … … 477 980 ui_label_set_halign(demo.label, gfx_halign_center); 478 981 479 rc = ui_fixed_add(demo. fixed, ui_label_ctl(demo.label));982 rc = ui_fixed_add(demo.bfixed, ui_label_ctl(demo.label)); 480 983 if (rc != EOK) { 481 984 printf("Error adding control to layout.\n"); … … 493 996 /* FIXME: Auto layout */ 494 997 if (ui_is_textmode(ui)) { 495 rect.p0.x = 20;496 rect.p0.y = 8;497 rect.p1.x = 30;498 rect.p1.y = 9;998 rect.p0.x = 4; 999 rect.p0.y = 9; 1000 rect.p1.x = 15; 1001 rect.p1.y = 10; 499 1002 } else { 500 1003 rect.p0.x = 15; 501 rect.p0.y = 1 11;1004 rect.p0.y = 146; 502 1005 rect.p1.x = 105; 503 rect.p1.y = 1 39;1006 rect.p1.y = 174; 504 1007 } 505 1008 … … 508 1011 ui_pbutton_set_default(demo.pb1, true); 509 1012 510 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb1));1013 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb1)); 511 1014 if (rc != EOK) { 512 1015 printf("Error adding control to layout.\n"); … … 523 1026 524 1027 if (ui_is_textmode(ui)) { 525 rect.p0.x = 50;526 rect.p0.y = 8;527 rect.p1.x = 60;528 rect.p1.y = 9;1028 rect.p0.x = 30; 1029 rect.p0.y = 9; 1030 rect.p1.x = 41; 1031 rect.p1.y = 10; 529 1032 } else { 530 1033 rect.p0.x = 115; 531 rect.p0.y = 1 11;1034 rect.p0.y = 146; 532 1035 rect.p1.x = 205; 533 rect.p1.y = 1 39;1036 rect.p1.y = 174; 534 1037 } 535 1038 536 1039 ui_pbutton_set_rect(demo.pb2, &rect); 537 1040 538 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb2));1041 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb2)); 539 1042 if (rc != EOK) { 540 1043 printf("Error adding control to layout.\n"); … … 543 1046 544 1047 gfx_bitmap_params_init(&bparams); 545 bparams.rect.p0.x = 0; 546 bparams.rect.p0.y = 0; 547 bparams.rect.p1.x = 188; 548 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 } 549 1059 550 1060 rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap); … … 562 1072 } 563 1073 564 off.x = 15; 565 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 566 1082 gfx_rect_translate(&off, &bparams.rect, &rect); 567 1083 568 1084 /* Adjust for frame width (2 x 1 pixel) */ 569 rect.p1.x += 2; 570 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 571 1091 ui_image_set_rect(demo.image, &rect); 572 ui_image_set_flags(demo.image, ui_imgf_frame); 573 574 rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image)); 1092 1093 rc = ui_fixed_add(demo.bfixed, ui_image_ctl(demo.image)); 575 1094 if (rc != EOK) { 576 1095 printf("Error adding control to layout.\n"); … … 578 1097 } 579 1098 580 rc = ui_checkbox_create(ui_res, " Check me", &demo.checkbox);1099 rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox); 581 1100 if (rc != EOK) { 582 1101 printf("Error creating check box.\n"); … … 586 1105 ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo); 587 1106 588 rect.p0.x = 15; 589 rect.p0.y = 190; 590 rect.p1.x = 140; 591 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 592 1120 ui_checkbox_set_rect(demo.checkbox, &rect); 593 1121 594 rc = ui_fixed_add(demo. fixed, ui_checkbox_ctl(demo.checkbox));1122 rc = ui_fixed_add(demo.bfixed, ui_checkbox_ctl(demo.checkbox)); 595 1123 if (rc != EOK) { 596 1124 printf("Error adding control to layout.\n"); … … 604 1132 } 605 1133 606 rc = ui_rbutton_create(demo.rbgroup, " Option 1", (void *) "First",607 &demo.rb 1);1134 rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0], 1135 &demo.rbleft); 608 1136 if (rc != EOK) { 609 1137 printf("Error creating radio button.\n"); … … 614 1142 (void *) &demo); 615 1143 616 rect.p0.x = 15; 617 rect.p0.y = 220; 618 rect.p1.x = 140; 619 rect.p1.y = 240; 620 ui_rbutton_set_rect(demo.rb1, &rect); 621 622 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)); 623 1159 if (rc != EOK) { 624 1160 printf("Error adding control to layout.\n"); … … 626 1162 } 627 1163 628 rc = ui_rbutton_create(demo.rbgroup, " Option 2", (void *) "Second",629 &demo.rb 2);1164 rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1], 1165 &demo.rbcenter); 630 1166 if (rc != EOK) { 631 1167 printf("Error creating radio button.\n"); … … 633 1169 } 634 1170 635 rect.p0.x = 15; 636 rect.p0.y = 250; 637 rect.p1.x = 140; 638 rect.p1.y = 270; 639 ui_rbutton_set_rect(demo.rb2, &rect); 640 641 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)); 642 1187 if (rc != EOK) { 643 1188 printf("Error adding control to layout.\n"); … … 645 1190 } 646 1191 647 rc = ui_rbutton_create(demo.rbgroup, " Option 3", (void *) "Third",648 &demo.rb 3);1192 rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2], 1193 &demo.rbright); 649 1194 if (rc != EOK) { 650 1195 printf("Error creating radio button.\n"); … … 652 1197 } 653 1198 654 rect.p0.x = 15; 655 rect.p0.y = 280; 656 rect.p1.x = 140; 657 rect.p1.y = 300; 658 ui_rbutton_set_rect(demo.rb3, &rect); 659 660 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)); 661 1214 if (rc != EOK) { 662 1215 printf("Error adding control to layout.\n"); … … 664 1217 } 665 1218 666 rc = ui_slider_create(ui_res, "Slide!",&demo.slider);1219 rc = ui_slider_create(ui_res, &demo.slider); 667 1220 if (rc != EOK) { 668 1221 printf("Error creating button.\n"); … … 672 1225 ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo); 673 1226 674 rect.p0.x = 15; 675 rect.p0.y = 310; 676 rect.p1.x = 130; 677 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 678 1240 ui_slider_set_rect(demo.slider, &rect); 679 1241 680 rc = ui_fixed_add(demo. fixed, ui_slider_ctl(demo.slider));1242 rc = ui_fixed_add(demo.bfixed, ui_slider_ctl(demo.slider)); 681 1243 if (rc != EOK) { 682 1244 printf("Error adding control to layout.\n"); 683 1245 return rc; 684 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)); 685 1392 686 1393 ui_window_add(window, ui_fixed_ctl(demo.fixed)); … … 728 1435 k = i * i + j * j; 729 1436 pixelmap_put_pixel(&pixelmap, i, j, 730 PIXEL( 255, k, k, 255 - k));1437 PIXEL(0, k, k, 255 - k)); 731 1438 } 732 1439 } … … 742 1449 int main(int argc, char *argv[]) 743 1450 { 744 const char *display_spec = UI_ DISPLAY_DEFAULT;1451 const char *display_spec = UI_ANY_DEFAULT; 745 1452 errno_t rc; 746 1453 int i;
Note:
See TracChangeset
for help on using the changeset viewer.