Changeset 8965860c in mainline
- Timestamp:
- 2022-03-23T18:35:16Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7ca7215
- Parents:
- d4ea1f6
- Location:
- uspace
- Files:
-
- 5 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rd4ea1f6 r8965860c 1070 1070 } 1071 1071 1072 rc = ui_scrollbar_create(ui _res, &demo.scrollbar);1072 rc = ui_scrollbar_create(ui, window, &demo.scrollbar); 1073 1073 if (rc != EOK) { 1074 1074 printf("Error creating button.\n"); -
uspace/lib/ui/include/ui/scrollbar.h
rd4ea1f6 r8965860c 43 43 #include <types/ui/control.h> 44 44 #include <types/ui/event.h> 45 #include <types/ui/resource.h>46 45 #include <types/ui/scrollbar.h> 46 #include <types/ui/ui.h> 47 #include <types/ui/window.h> 47 48 48 extern errno_t ui_scrollbar_create(ui_ resource_t *, ui_scrollbar_t **);49 extern errno_t ui_scrollbar_create(ui_t *, ui_window_t *, ui_scrollbar_t **); 49 50 extern void ui_scrollbar_destroy(ui_scrollbar_t *); 50 51 extern ui_control_t *ui_scrollbar_ctl(ui_scrollbar_t *); … … 62 63 extern void ui_scrollbar_release(ui_scrollbar_t *, gfx_coord2_t *); 63 64 extern void ui_scrollbar_update(ui_scrollbar_t *, gfx_coord2_t *); 65 extern void ui_scrollbar_throughs_update(ui_scrollbar_t *, gfx_coord2_t *); 64 66 extern void ui_scrollbar_up(ui_scrollbar_t *); 65 67 extern void ui_scrollbar_down(ui_scrollbar_t *); -
uspace/lib/ui/include/ui/ui.h
rd4ea1f6 r8965860c 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <io/console.h> 42 42 #include <stdbool.h> 43 #include <types/ui/clickmatic.h> 43 44 #include <types/ui/ui.h> 44 45 … … 54 55 extern errno_t ui_suspend(ui_t *); 55 56 extern errno_t ui_resume(ui_t *); 57 extern void ui_lock(ui_t *); 58 extern void ui_unlock(ui_t *); 59 extern ui_clickmatic_t *ui_get_clickmatic(ui_t *); 56 60 57 61 #endif -
uspace/lib/ui/meson.build
rd4ea1f6 r8965860c 1 1 # 2 # Copyright (c) 202 1Jiri Svoboda2 # Copyright (c) 2022 Jiri Svoboda 3 3 # All rights reserved. 4 4 # … … 31 31 'src/accel.c', 32 32 'src/checkbox.c', 33 'src/clickmatic.c', 33 34 'src/control.c', 34 35 'src/dummygc.c', … … 58 59 'test/accel.c', 59 60 'test/checkbox.c', 61 'test/clickmatic.c', 60 62 'test/control.c', 61 63 'test/entry.c', -
uspace/lib/ui/private/scrollbar.h
rd4ea1f6 r8965860c 48 48 /** Base control object */ 49 49 struct ui_control *control; 50 /** UI resource */ 51 struct ui_resource *res; 50 /** UI */ 51 struct ui *ui; 52 /** UI window containing scrollbar */ 53 struct ui_window *window; 52 54 /** Callbacks */ 53 55 struct ui_scrollbar_cb *cb; … … 66 68 /** Up through is currently held down */ 67 69 bool up_through_held; 70 /** Pointer is inside up through */ 71 bool up_through_inside; 68 72 /** Down through is currently held down */ 69 73 bool down_through_held; 74 /** Pointer is inside down through */ 75 bool down_through_inside; 70 76 /** Position where thumb was pressed */ 71 77 gfx_coord2_t press_pos; … … 74 80 /** Thumb position */ 75 81 gfx_coord_t pos; 82 /** Last cursor position (when through is held) */ 83 gfx_coord2_t last_curs_pos; 76 84 }; 77 85 … … 97 105 extern errno_t ui_scrollbar_paint_gfx(ui_scrollbar_t *); 98 106 extern errno_t ui_scrollbar_paint_text(ui_scrollbar_t *); 99 extern errno_t ui_scrollbar_thumb_clear(ui_scrollbar_t *);100 107 extern void ui_scrollbar_get_geom(ui_scrollbar_t *, ui_scrollbar_geom_t *); 101 108 -
uspace/lib/ui/private/ui.h
rd4ea1f6 r8965860c 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <gfx/coord.h> 42 42 #include <display.h> 43 #include <fibril_synch.h> 43 44 #include <io/console.h> 44 45 #include <stdbool.h> … … 63 64 /** Windows (in stacking order, ui_window_t) */ 64 65 list_t windows; 66 /** UI lock */ 67 fibril_mutex_t lock; 68 /** Clickmatic */ 69 struct ui_clickmatic *clickmatic; 65 70 }; 66 71 -
uspace/lib/ui/src/scrollbar.c
rd4ea1f6 r8965860c 53 53 * button on the up/down through generates page up / page down events. 54 54 * 55 * TODO: Up/down buttons/throughs should be equipped with an autorepeat56 * mechanism: after an initial delay, start repeating at a preset rate.55 * Pressing and holding down mouse button on up / down button or up / down 56 * through will auto-scroll (using clickmatic). 57 57 */ 58 58 … … 65 65 #include <stdlib.h> 66 66 #include <str.h> 67 #include <ui/clickmatic.h> 67 68 #include <ui/control.h> 68 69 #include <ui/paint.h> 69 70 #include <ui/pbutton.h> 70 71 #include <ui/scrollbar.h> 72 #include <ui/ui.h> 73 #include <ui/window.h> 74 #include "../private/pbutton.h" 71 75 #include "../private/resource.h" 72 76 #include "../private/scrollbar.h" … … 92 96 93 97 static void ui_scrollbar_up_btn_down(ui_pbutton_t *, void *); 98 static void ui_scrollbar_up_btn_up(ui_pbutton_t *, void *); 94 99 static void ui_scrollbar_down_btn_down(ui_pbutton_t *, void *); 100 static void ui_scrollbar_down_btn_up(ui_pbutton_t *, void *); 95 101 static void ui_scrollbar_ctl_destroy(void *); 96 102 static errno_t ui_scrollbar_ctl_paint(void *); 97 103 static ui_evclaim_t ui_scrollbar_ctl_pos_event(void *, pos_event_t *); 98 104 99 ui_pbutton_cb_t ui_scrollbar_up_btn_cb = { 100 .down = ui_scrollbar_up_btn_down 105 static ui_pbutton_cb_t ui_scrollbar_up_btn_cb = { 106 .down = ui_scrollbar_up_btn_down, 107 .up = ui_scrollbar_up_btn_up 101 108 }; 102 109 103 ui_pbutton_cb_t ui_scrollbar_down_btn_cb = { 104 .down = ui_scrollbar_down_btn_down 110 static ui_pbutton_cb_t ui_scrollbar_down_btn_cb = { 111 .down = ui_scrollbar_down_btn_down, 112 .up = ui_scrollbar_down_btn_up 105 113 }; 106 114 107 115 /** Scrollbar control ops */ 108 ui_control_ops_t ui_scrollbar_ops = {116 static ui_control_ops_t ui_scrollbar_ops = { 109 117 .destroy = ui_scrollbar_ctl_destroy, 110 118 .paint = ui_scrollbar_ctl_paint, … … 112 120 }; 113 121 122 static void ui_scrollbar_cm_up(ui_clickmatic_t *, void *); 123 static void ui_scrollbar_cm_down(ui_clickmatic_t *, void *); 124 static void ui_scrollbar_cm_page_up(ui_clickmatic_t *, void *); 125 static void ui_scrollbar_cm_page_down(ui_clickmatic_t *, void *); 126 127 /** Scrollbar clickmatic up callbacks */ 128 ui_clickmatic_cb_t ui_scrollbar_clickmatic_up_cb = { 129 .clicked = ui_scrollbar_cm_up 130 }; 131 132 /** Scrollbar clickmatic down callbacks */ 133 ui_clickmatic_cb_t ui_scrollbar_clickmatic_down_cb = { 134 .clicked = ui_scrollbar_cm_down 135 }; 136 137 /** Scrollbar clickmatic page up callbacks */ 138 ui_clickmatic_cb_t ui_scrollbar_clickmatic_page_up_cb = { 139 .clicked = ui_scrollbar_cm_page_up 140 }; 141 142 /** Scrollbar clickmatic page down callbacks */ 143 ui_clickmatic_cb_t ui_scrollbar_clickmatic_page_down_cb = { 144 .clicked = ui_scrollbar_cm_page_down 145 }; 146 114 147 /** Create new scrollbar. 115 148 * 116 * @param resource UI resource 149 * @param ui UI 150 * @param window Window containing scrollbar 117 151 * @param rscrollbar Place to store pointer to new scrollbar 118 152 * @return EOK on success, ENOMEM if out of memory 119 153 */ 120 errno_t ui_scrollbar_create(ui_ resource_t *resource,154 errno_t ui_scrollbar_create(ui_t *ui, ui_window_t *window, 121 155 ui_scrollbar_t **rscrollbar) 122 156 { 123 157 ui_scrollbar_t *scrollbar; 158 ui_resource_t *resource; 124 159 errno_t rc; 160 161 resource = ui_window_get_res(window); 125 162 126 163 scrollbar = calloc(1, sizeof(ui_scrollbar_t)); … … 155 192 ui_scrollbar_def_thumb_len; 156 193 157 scrollbar->res = resource; 194 scrollbar->ui = ui; 195 scrollbar->window = window; 158 196 *rscrollbar = scrollbar; 159 197 return EOK; … … 283 321 gfx_rect_t *rect, gfx_rect_t *inside) 284 322 { 285 return ui_paint_bevel(scrollbar->res->gc, rect, 286 scrollbar->res->btn_highlight_color, 287 scrollbar->res->btn_shadow_color, ui_scrollbar_thumb_bevel_width, inside); 288 } 289 290 /** Determine scrollbar thumb rectagle. 291 * 292 * @param scrollbar Scrollbar 293 */ 294 static void ui_scrollbar_thumb_rect(ui_scrollbar_t *scrollbar, gfx_rect_t *rect) 295 { 296 ui_scrollbar_geom_t geom; 297 298 ui_scrollbar_get_geom(scrollbar, &geom); 299 *rect = geom.thumb_rect; 323 ui_resource_t *resource = ui_window_get_res(scrollbar->window); 324 325 return ui_paint_bevel(resource->gc, rect, 326 resource->btn_highlight_color, 327 resource->btn_shadow_color, ui_scrollbar_thumb_bevel_width, inside); 300 328 } 301 329 … … 310 338 gfx_coord_t ui_scrollbar_through_length(ui_scrollbar_t *scrollbar) 311 339 { 340 ui_resource_t *resource; 312 341 gfx_coord2_t dims; 313 342 gfx_coord_t w; 314 343 344 resource = ui_window_get_res(scrollbar->window); 345 315 346 gfx_rect_dims(&scrollbar->rect, &dims); 316 w = scrollbar->res->textmode ? ui_scrollbar_btn_len_text :347 w = resource->textmode ? ui_scrollbar_btn_len_text : 317 348 ui_scrollbar_btn_len; 318 349 return dims.x - 2 * w; … … 339 370 void ui_scrollbar_set_thumb_length(ui_scrollbar_t *scrollbar, gfx_coord_t len) 340 371 { 372 ui_resource_t *resource; 341 373 gfx_coord_t min_len; 342 374 gfx_coord_t max_len; 343 375 344 min_len = scrollbar->res->textmode ? 376 resource = ui_window_get_res(scrollbar->window); 377 378 min_len = resource->textmode ? 345 379 ui_scrollbar_min_thumb_len_text : 346 380 ui_scrollbar_min_thumb_len; … … 353 387 354 388 if (len != scrollbar->thumb_len) { 355 (void) ui_scrollbar_thumb_clear(scrollbar);356 389 scrollbar->thumb_len = len; 357 390 (void) ui_scrollbar_paint(scrollbar); … … 387 420 388 421 if (pos != scrollbar->pos) { 389 (void) ui_scrollbar_thumb_clear(scrollbar);390 422 scrollbar->pos = pos; 391 423 (void) ui_scrollbar_paint(scrollbar); 424 ui_scrollbar_throughs_update(scrollbar, 425 &scrollbar->last_curs_pos); 392 426 ui_scrollbar_moved(scrollbar, pos); 393 427 } … … 401 435 errno_t ui_scrollbar_paint_gfx(ui_scrollbar_t *scrollbar) 402 436 { 437 ui_resource_t *resource; 403 438 ui_scrollbar_geom_t geom; 404 439 gfx_rect_t brect; … … 406 441 errno_t rc; 407 442 443 resource = ui_window_get_res(scrollbar->window); 444 408 445 ui_scrollbar_get_geom(scrollbar, &geom); 409 446 410 447 /* Paint scrollbar frame */ 411 448 412 rc = ui_paint_inset_frame( scrollbar->res, &scrollbar->rect, NULL);449 rc = ui_paint_inset_frame(resource, &scrollbar->rect, NULL); 413 450 if (rc != EOK) 414 451 goto error; 415 452 416 453 /* Paint scrollbar up through */ 417 rc = gfx_set_color( scrollbar->res->gc,418 scrollbar->up_through_held ?419 scrollbar->res->sbar_act_through_color :420 scrollbar->res->sbar_through_color);421 if (rc != EOK) 422 goto error; 423 424 rc = gfx_fill_rect( scrollbar->res->gc, &geom.up_through_rect);454 rc = gfx_set_color(resource->gc, 455 scrollbar->up_through_held && scrollbar->up_through_inside ? 456 resource->sbar_act_through_color : 457 resource->sbar_through_color); 458 if (rc != EOK) 459 goto error; 460 461 rc = gfx_fill_rect(resource->gc, &geom.up_through_rect); 425 462 if (rc != EOK) 426 463 goto error; … … 428 465 /* Paint scrollbar down through */ 429 466 430 rc = gfx_set_color( scrollbar->res->gc,431 scrollbar->down_through_held ?432 scrollbar->res->sbar_act_through_color :433 scrollbar->res->sbar_through_color);434 if (rc != EOK) 435 goto error; 436 437 rc = gfx_fill_rect( scrollbar->res->gc, &geom.down_through_rect);467 rc = gfx_set_color(resource->gc, 468 scrollbar->down_through_held && scrollbar->down_through_inside ? 469 resource->sbar_act_through_color : 470 resource->sbar_through_color); 471 if (rc != EOK) 472 goto error; 473 474 rc = gfx_fill_rect(resource->gc, &geom.down_through_rect); 438 475 if (rc != EOK) 439 476 goto error; … … 441 478 /* Paint scrollbar thumb */ 442 479 443 rc = ui_scrollbar_paint_thumb_frame( scrollbar->res, &geom.thumb_rect,480 rc = ui_scrollbar_paint_thumb_frame(resource, &geom.thumb_rect, 444 481 ui_scrollbar_thumb_frame_thickness, &brect); 445 482 if (rc != EOK) … … 450 487 goto error; 451 488 452 rc = gfx_set_color( scrollbar->res->gc, scrollbar->res->btn_face_color);453 if (rc != EOK) 454 goto error; 455 456 rc = gfx_fill_rect( scrollbar->res->gc, &irect);489 rc = gfx_set_color(resource->gc, resource->btn_face_color); 490 if (rc != EOK) 491 goto error; 492 493 rc = gfx_fill_rect(resource->gc, &irect); 457 494 if (rc != EOK) 458 495 goto error; … … 466 503 goto error; 467 504 468 rc = gfx_update( scrollbar->res->gc);505 rc = gfx_update(resource->gc); 469 506 if (rc != EOK) 470 507 goto error; … … 482 519 errno_t ui_scrollbar_paint_text(ui_scrollbar_t *scrollbar) 483 520 { 521 ui_resource_t *resource; 484 522 gfx_coord2_t pos; 485 523 gfx_text_fmt_t fmt; … … 490 528 errno_t rc; 491 529 530 resource = ui_window_get_res(scrollbar->window); 531 492 532 /* Paint scrollbar through */ 493 533 … … 496 536 497 537 gfx_text_fmt_init(&fmt); 498 fmt.font = scrollbar->res->font;499 fmt.color = scrollbar->res->sbar_through_color;538 fmt.font = resource->font; 539 fmt.color = resource->sbar_through_color; 500 540 fmt.halign = gfx_halign_left; 501 541 fmt.valign = gfx_valign_top; … … 552 592 goto error; 553 593 554 rc = gfx_update( scrollbar->res->gc);594 rc = gfx_update(resource->gc); 555 595 if (rc != EOK) 556 596 goto error; … … 568 608 errno_t ui_scrollbar_paint(ui_scrollbar_t *scrollbar) 569 609 { 570 if (scrollbar->res->textmode) 610 ui_resource_t *resource = ui_window_get_res(scrollbar->window); 611 612 if (resource->textmode) 571 613 return ui_scrollbar_paint_text(scrollbar); 572 614 else … … 581 623 void ui_scrollbar_get_geom(ui_scrollbar_t *scrollbar, ui_scrollbar_geom_t *geom) 582 624 { 625 ui_resource_t *resource; 583 626 gfx_coord_t btn_len; 584 627 gfx_rect_t orect; 585 628 gfx_rect_t irect; 586 629 587 if (scrollbar->res->textmode) { 630 resource = ui_window_get_res(scrollbar->window); 631 632 if (resource->textmode) { 588 633 btn_len = ui_scrollbar_btn_len_text; 589 634 } else { … … 591 636 } 592 637 593 if ( scrollbar->res->textmode) {638 if (resource->textmode) { 594 639 irect = scrollbar->rect; 595 640 orect = scrollbar->rect; 596 641 } else { 597 ui_paint_get_inset_frame_inside( scrollbar->res,642 ui_paint_get_inset_frame_inside(resource, 598 643 &scrollbar->rect, &irect); 599 ui_paint_get_bevel_inside( scrollbar->res->gc,644 ui_paint_get_bevel_inside(resource->gc, 600 645 &scrollbar->rect, 1, &orect); 601 646 } … … 636 681 } 637 682 638 /** Clear scrollbar thumb.639 *640 * @param scrollbar Scrollbar641 * @return EOK on success or an error code642 */643 errno_t ui_scrollbar_thumb_clear(ui_scrollbar_t *scrollbar)644 {645 gfx_rect_t rect;646 errno_t rc;647 648 /* No need to clear thumb in text mode */649 if (scrollbar->res->textmode)650 return EOK;651 652 ui_scrollbar_thumb_rect(scrollbar, &rect);653 654 rc = gfx_set_color(scrollbar->res->gc, scrollbar->res->wnd_face_color);655 if (rc != EOK)656 goto error;657 658 rc = gfx_fill_rect(scrollbar->res->gc, &rect);659 if (rc != EOK)660 goto error;661 662 return EOK;663 error:664 return rc;665 }666 667 683 /** Press down scrollbar thumb. 668 684 * … … 688 704 void ui_scrollbar_up_through_press(ui_scrollbar_t *scrollbar) 689 705 { 690 if (scrollbar->up_through_held) 691 return; 706 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 692 707 693 708 scrollbar->up_through_held = true; 694 (void) ui_scrollbar_paint(scrollbar); 695 696 ui_scrollbar_page_up(scrollbar); 709 scrollbar->up_through_inside = true; 710 711 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_up_cb, 712 (void *) scrollbar); 713 ui_clickmatic_press(clickmatic); 697 714 } 698 715 … … 703 720 void ui_scrollbar_down_through_press(ui_scrollbar_t *scrollbar) 704 721 { 705 if (scrollbar->down_through_held) 706 return; 722 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 707 723 708 724 scrollbar->down_through_held = true; 709 (void) ui_scrollbar_paint(scrollbar); 710 711 ui_scrollbar_page_down(scrollbar); 725 scrollbar->down_through_inside = true; 726 727 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_down_cb, 728 (void *) scrollbar); 729 ui_clickmatic_press(clickmatic); 712 730 } 713 731 … … 719 737 void ui_scrollbar_release(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos) 720 738 { 739 ui_clickmatic_t *clickmatic; 740 721 741 if (scrollbar->thumb_held) { 722 742 ui_scrollbar_update(scrollbar, pos); … … 725 745 726 746 if (scrollbar->up_through_held || scrollbar->down_through_held) { 747 clickmatic = ui_get_clickmatic(scrollbar->ui); 748 ui_clickmatic_release(clickmatic); 749 ui_clickmatic_set_cb(clickmatic, NULL, NULL); 750 727 751 scrollbar->up_through_held = false; 728 752 scrollbar->down_through_held = false; … … 731 755 } 732 756 757 /** Update state of scrollbar throuhgs. 758 * 759 * Update state of scrollbar throughs after mouse cursor or thumb has moved. 760 * 761 * @param scrollbar Scrollbar 762 * @param pos Mouse cursor position 763 */ 764 void ui_scrollbar_throughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos) 765 { 766 ui_scrollbar_geom_t geom; 767 bool inside_up; 768 bool inside_down; 769 770 ui_scrollbar_get_geom(scrollbar, &geom); 771 772 inside_up = gfx_pix_inside_rect(pos, &geom.up_through_rect); 773 inside_down = gfx_pix_inside_rect(pos, &geom.down_through_rect); 774 775 if (inside_up && !scrollbar->up_through_inside) { 776 scrollbar->up_through_inside = true; 777 (void) ui_scrollbar_paint(scrollbar); 778 } else if (!inside_up && scrollbar->up_through_inside) { 779 scrollbar->up_through_inside = false; 780 (void) ui_scrollbar_paint(scrollbar); 781 } 782 783 if (inside_down && !scrollbar->down_through_inside) { 784 scrollbar->down_through_inside = true; 785 (void) ui_scrollbar_paint(scrollbar); 786 } else if (!inside_down && scrollbar->down_through_inside) { 787 scrollbar->down_through_inside = false; 788 (void) ui_scrollbar_paint(scrollbar); 789 } 790 } 791 733 792 /** Pointer moved. 734 793 * … … 744 803 ui_scrollbar_set_pos(scrollbar, spos); 745 804 } 805 806 ui_scrollbar_throughs_update(scrollbar, pos); 746 807 } 747 808 … … 845 906 case POS_UPDATE: 846 907 ui_scrollbar_update(scrollbar, &pos); 908 scrollbar->last_curs_pos = pos; 847 909 break; 848 910 case POS_DCLICK: … … 861 923 { 862 924 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 863 864 ui_scrollbar_up(scrollbar); 925 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 926 927 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_up_cb, 928 (void *) scrollbar); 929 ui_clickmatic_press(clickmatic); 930 } 931 932 /** Scrollbar up button released. 933 * 934 * @param pbutton Up button 935 * @param arg Argument (ui_scrollbar_t *) 936 */ 937 static void ui_scrollbar_up_btn_up(ui_pbutton_t *pbutton, void *arg) 938 { 939 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 940 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 941 942 ui_clickmatic_release(clickmatic); 943 ui_clickmatic_set_cb(clickmatic, NULL, NULL); 865 944 } 866 945 … … 873 952 { 874 953 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 875 876 ui_scrollbar_down(scrollbar); 954 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 955 956 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_down_cb, 957 (void *) scrollbar); 958 ui_clickmatic_press(clickmatic); 959 } 960 961 /** Scrollbar down button released. 962 * 963 * @param pbutton Down button 964 * @param arg Argument (ui_scrollbar_t *) 965 */ 966 static void ui_scrollbar_down_btn_up(ui_pbutton_t *pbutton, void *arg) 967 { 968 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 969 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 970 971 ui_clickmatic_release(clickmatic); 972 ui_clickmatic_set_cb(clickmatic, NULL, NULL); 877 973 } 878 974 … … 908 1004 ui_evclaim_t ui_scrollbar_ctl_pos_event(void *arg, pos_event_t *event) 909 1005 { 910 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *) 1006 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 911 1007 912 1008 return ui_scrollbar_pos_event(scrollbar, event); 913 1009 } 914 1010 1011 /** Scrollbar clickmatic up button click event. 1012 * 1013 * @param clickmatic Clickmatic 1014 * @param arg Argument (ui_scrollbar_t *) 1015 */ 1016 static void ui_scrollbar_cm_up(ui_clickmatic_t *clickmatic, void *arg) 1017 { 1018 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1019 1020 if (scrollbar->up_btn->inside) 1021 ui_scrollbar_up(scrollbar); 1022 } 1023 1024 /** Scrollbar clickmatic down button click event. 1025 * 1026 * @param clickmatic Clickmatic 1027 * @param arg Argument (ui_scrollbar_t *) 1028 */ 1029 static void ui_scrollbar_cm_down(ui_clickmatic_t *clickmatic, void *arg) 1030 { 1031 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1032 1033 if (scrollbar->down_btn->inside) 1034 ui_scrollbar_down(scrollbar); 1035 } 1036 1037 /** Scrollbar clickmatic up through click event. 1038 * 1039 * @param clickmatic Clickmatic 1040 * @param arg Argument (ui_scrollbar_t *) 1041 */ 1042 static void ui_scrollbar_cm_page_up(ui_clickmatic_t *clickmatic, void *arg) 1043 { 1044 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1045 1046 if (scrollbar->up_through_inside) 1047 ui_scrollbar_page_up(scrollbar); 1048 } 1049 1050 /** Scrollbar clickmatic down through click event. 1051 * 1052 * @param clickmatic Clickmatic 1053 * @param arg Argument (ui_scrollbar_t *) 1054 */ 1055 static void ui_scrollbar_cm_page_down(ui_clickmatic_t *clickmatic, void *arg) 1056 { 1057 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1058 1059 if (scrollbar->down_through_inside) 1060 ui_scrollbar_page_down(scrollbar); 1061 } 1062 915 1063 /** @} 916 1064 */ -
uspace/lib/ui/src/ui.c
rd4ea1f6 r8965860c 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <errno.h> 40 40 #include <fibril.h> 41 #include <fibril_synch.h> 41 42 #include <gfx/color.h> 42 43 #include <gfx/cursor.h> … … 47 48 #include <str.h> 48 49 #include <task.h> 50 #include <ui/clickmatic.h> 49 51 #include <ui/ui.h> 50 52 #include <ui/wdecor.h> … … 198 200 { 199 201 ui_t *ui; 202 errno_t rc; 200 203 201 204 ui = calloc(1, sizeof(ui_t)); … … 203 206 return ENOMEM; 204 207 208 rc = ui_clickmatic_create(ui, &ui->clickmatic); 209 if (rc != EOK) { 210 free(ui); 211 return rc; 212 } 213 205 214 ui->console = console; 206 215 list_initialize(&ui->windows); 216 fibril_mutex_initialize(&ui->lock); 207 217 *rui = ui; 208 218 return EOK; … … 218 228 { 219 229 ui_t *ui; 230 errno_t rc; 220 231 221 232 ui = calloc(1, sizeof(ui_t)); … … 223 234 return ENOMEM; 224 235 236 rc = ui_clickmatic_create(ui, &ui->clickmatic); 237 if (rc != EOK) { 238 free(ui); 239 return rc; 240 } 241 225 242 ui->display = disp; 226 243 list_initialize(&ui->windows); 244 fibril_mutex_initialize(&ui->lock); 227 245 *rui = ui; 228 246 return EOK; … … 443 461 } 444 462 463 /** Lock UI. 464 * 465 * Block UI from calling window callbacks. @c ui_lock() and @c ui_unlock() 466 * must be used when accessing UI resources from a fibril (as opposed to 467 * from a window callback). 468 * 469 * @param ui UI 470 */ 471 void ui_lock(ui_t *ui) 472 { 473 fibril_mutex_lock(&ui->lock); 474 } 475 476 /** Unlock UI. 477 * 478 * Allow UI to call window callbacks. @c ui_lock() and @c ui_unlock() 479 * must be used when accessing window resources from a fibril (as opposed to 480 * from a window callback). 481 * 482 * @param ui UI 483 */ 484 void ui_unlock(ui_t *ui) 485 { 486 fibril_mutex_unlock(&ui->lock); 487 } 488 445 489 /** Terminate user interface. 446 490 * … … 480 524 } 481 525 526 /** Get clickmatic from UI. 527 * 528 * @pararm ui UI 529 * @return Clickmatic 530 */ 531 ui_clickmatic_t *ui_get_clickmatic(ui_t *ui) 532 { 533 return ui->clickmatic; 534 } 535 482 536 /** @} 483 537 */ -
uspace/lib/ui/src/window.c
rd4ea1f6 r8965860c 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 766 766 { 767 767 ui_window_t *window = (ui_window_t *) arg; 768 768 ui_t *ui = window->ui; 769 770 ui_lock(ui); 769 771 ui_window_send_close(window); 772 ui_unlock(ui); 770 773 } 771 774 … … 774 777 { 775 778 ui_window_t *window = (ui_window_t *) arg; 779 780 ui_lock(window->ui); 776 781 777 782 if (window->wdecor != NULL) { … … 781 786 782 787 ui_window_send_focus(window); 788 ui_unlock(window->ui); 783 789 } 784 790 … … 788 794 ui_window_t *window = (ui_window_t *) arg; 789 795 790 (void) window;796 ui_lock(window->ui); 791 797 ui_window_send_kbd(window, kbd_event); 798 ui_unlock(window->ui); 792 799 } 793 800 … … 801 808 return; 802 809 810 ui_lock(window->ui); 803 811 ui_wdecor_pos_event(window->wdecor, event); 804 812 ui_window_send_pos(window, event); 813 ui_unlock(window->ui); 805 814 } 806 815 … … 817 826 return; 818 827 828 ui_lock(window->ui); 819 829 (void) ui_window_resize(window, rect); 820 830 (void) ui_window_paint(window); 831 ui_unlock(window->ui); 821 832 } 822 833 … … 825 836 { 826 837 ui_window_t *window = (ui_window_t *) arg; 838 839 ui_lock(window->ui); 827 840 828 841 if (window->wdecor != NULL) { … … 832 845 833 846 ui_window_send_unfocus(window); 847 ui_unlock(window->ui); 834 848 } 835 849 -
uspace/lib/ui/test/main.c
rd4ea1f6 r8965860c 34 34 PCUT_IMPORT(control); 35 35 PCUT_IMPORT(checkbox); 36 PCUT_IMPORT(clickmatic); 36 37 PCUT_IMPORT(entry); 37 38 PCUT_IMPORT(file_dialog); -
uspace/lib/ui/test/scrollbar.c
rd4ea1f6 r8965860c 35 35 #include <ui/scrollbar.h> 36 36 #include <ui/resource.h> 37 #include <ui/ui.h> 38 #include <ui/window.h> 37 39 #include "../private/pbutton.h" 38 40 #include "../private/scrollbar.h" … … 41 43 42 44 PCUT_TEST_SUITE(scrollbar); 43 44 static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);45 static errno_t testgc_set_color(void *, gfx_color_t *);46 static errno_t testgc_fill_rect(void *, gfx_rect_t *);47 static errno_t testgc_update(void *);48 static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,49 gfx_bitmap_alloc_t *, void **);50 static errno_t testgc_bitmap_destroy(void *);51 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);52 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);53 54 static gfx_context_ops_t ops = {55 .set_clip_rect = testgc_set_clip_rect,56 .set_color = testgc_set_color,57 .fill_rect = testgc_fill_rect,58 .update = testgc_update,59 .bitmap_create = testgc_bitmap_create,60 .bitmap_destroy = testgc_bitmap_destroy,61 .bitmap_render = testgc_bitmap_render,62 .bitmap_get_alloc = testgc_bitmap_get_alloc63 };64 45 65 46 static void test_scrollbar_up(ui_scrollbar_t *, void *); … … 79 60 static ui_scrollbar_cb_t dummy_scrollbar_cb = { 80 61 }; 81 82 typedef struct {83 bool bm_created;84 bool bm_destroyed;85 gfx_bitmap_params_t bm_params;86 void *bm_pixels;87 gfx_rect_t bm_srect;88 gfx_coord2_t bm_offs;89 bool bm_rendered;90 bool bm_got_alloc;91 } test_gc_t;92 93 typedef struct {94 test_gc_t *tgc;95 gfx_bitmap_alloc_t alloc;96 bool myalloc;97 } testgc_bitmap_t;98 62 99 63 typedef struct { … … 109 73 PCUT_TEST(create_destroy) 110 74 { 111 errno_t rc; 112 gfx_context_t *gc = NULL; 113 test_gc_t tgc; 114 ui_resource_t *resource = NULL; 75 ui_t *ui = NULL; 76 ui_window_t *window = NULL; 77 ui_wnd_params_t params; 115 78 ui_scrollbar_t *scrollbar = NULL; 116 117 memset(&tgc, 0, sizeof(tgc)); 118 rc = gfx_context_new(&ops, &tgc, &gc); 119 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 120 121 rc = ui_resource_create(gc, false, &resource); 122 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 123 PCUT_ASSERT_NOT_NULL(resource); 124 125 rc = ui_scrollbar_create(resource, &scrollbar); 79 errno_t rc; 80 81 rc = ui_create_disp(NULL, &ui); 82 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 83 84 ui_wnd_params_init(¶ms); 85 params.caption = "Hello"; 86 87 rc = ui_window_create(ui, ¶ms, &window); 88 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 89 PCUT_ASSERT_NOT_NULL(window); 90 91 rc = ui_scrollbar_create(ui, window, &scrollbar); 126 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 127 93 PCUT_ASSERT_NOT_NULL(scrollbar); 128 94 129 95 ui_scrollbar_destroy(scrollbar); 130 ui_resource_destroy(resource); 131 132 rc = gfx_context_delete(gc); 133 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 96 ui_window_destroy(window); 97 ui_destroy(ui); 134 98 } 135 99 … … 143 107 PCUT_TEST(ctl) 144 108 { 145 errno_t rc; 146 gfx_context_t *gc = NULL; 147 test_gc_t tgc; 148 ui_resource_t *resource = NULL; 109 ui_t *ui = NULL; 110 ui_window_t *window = NULL; 111 ui_wnd_params_t params; 149 112 ui_scrollbar_t *scrollbar = NULL; 150 113 ui_control_t *control; 151 152 memset(&tgc, 0, sizeof(tgc)); 153 rc = gfx_context_new(&ops, &tgc, &gc); 154 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 155 156 rc = ui_resource_create(gc, false, &resource); 157 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 158 PCUT_ASSERT_NOT_NULL(resource); 159 160 rc = ui_scrollbar_create(resource, &scrollbar); 114 errno_t rc; 115 116 rc = ui_create_disp(NULL, &ui); 117 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 118 119 ui_wnd_params_init(¶ms); 120 params.caption = "Hello"; 121 122 rc = ui_window_create(ui, ¶ms, &window); 123 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 124 PCUT_ASSERT_NOT_NULL(window); 125 126 rc = ui_scrollbar_create(ui, window, &scrollbar); 161 127 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 162 128 PCUT_ASSERT_NOT_NULL(scrollbar); … … 166 132 167 133 ui_control_destroy(control); 168 ui_resource_destroy(resource); 169 170 rc = gfx_context_delete(gc); 171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 134 ui_window_destroy(window); 135 ui_destroy(ui); 172 136 } 173 137 … … 175 139 PCUT_TEST(set_rect) 176 140 { 177 errno_t rc; 178 gfx_context_t *gc = NULL; 179 test_gc_t tgc; 180 ui_resource_t *resource = NULL; 141 ui_t *ui = NULL; 142 ui_window_t *window = NULL; 143 ui_wnd_params_t params; 181 144 ui_scrollbar_t *scrollbar = NULL; 182 145 gfx_rect_t rect; 183 184 memset(&tgc, 0, sizeof(tgc)); 185 rc = gfx_context_new(&ops, &tgc, &gc); 186 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 187 188 rc = ui_resource_create(gc, false, &resource); 189 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 190 PCUT_ASSERT_NOT_NULL(resource); 191 192 rc = ui_scrollbar_create(resource, &scrollbar); 146 errno_t rc; 147 148 rc = ui_create_disp(NULL, &ui); 149 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 150 151 ui_wnd_params_init(¶ms); 152 params.caption = "Hello"; 153 154 rc = ui_window_create(ui, ¶ms, &window); 155 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 156 PCUT_ASSERT_NOT_NULL(window); 157 158 rc = ui_scrollbar_create(ui, window, &scrollbar); 193 159 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 194 160 PCUT_ASSERT_NOT_NULL(scrollbar); … … 206 172 207 173 ui_scrollbar_destroy(scrollbar); 208 ui_resource_destroy(resource); 209 210 rc = gfx_context_delete(gc); 211 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 174 ui_window_destroy(window); 175 ui_destroy(ui); 212 176 } 213 177 … … 215 179 PCUT_TEST(paint_gfx) 216 180 { 217 errno_t rc; 218 gfx_context_t *gc = NULL; 219 test_gc_t tgc; 220 ui_resource_t *resource = NULL; 221 ui_scrollbar_t *scrollbar; 222 223 memset(&tgc, 0, sizeof(tgc)); 224 rc = gfx_context_new(&ops, &tgc, &gc); 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 227 rc = ui_resource_create(gc, false, &resource); 228 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 229 PCUT_ASSERT_NOT_NULL(resource); 230 231 rc = ui_scrollbar_create(resource, &scrollbar); 181 ui_t *ui = NULL; 182 ui_window_t *window = NULL; 183 ui_wnd_params_t params; 184 ui_scrollbar_t *scrollbar; 185 errno_t rc; 186 187 rc = ui_create_disp(NULL, &ui); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 ui_wnd_params_init(¶ms); 191 params.caption = "Hello"; 192 193 rc = ui_window_create(ui, ¶ms, &window); 194 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 195 PCUT_ASSERT_NOT_NULL(window); 196 197 rc = ui_scrollbar_create(ui, window, &scrollbar); 232 198 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 233 199 … … 236 202 237 203 ui_scrollbar_destroy(scrollbar); 238 ui_resource_destroy(resource); 239 240 rc = gfx_context_delete(gc); 241 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 204 ui_window_destroy(window); 205 ui_destroy(ui); 242 206 } 243 207 … … 245 209 PCUT_TEST(paint_text) 246 210 { 247 errno_t rc; 248 gfx_context_t *gc = NULL; 249 test_gc_t tgc; 250 ui_resource_t *resource = NULL; 251 ui_scrollbar_t *scrollbar; 252 gfx_rect_t rect; 253 254 memset(&tgc, 0, sizeof(tgc)); 255 rc = gfx_context_new(&ops, &tgc, &gc); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 rc = ui_resource_create(gc, true, &resource); 259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 260 PCUT_ASSERT_NOT_NULL(resource); 261 262 rc = ui_scrollbar_create(resource, &scrollbar); 211 ui_t *ui = NULL; 212 ui_window_t *window = NULL; 213 ui_wnd_params_t params; 214 ui_scrollbar_t *scrollbar; 215 gfx_rect_t rect; 216 errno_t rc; 217 218 rc = ui_create_disp(NULL, &ui); 219 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 220 221 ui_wnd_params_init(¶ms); 222 params.caption = "Hello"; 223 224 rc = ui_window_create(ui, ¶ms, &window); 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 PCUT_ASSERT_NOT_NULL(window); 227 228 rc = ui_scrollbar_create(ui, window, &scrollbar); 263 229 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 264 230 … … 273 239 274 240 ui_scrollbar_destroy(scrollbar); 275 ui_resource_destroy(resource); 276 277 rc = gfx_context_delete(gc); 278 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 241 ui_window_destroy(window); 242 ui_destroy(ui); 243 } 244 245 /** ui_scrollbar_get_geom() returns scrollbar geometry */ 246 PCUT_TEST(get_geom) 247 { 248 ui_t *ui = NULL; 249 ui_window_t *window = NULL; 250 ui_wnd_params_t params; 251 ui_scrollbar_t *scrollbar; 252 ui_scrollbar_geom_t geom; 253 gfx_rect_t rect; 254 errno_t rc; 255 256 rc = ui_create_disp(NULL, &ui); 257 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 258 259 ui_wnd_params_init(¶ms); 260 params.caption = "Hello"; 261 262 rc = ui_window_create(ui, ¶ms, &window); 263 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 264 PCUT_ASSERT_NOT_NULL(window); 265 266 rc = ui_scrollbar_create(ui, window, &scrollbar); 267 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 268 269 rect.p0.x = 10; 270 rect.p0.y = 10; 271 rect.p1.x = 100; 272 rect.p1.y = 30; 273 ui_scrollbar_set_rect(scrollbar, &rect); 274 275 ui_scrollbar_get_geom(scrollbar, &geom); 276 PCUT_ASSERT_INT_EQUALS(11, geom.up_btn_rect.p0.x); 277 PCUT_ASSERT_INT_EQUALS(11, geom.up_btn_rect.p0.y); 278 PCUT_ASSERT_INT_EQUALS(99, geom.down_btn_rect.p1.x); 279 PCUT_ASSERT_INT_EQUALS(29, geom.down_btn_rect.p1.y); 280 281 ui_scrollbar_destroy(scrollbar); 282 ui_window_destroy(window); 283 ui_destroy(ui); 279 284 } 280 285 … … 282 287 PCUT_TEST(through_length) 283 288 { 284 errno_t rc; 285 gfx_context_t *gc = NULL; 286 test_gc_t tgc; 287 ui_resource_t *resource = NULL; 289 ui_t *ui = NULL; 290 ui_window_t *window = NULL; 291 ui_wnd_params_t params; 288 292 ui_scrollbar_t *scrollbar; 289 293 gfx_coord_t length; 290 294 gfx_rect_t rect; 291 292 memset(&tgc, 0, sizeof(tgc)); 293 rc = gfx_context_new(&ops, &tgc, &gc); 294 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 295 296 rc = ui_resource_create(gc, false, &resource); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 PCUT_ASSERT_NOT_NULL(resource); 299 300 rc = ui_scrollbar_create(resource, &scrollbar); 295 errno_t rc; 296 297 rc = ui_create_disp(NULL, &ui); 298 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 299 300 ui_wnd_params_init(¶ms); 301 params.caption = "Hello"; 302 303 rc = ui_window_create(ui, ¶ms, &window); 304 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 305 PCUT_ASSERT_NOT_NULL(window); 306 307 rc = ui_scrollbar_create(ui, window, &scrollbar); 301 308 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 302 309 … … 315 322 316 323 ui_scrollbar_destroy(scrollbar); 317 ui_resource_destroy(resource); 318 319 rc = gfx_context_delete(gc); 320 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 324 ui_window_destroy(window); 325 ui_destroy(ui); 321 326 } 322 327 … … 324 329 PCUT_TEST(move_length) 325 330 { 326 errno_t rc; 327 gfx_context_t *gc = NULL; 328 test_gc_t tgc; 329 ui_resource_t *resource = NULL; 331 ui_t *ui = NULL; 332 ui_window_t *window = NULL; 333 ui_wnd_params_t params; 330 334 ui_scrollbar_t *scrollbar; 331 335 gfx_coord_t length; 332 336 gfx_rect_t rect; 333 334 memset(&tgc, 0, sizeof(tgc)); 335 rc = gfx_context_new(&ops, &tgc, &gc); 336 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 337 338 rc = ui_resource_create(gc, false, &resource); 339 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 340 PCUT_ASSERT_NOT_NULL(resource); 341 342 rc = ui_scrollbar_create(resource, &scrollbar); 337 errno_t rc; 338 339 rc = ui_create_disp(NULL, &ui); 340 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 341 342 ui_wnd_params_init(¶ms); 343 params.caption = "Hello"; 344 345 rc = ui_window_create(ui, ¶ms, &window); 346 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 347 PCUT_ASSERT_NOT_NULL(window); 348 349 rc = ui_scrollbar_create(ui, window, &scrollbar); 343 350 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 344 351 … … 357 364 358 365 ui_scrollbar_destroy(scrollbar); 359 ui_resource_destroy(resource); 360 361 rc = gfx_context_delete(gc); 362 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 366 ui_window_destroy(window); 367 ui_destroy(ui); 363 368 } 364 369 … … 366 371 PCUT_TEST(get_pos) 367 372 { 368 errno_t rc; 369 gfx_context_t *gc = NULL; 370 test_gc_t tgc; 371 ui_resource_t *resource = NULL; 373 ui_t *ui = NULL; 374 ui_window_t *window = NULL; 375 ui_wnd_params_t params; 372 376 ui_scrollbar_t *scrollbar; 373 377 gfx_coord_t pos; 374 378 gfx_rect_t rect; 375 376 memset(&tgc, 0, sizeof(tgc)); 377 rc = gfx_context_new(&ops, &tgc, &gc); 378 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 379 380 rc = ui_resource_create(gc, false, &resource); 381 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 382 PCUT_ASSERT_NOT_NULL(resource); 383 384 rc = ui_scrollbar_create(resource, &scrollbar); 379 errno_t rc; 380 381 rc = ui_create_disp(NULL, &ui); 382 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 384 ui_wnd_params_init(¶ms); 385 params.caption = "Hello"; 386 387 rc = ui_window_create(ui, ¶ms, &window); 388 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 389 PCUT_ASSERT_NOT_NULL(window); 390 391 rc = ui_scrollbar_create(ui, window, &scrollbar); 385 392 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 386 393 … … 398 405 399 406 ui_scrollbar_destroy(scrollbar); 400 ui_resource_destroy(resource); 401 402 rc = gfx_context_delete(gc); 403 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 407 ui_window_destroy(window); 408 ui_destroy(ui); 404 409 } 405 410 … … 407 412 PCUT_TEST(set_thumb_length) 408 413 { 409 errno_t rc; 410 gfx_context_t *gc = NULL; 411 test_gc_t tgc; 412 ui_resource_t *resource = NULL; 413 ui_scrollbar_t *scrollbar; 414 gfx_rect_t rect; 415 416 memset(&tgc, 0, sizeof(tgc)); 417 rc = gfx_context_new(&ops, &tgc, &gc); 418 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 419 420 rc = ui_resource_create(gc, false, &resource); 421 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 422 PCUT_ASSERT_NOT_NULL(resource); 423 424 rc = ui_scrollbar_create(resource, &scrollbar); 414 ui_t *ui = NULL; 415 ui_window_t *window = NULL; 416 ui_wnd_params_t params; 417 ui_scrollbar_t *scrollbar; 418 gfx_rect_t rect; 419 errno_t rc; 420 421 rc = ui_create_disp(NULL, &ui); 422 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 423 424 ui_wnd_params_init(¶ms); 425 params.caption = "Hello"; 426 427 rc = ui_window_create(ui, ¶ms, &window); 428 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 PCUT_ASSERT_NOT_NULL(window); 430 431 rc = ui_scrollbar_create(ui, window, &scrollbar); 425 432 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 426 433 … … 437 444 438 445 ui_scrollbar_destroy(scrollbar); 439 ui_resource_destroy(resource); 440 441 rc = gfx_context_delete(gc); 442 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 446 ui_window_destroy(window); 447 ui_destroy(ui); 443 448 } 444 449 … … 446 451 PCUT_TEST(set_pos) 447 452 { 448 errno_t rc; 449 gfx_context_t *gc = NULL; 450 test_gc_t tgc; 451 ui_resource_t *resource = NULL; 453 ui_t *ui = NULL; 454 ui_window_t *window = NULL; 455 ui_wnd_params_t params; 452 456 ui_scrollbar_t *scrollbar; 453 457 gfx_coord_t pos; 454 458 gfx_rect_t rect; 455 456 memset(&tgc, 0, sizeof(tgc)); 457 rc = gfx_context_new(&ops, &tgc, &gc); 458 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 459 460 rc = ui_resource_create(gc, false, &resource); 461 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 462 PCUT_ASSERT_NOT_NULL(resource); 463 464 rc = ui_scrollbar_create(resource, &scrollbar); 459 errno_t rc; 460 461 rc = ui_create_disp(NULL, &ui); 462 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 463 464 ui_wnd_params_init(¶ms); 465 params.caption = "Hello"; 466 467 rc = ui_window_create(ui, ¶ms, &window); 468 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 469 PCUT_ASSERT_NOT_NULL(window); 470 471 rc = ui_scrollbar_create(ui, window, &scrollbar); 465 472 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 466 473 … … 489 496 490 497 ui_scrollbar_destroy(scrollbar); 491 ui_resource_destroy(resource); 492 493 rc = gfx_context_delete(gc); 494 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 ui_window_destroy(window); 499 ui_destroy(ui); 495 500 } 496 501 … … 498 503 PCUT_TEST(thumb_press_release) 499 504 { 500 errno_t rc; 501 gfx_context_t *gc = NULL; 502 test_gc_t tgc; 503 ui_resource_t *resource = NULL; 505 ui_t *ui = NULL; 506 ui_window_t *window = NULL; 507 ui_wnd_params_t params; 504 508 gfx_coord2_t pos; 505 509 gfx_rect_t rect; 506 510 ui_scrollbar_t *scrollbar; 507 511 test_cb_resp_t resp; 508 509 memset(&tgc, 0, sizeof(tgc)); 510 rc = gfx_context_new(&ops, &tgc, &gc); 511 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 512 513 rc = ui_resource_create(gc, false, &resource); 514 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 515 PCUT_ASSERT_NOT_NULL(resource); 516 517 rc = ui_scrollbar_create(resource, &scrollbar); 512 errno_t rc; 513 514 rc = ui_create_disp(NULL, &ui); 515 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 516 517 ui_wnd_params_init(¶ms); 518 params.caption = "Hello"; 519 520 rc = ui_window_create(ui, ¶ms, &window); 521 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 522 PCUT_ASSERT_NOT_NULL(window); 523 524 rc = ui_scrollbar_create(ui, window, &scrollbar); 518 525 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 519 526 … … 545 552 546 553 ui_scrollbar_destroy(scrollbar); 547 ui_resource_destroy(resource); 548 549 rc = gfx_context_delete(gc); 550 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 554 ui_window_destroy(window); 555 ui_destroy(ui); 551 556 } 552 557 … … 554 559 PCUT_TEST(thumb_press_update_release) 555 560 { 556 errno_t rc; 557 gfx_context_t *gc = NULL; 558 test_gc_t tgc; 559 ui_resource_t *resource = NULL; 561 ui_t *ui = NULL; 562 ui_window_t *window = NULL; 563 ui_wnd_params_t params; 560 564 gfx_coord2_t pos; 561 565 gfx_rect_t rect; 562 566 ui_scrollbar_t *scrollbar; 563 567 test_cb_resp_t resp; 564 565 memset(&tgc, 0, sizeof(tgc)); 566 rc = gfx_context_new(&ops, &tgc, &gc); 567 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 568 569 rc = ui_resource_create(gc, false, &resource); 570 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 571 PCUT_ASSERT_NOT_NULL(resource); 572 573 rc = ui_scrollbar_create(resource, &scrollbar); 568 errno_t rc; 569 570 rc = ui_create_disp(NULL, &ui); 571 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 572 573 ui_wnd_params_init(¶ms); 574 params.caption = "Hello"; 575 576 rc = ui_window_create(ui, ¶ms, &window); 577 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 578 PCUT_ASSERT_NOT_NULL(window); 579 580 rc = ui_scrollbar_create(ui, window, &scrollbar); 574 581 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 575 582 … … 609 616 610 617 ui_scrollbar_destroy(scrollbar); 611 ui_resource_destroy(resource); 612 613 rc = gfx_context_delete(gc); 614 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 618 ui_window_destroy(window); 619 ui_destroy(ui); 615 620 } 616 621 … … 618 623 PCUT_TEST(up_through_press_release) 619 624 { 620 errno_t rc; 621 gfx_context_t *gc = NULL; 622 test_gc_t tgc; 623 ui_resource_t *resource = NULL; 625 ui_t *ui = NULL; 626 ui_window_t *window = NULL; 627 ui_wnd_params_t params; 624 628 gfx_coord2_t pos; 625 629 gfx_rect_t rect; 626 630 ui_scrollbar_t *scrollbar; 627 631 test_cb_resp_t resp; 628 629 memset(&tgc, 0, sizeof(tgc)); 630 rc = gfx_context_new(&ops, &tgc, &gc); 631 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 632 633 rc = ui_resource_create(gc, false, &resource); 634 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 635 PCUT_ASSERT_NOT_NULL(resource); 636 637 rc = ui_scrollbar_create(resource, &scrollbar); 632 errno_t rc; 633 634 rc = ui_create_disp(NULL, &ui); 635 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 636 637 ui_wnd_params_init(¶ms); 638 params.caption = "Hello"; 639 640 rc = ui_window_create(ui, ¶ms, &window); 641 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 642 PCUT_ASSERT_NOT_NULL(window); 643 644 rc = ui_scrollbar_create(ui, window, &scrollbar); 638 645 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 639 646 … … 661 668 662 669 ui_scrollbar_destroy(scrollbar); 663 ui_resource_destroy(resource); 664 665 rc = gfx_context_delete(gc); 666 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 670 ui_window_destroy(window); 671 ui_destroy(ui); 667 672 } 668 673 … … 670 675 PCUT_TEST(down_through_press_release) 671 676 { 672 errno_t rc; 673 gfx_context_t *gc = NULL; 674 test_gc_t tgc; 675 ui_resource_t *resource = NULL; 677 ui_t *ui = NULL; 678 ui_window_t *window = NULL; 679 ui_wnd_params_t params; 676 680 gfx_coord2_t pos; 677 681 gfx_rect_t rect; 678 682 ui_scrollbar_t *scrollbar; 679 683 test_cb_resp_t resp; 680 681 memset(&tgc, 0, sizeof(tgc)); 682 rc = gfx_context_new(&ops, &tgc, &gc); 683 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 684 685 rc = ui_resource_create(gc, false, &resource); 686 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 687 PCUT_ASSERT_NOT_NULL(resource); 688 689 rc = ui_scrollbar_create(resource, &scrollbar); 684 errno_t rc; 685 686 rc = ui_create_disp(NULL, &ui); 687 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 688 689 ui_wnd_params_init(¶ms); 690 params.caption = "Hello"; 691 692 rc = ui_window_create(ui, ¶ms, &window); 693 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 694 PCUT_ASSERT_NOT_NULL(window); 695 696 rc = ui_scrollbar_create(ui, window, &scrollbar); 690 697 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 691 698 … … 713 720 714 721 ui_scrollbar_destroy(scrollbar); 715 ui_resource_destroy(resource); 716 717 rc = gfx_context_delete(gc); 718 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 722 ui_window_destroy(window); 723 ui_destroy(ui); 724 } 725 726 /** Updating state of throughs when cursor or thumb moves */ 727 PCUT_TEST(throughs_update) 728 { 729 ui_t *ui = NULL; 730 ui_window_t *window = NULL; 731 ui_wnd_params_t params; 732 gfx_coord2_t pos; 733 gfx_rect_t rect; 734 ui_scrollbar_t *scrollbar; 735 errno_t rc; 736 737 rc = ui_create_disp(NULL, &ui); 738 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 739 740 ui_wnd_params_init(¶ms); 741 params.caption = "Hello"; 742 743 rc = ui_window_create(ui, ¶ms, &window); 744 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 745 PCUT_ASSERT_NOT_NULL(window); 746 747 rc = ui_scrollbar_create(ui, window, &scrollbar); 748 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 749 750 rect.p0.x = 10; 751 rect.p0.y = 20; 752 rect.p1.x = 110; 753 rect.p1.y = 120; 754 ui_scrollbar_set_rect(scrollbar, &rect); 755 756 PCUT_ASSERT_FALSE(scrollbar->down_through_inside); 757 758 pos.x = 60; 759 pos.y = 22; 760 761 ui_scrollbar_throughs_update(scrollbar, &pos); 762 PCUT_ASSERT_TRUE(scrollbar->down_through_inside); 763 764 ui_scrollbar_destroy(scrollbar); 765 ui_window_destroy(window); 766 ui_destroy(ui); 719 767 } 720 768 … … 722 770 PCUT_TEST(up) 723 771 { 724 ui_scrollbar_t *scrollbar; 725 errno_t rc; 726 gfx_context_t *gc = NULL; 727 test_gc_t tgc; 728 ui_resource_t *resource = NULL; 772 ui_t *ui = NULL; 773 ui_window_t *window = NULL; 774 ui_wnd_params_t params; 775 ui_scrollbar_t *scrollbar; 729 776 test_cb_resp_t resp; 730 731 memset(&tgc, 0, sizeof(tgc)); 732 rc = gfx_context_new(&ops, &tgc, &gc); 733 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 734 735 rc = ui_resource_create(gc, false, &resource); 736 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 737 PCUT_ASSERT_NOT_NULL(resource); 738 739 rc = ui_scrollbar_create(resource, &scrollbar); 777 errno_t rc; 778 779 rc = ui_create_disp(NULL, &ui); 780 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 781 782 ui_wnd_params_init(¶ms); 783 params.caption = "Hello"; 784 785 rc = ui_window_create(ui, ¶ms, &window); 786 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 787 PCUT_ASSERT_NOT_NULL(window); 788 789 rc = ui_scrollbar_create(ui, window, &scrollbar); 740 790 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 741 791 … … 754 804 755 805 ui_scrollbar_destroy(scrollbar); 756 ui_resource_destroy(resource); 757 758 rc = gfx_context_delete(gc); 759 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 806 ui_window_destroy(window); 807 ui_destroy(ui); 760 808 } 761 809 … … 763 811 PCUT_TEST(down) 764 812 { 765 ui_scrollbar_t *scrollbar; 766 errno_t rc; 767 gfx_context_t *gc = NULL; 768 test_gc_t tgc; 769 ui_resource_t *resource = NULL; 813 ui_t *ui = NULL; 814 ui_window_t *window = NULL; 815 ui_wnd_params_t params; 816 ui_scrollbar_t *scrollbar; 770 817 test_cb_resp_t resp; 771 772 memset(&tgc, 0, sizeof(tgc)); 773 rc = gfx_context_new(&ops, &tgc, &gc); 774 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 775 776 rc = ui_resource_create(gc, false, &resource); 777 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 778 PCUT_ASSERT_NOT_NULL(resource); 779 780 rc = ui_scrollbar_create(resource, &scrollbar); 818 errno_t rc; 819 820 rc = ui_create_disp(NULL, &ui); 821 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 822 823 ui_wnd_params_init(¶ms); 824 params.caption = "Hello"; 825 826 rc = ui_window_create(ui, ¶ms, &window); 827 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 828 PCUT_ASSERT_NOT_NULL(window); 829 830 rc = ui_scrollbar_create(ui, window, &scrollbar); 781 831 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 782 832 … … 795 845 796 846 ui_scrollbar_destroy(scrollbar); 797 ui_resource_destroy(resource); 798 799 rc = gfx_context_delete(gc); 800 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 847 ui_window_destroy(window); 848 ui_destroy(ui); 801 849 } 802 850 … … 804 852 PCUT_TEST(page_up) 805 853 { 806 ui_scrollbar_t *scrollbar; 807 errno_t rc; 808 gfx_context_t *gc = NULL; 809 test_gc_t tgc; 810 ui_resource_t *resource = NULL; 854 ui_t *ui = NULL; 855 ui_window_t *window = NULL; 856 ui_wnd_params_t params; 857 ui_scrollbar_t *scrollbar; 811 858 test_cb_resp_t resp; 812 813 memset(&tgc, 0, sizeof(tgc)); 814 rc = gfx_context_new(&ops, &tgc, &gc); 815 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 816 817 rc = ui_resource_create(gc, false, &resource); 818 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 819 PCUT_ASSERT_NOT_NULL(resource); 820 821 rc = ui_scrollbar_create(resource, &scrollbar); 859 errno_t rc; 860 861 rc = ui_create_disp(NULL, &ui); 862 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 863 864 ui_wnd_params_init(¶ms); 865 params.caption = "Hello"; 866 867 rc = ui_window_create(ui, ¶ms, &window); 868 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 869 PCUT_ASSERT_NOT_NULL(window); 870 871 rc = ui_scrollbar_create(ui, window, &scrollbar); 822 872 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 823 873 … … 836 886 837 887 ui_scrollbar_destroy(scrollbar); 838 ui_resource_destroy(resource); 839 840 rc = gfx_context_delete(gc); 841 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 888 ui_window_destroy(window); 889 ui_destroy(ui); 842 890 } 843 891 … … 845 893 PCUT_TEST(page_down) 846 894 { 847 ui_scrollbar_t *scrollbar; 848 errno_t rc; 849 gfx_context_t *gc = NULL; 850 test_gc_t tgc; 851 ui_resource_t *resource = NULL; 895 ui_t *ui = NULL; 896 ui_window_t *window = NULL; 897 ui_wnd_params_t params; 898 ui_scrollbar_t *scrollbar; 852 899 test_cb_resp_t resp; 853 854 memset(&tgc, 0, sizeof(tgc)); 855 rc = gfx_context_new(&ops, &tgc, &gc); 856 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 857 858 rc = ui_resource_create(gc, false, &resource); 859 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 860 PCUT_ASSERT_NOT_NULL(resource); 861 862 rc = ui_scrollbar_create(resource, &scrollbar); 900 errno_t rc; 901 902 rc = ui_create_disp(NULL, &ui); 903 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 904 905 ui_wnd_params_init(¶ms); 906 params.caption = "Hello"; 907 908 rc = ui_window_create(ui, ¶ms, &window); 909 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 910 PCUT_ASSERT_NOT_NULL(window); 911 912 rc = ui_scrollbar_create(ui, window, &scrollbar); 863 913 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 864 914 … … 877 927 878 928 ui_scrollbar_destroy(scrollbar); 879 ui_resource_destroy(resource); 880 881 rc = gfx_context_delete(gc); 882 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 929 ui_window_destroy(window); 930 ui_destroy(ui); 883 931 } 884 932 … … 886 934 PCUT_TEST(moved) 887 935 { 888 ui_scrollbar_t *scrollbar; 889 errno_t rc; 890 gfx_context_t *gc = NULL; 891 test_gc_t tgc; 892 ui_resource_t *resource = NULL; 936 ui_t *ui = NULL; 937 ui_window_t *window = NULL; 938 ui_wnd_params_t params; 939 ui_scrollbar_t *scrollbar; 893 940 test_cb_resp_t resp; 894 895 memset(&tgc, 0, sizeof(tgc)); 896 rc = gfx_context_new(&ops, &tgc, &gc); 897 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 898 899 rc = ui_resource_create(gc, false, &resource); 900 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 901 PCUT_ASSERT_NOT_NULL(resource); 902 903 rc = ui_scrollbar_create(resource, &scrollbar); 941 errno_t rc; 942 943 rc = ui_create_disp(NULL, &ui); 944 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 945 946 ui_wnd_params_init(¶ms); 947 params.caption = "Hello"; 948 949 rc = ui_window_create(ui, ¶ms, &window); 950 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 951 PCUT_ASSERT_NOT_NULL(window); 952 953 rc = ui_scrollbar_create(ui, window, &scrollbar); 904 954 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 905 955 … … 920 970 921 971 ui_scrollbar_destroy(scrollbar); 922 ui_resource_destroy(resource); 923 924 rc = gfx_context_delete(gc); 925 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 972 ui_window_destroy(window); 973 ui_destroy(ui); 926 974 } 927 975 … … 929 977 PCUT_TEST(pos_event_press_release_thumb) 930 978 { 931 errno_t rc; 932 gfx_context_t *gc = NULL; 933 test_gc_t tgc; 934 ui_resource_t *resource = NULL; 979 ui_t *ui = NULL; 980 ui_window_t *window = NULL; 981 ui_wnd_params_t params; 935 982 ui_scrollbar_t *scrollbar; 936 983 ui_evclaim_t claim; 937 984 pos_event_t event; 938 985 gfx_rect_t rect; 939 940 memset(&tgc, 0, sizeof(tgc)); 941 rc = gfx_context_new(&ops, &tgc, &gc); 942 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 943 944 rc = ui_resource_create(gc, false, &resource); 945 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 946 PCUT_ASSERT_NOT_NULL(resource); 947 948 rc = ui_scrollbar_create(resource, &scrollbar); 986 errno_t rc; 987 988 rc = ui_create_disp(NULL, &ui); 989 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 990 991 ui_wnd_params_init(¶ms); 992 params.caption = "Hello"; 993 994 rc = ui_window_create(ui, ¶ms, &window); 995 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 996 PCUT_ASSERT_NOT_NULL(window); 997 998 rc = ui_scrollbar_create(ui, window, &scrollbar); 949 999 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 950 1000 … … 982 1032 983 1033 ui_scrollbar_destroy(scrollbar); 984 ui_resource_destroy(resource); 985 986 rc = gfx_context_delete(gc); 987 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1034 ui_window_destroy(window); 1035 ui_destroy(ui); 988 1036 } 989 1037 … … 991 1039 PCUT_TEST(pos_event_press_release_up_btn) 992 1040 { 993 errno_t rc; 994 gfx_context_t *gc = NULL; 995 test_gc_t tgc; 996 ui_resource_t *resource = NULL; 1041 ui_t *ui = NULL; 1042 ui_window_t *window = NULL; 1043 ui_wnd_params_t params; 997 1044 ui_scrollbar_t *scrollbar; 998 1045 ui_evclaim_t claim; 999 1046 pos_event_t event; 1000 1047 gfx_rect_t rect; 1001 1002 memset(&tgc, 0, sizeof(tgc)); 1003 rc = gfx_context_new(&ops, &tgc, &gc); 1004 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1005 1006 rc = ui_resource_create(gc, false, &resource); 1007 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1008 PCUT_ASSERT_NOT_NULL(resource); 1009 1010 rc = ui_scrollbar_create(resource, &scrollbar); 1048 errno_t rc; 1049 1050 rc = ui_create_disp(NULL, &ui); 1051 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1052 1053 ui_wnd_params_init(¶ms); 1054 params.caption = "Hello"; 1055 1056 rc = ui_window_create(ui, ¶ms, &window); 1057 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1058 PCUT_ASSERT_NOT_NULL(window); 1059 1060 rc = ui_scrollbar_create(ui, window, &scrollbar); 1011 1061 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1012 1062 … … 1028 1078 1029 1079 ui_scrollbar_destroy(scrollbar); 1030 ui_resource_destroy(resource); 1031 1032 rc = gfx_context_delete(gc); 1033 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1080 ui_window_destroy(window); 1081 ui_destroy(ui); 1034 1082 } 1035 1083 … … 1037 1085 PCUT_TEST(pos_event_press_release_up_through) 1038 1086 { 1039 errno_t rc; 1040 gfx_context_t *gc = NULL; 1041 test_gc_t tgc; 1042 ui_resource_t *resource = NULL; 1087 ui_t *ui = NULL; 1088 ui_window_t *window = NULL; 1089 ui_wnd_params_t params; 1043 1090 ui_scrollbar_t *scrollbar; 1044 1091 ui_evclaim_t claim; 1045 1092 pos_event_t event; 1046 1093 gfx_rect_t rect; 1047 1048 memset(&tgc, 0, sizeof(tgc)); 1049 rc = gfx_context_new(&ops, &tgc, &gc); 1050 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1051 1052 rc = ui_resource_create(gc, false, &resource); 1053 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1054 PCUT_ASSERT_NOT_NULL(resource); 1055 1056 rc = ui_scrollbar_create(resource, &scrollbar); 1094 errno_t rc; 1095 1096 rc = ui_create_disp(NULL, &ui); 1097 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1098 1099 ui_wnd_params_init(¶ms); 1100 params.caption = "Hello"; 1101 1102 rc = ui_window_create(ui, ¶ms, &window); 1103 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1104 PCUT_ASSERT_NOT_NULL(window); 1105 1106 rc = ui_scrollbar_create(ui, window, &scrollbar); 1057 1107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1058 1108 … … 1085 1135 1086 1136 ui_scrollbar_destroy(scrollbar); 1087 ui_resource_destroy(resource); 1088 1089 rc = gfx_context_delete(gc); 1090 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1137 ui_window_destroy(window); 1138 ui_destroy(ui); 1091 1139 } 1092 1140 … … 1094 1142 PCUT_TEST(pos_event_press_release_down_through) 1095 1143 { 1096 errno_t rc; 1097 gfx_context_t *gc = NULL; 1098 test_gc_t tgc; 1099 ui_resource_t *resource = NULL; 1144 ui_t *ui = NULL; 1145 ui_window_t *window = NULL; 1146 ui_wnd_params_t params; 1100 1147 ui_scrollbar_t *scrollbar; 1101 1148 ui_evclaim_t claim; 1102 1149 pos_event_t event; 1103 1150 gfx_rect_t rect; 1104 1105 memset(&tgc, 0, sizeof(tgc)); 1106 rc = gfx_context_new(&ops, &tgc, &gc); 1107 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1108 1109 rc = ui_resource_create(gc, false, &resource); 1110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1111 PCUT_ASSERT_NOT_NULL(resource); 1112 1113 rc = ui_scrollbar_create(resource, &scrollbar); 1151 errno_t rc; 1152 1153 rc = ui_create_disp(NULL, &ui); 1154 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1155 1156 ui_wnd_params_init(¶ms); 1157 params.caption = "Hello"; 1158 1159 rc = ui_window_create(ui, ¶ms, &window); 1160 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1161 PCUT_ASSERT_NOT_NULL(window); 1162 1163 rc = ui_scrollbar_create(ui, window, &scrollbar); 1114 1164 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1115 1165 … … 1139 1189 1140 1190 ui_scrollbar_destroy(scrollbar); 1141 ui_resource_destroy(resource); 1142 1143 rc = gfx_context_delete(gc); 1144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1191 ui_window_destroy(window); 1192 ui_destroy(ui); 1145 1193 } 1146 1194 … … 1148 1196 PCUT_TEST(pos_event_press_relese_down_btn) 1149 1197 { 1150 errno_t rc; 1151 gfx_context_t *gc = NULL; 1152 test_gc_t tgc; 1153 ui_resource_t *resource = NULL; 1198 ui_t *ui = NULL; 1199 ui_window_t *window = NULL; 1200 ui_wnd_params_t params; 1154 1201 ui_scrollbar_t *scrollbar; 1155 1202 ui_evclaim_t claim; 1156 1203 pos_event_t event; 1157 1204 gfx_rect_t rect; 1158 1159 memset(&tgc, 0, sizeof(tgc)); 1160 rc = gfx_context_new(&ops, &tgc, &gc); 1161 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1162 1163 rc = ui_resource_create(gc, false, &resource); 1164 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1165 PCUT_ASSERT_NOT_NULL(resource); 1166 1167 rc = ui_scrollbar_create(resource, &scrollbar); 1205 errno_t rc; 1206 1207 rc = ui_create_disp(NULL, &ui); 1208 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1209 1210 ui_wnd_params_init(¶ms); 1211 params.caption = "Hello"; 1212 1213 rc = ui_window_create(ui, ¶ms, &window); 1214 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1215 PCUT_ASSERT_NOT_NULL(window); 1216 1217 rc = ui_scrollbar_create(ui, window, &scrollbar); 1168 1218 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1169 1219 … … 1185 1235 1186 1236 ui_scrollbar_destroy(scrollbar); 1187 ui_resource_destroy(resource); 1188 1189 rc = gfx_context_delete(gc); 1190 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1191 } 1192 1193 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 1194 { 1195 (void) arg; 1196 (void) rect; 1197 return EOK; 1198 } 1199 1200 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 1201 { 1202 (void) arg; 1203 (void) color; 1204 return EOK; 1205 } 1206 1207 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 1208 { 1209 (void) arg; 1210 (void) rect; 1211 return EOK; 1212 } 1213 1214 static errno_t testgc_update(void *arg) 1215 { 1216 (void) arg; 1217 return EOK; 1218 } 1219 1220 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 1221 gfx_bitmap_alloc_t *alloc, void **rbm) 1222 { 1223 test_gc_t *tgc = (test_gc_t *) arg; 1224 testgc_bitmap_t *tbm; 1225 1226 tbm = calloc(1, sizeof(testgc_bitmap_t)); 1227 if (tbm == NULL) 1228 return ENOMEM; 1229 1230 if (alloc == NULL) { 1231 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 1232 sizeof(uint32_t); 1233 tbm->alloc.off0 = 0; 1234 tbm->alloc.pixels = calloc(sizeof(uint32_t), 1235 (params->rect.p1.x - params->rect.p0.x) * 1236 (params->rect.p1.y - params->rect.p0.y)); 1237 tbm->myalloc = true; 1238 if (tbm->alloc.pixels == NULL) { 1239 free(tbm); 1240 return ENOMEM; 1241 } 1242 } else { 1243 tbm->alloc = *alloc; 1244 } 1245 1246 tbm->tgc = tgc; 1247 tgc->bm_created = true; 1248 tgc->bm_params = *params; 1249 tgc->bm_pixels = tbm->alloc.pixels; 1250 *rbm = (void *)tbm; 1251 return EOK; 1252 } 1253 1254 static errno_t testgc_bitmap_destroy(void *bm) 1255 { 1256 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 1257 if (tbm->myalloc) 1258 free(tbm->alloc.pixels); 1259 tbm->tgc->bm_destroyed = true; 1260 free(tbm); 1261 return EOK; 1262 } 1263 1264 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 1265 gfx_coord2_t *offs) 1266 { 1267 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 1268 1269 tbm->tgc->bm_rendered = true; 1270 if (srect != NULL) 1271 tbm->tgc->bm_srect = *srect; 1272 if (offs != NULL) 1273 tbm->tgc->bm_offs = *offs; 1274 return EOK; 1275 } 1276 1277 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 1278 { 1279 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 1280 *alloc = tbm->alloc; 1281 tbm->tgc->bm_got_alloc = true; 1282 return EOK; 1237 ui_window_destroy(window); 1238 ui_destroy(ui); 1283 1239 } 1284 1240 -
uspace/lib/ui/test/ui.c
rd4ea1f6 r8965860c 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 169 169 } 170 170 171 /** ui_lock(), ui_unlock() */ 172 PCUT_TEST(lock_unlock) 173 { 174 ui_t *ui = NULL; 175 errno_t rc; 176 177 rc = ui_create_disp((display_t *)(-1), &ui); 178 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 PCUT_ASSERT_NOT_NULL(ui); 180 181 ui_lock(ui); 182 ui_unlock(ui); 183 184 ui_destroy(ui); 185 } 186 171 187 PCUT_EXPORT(ui);
Note:
See TracChangeset
for help on using the changeset viewer.