Changeset 7ca7215 in mainline for uspace/lib/ui/src/scrollbar.c
- Timestamp:
- 2022-03-25T21:41:21Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0d1d0ea
- Parents:
- 8965860c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/scrollbar.c
r8965860c r7ca7215 149 149 * @param ui UI 150 150 * @param window Window containing scrollbar 151 * @param dir Scrollbar direction 151 152 * @param rscrollbar Place to store pointer to new scrollbar 152 153 * @return EOK on success, ENOMEM if out of memory 153 154 */ 154 155 errno_t ui_scrollbar_create(ui_t *ui, ui_window_t *window, 155 ui_scrollbar_ t **rscrollbar)156 ui_scrollbar_dir_t dir, ui_scrollbar_t **rscrollbar) 156 157 { 157 158 ui_scrollbar_t *scrollbar; 158 159 ui_resource_t *resource; 160 const char *up_text; 161 const char *down_text; 159 162 errno_t rc; 160 163 … … 172 175 } 173 176 174 rc = ui_pbutton_create(resource, resource->textmode ? "\u25c4" : "<", 175 &scrollbar->up_btn); 177 if (dir == ui_sbd_horiz) { 178 up_text = resource->textmode ? "\u25c4" : "<"; 179 down_text = resource->textmode ? "\u25ba" : ">"; 180 } else { 181 up_text = resource->textmode ? "\u25b2" : "^"; 182 down_text = resource->textmode ? "\u25bc" : "v"; 183 } 184 185 rc = ui_pbutton_create(resource, up_text, &scrollbar->up_btn); 176 186 if (rc != EOK) 177 187 goto error; … … 180 190 (void *) scrollbar); 181 191 182 rc = ui_pbutton_create(resource, resource->textmode ? "\u25ba" : ">", 183 &scrollbar->down_btn); 192 rc = ui_pbutton_create(resource, down_text, &scrollbar->down_btn); 184 193 if (rc != EOK) 185 194 goto error; … … 194 203 scrollbar->ui = ui; 195 204 scrollbar->window = window; 205 scrollbar->dir = dir; 196 206 *rscrollbar = scrollbar; 197 207 return EOK; … … 340 350 ui_resource_t *resource; 341 351 gfx_coord2_t dims; 342 gfx_coord_t w; 352 gfx_coord_t len; 353 gfx_coord_t sblen; 343 354 344 355 resource = ui_window_get_res(scrollbar->window); 345 356 346 357 gfx_rect_dims(&scrollbar->rect, &dims); 347 w = resource->textmode ? ui_scrollbar_btn_len_text : 358 sblen = scrollbar->dir == ui_sbd_horiz ? 359 dims.x : dims.y; 360 361 len = resource->textmode ? ui_scrollbar_btn_len_text : 348 362 ui_scrollbar_btn_len; 349 return dims.x - 2 * w; 363 364 return sblen - 2 * len; 350 365 } 351 366 … … 477 492 478 493 /* Paint scrollbar thumb */ 479 480 494 rc = ui_scrollbar_paint_thumb_frame(resource, &geom.thumb_rect, 481 495 ui_scrollbar_thumb_frame_thickness, &brect); … … 512 526 } 513 527 514 /** Paint scrollbar in text mode.528 /** Paint horizontal scrollbar in text mode. 515 529 * 516 530 * @param scrollbar Scrollbar 517 531 * @return EOK on success or an error code 518 532 */ 519 errno_t ui_scrollbar_paint_text (ui_scrollbar_t *scrollbar)533 errno_t ui_scrollbar_paint_text_horiz(ui_scrollbar_t *scrollbar) 520 534 { 521 535 ui_resource_t *resource; … … 601 615 } 602 616 617 /** Paint vertical scrollbar in text mode. 618 * 619 * @param scrollbar Scrollbar 620 * @return EOK on success or an error code 621 */ 622 errno_t ui_scrollbar_paint_text_vert(ui_scrollbar_t *scrollbar) 623 { 624 ui_resource_t *resource; 625 ui_scrollbar_geom_t geom; 626 gfx_coord2_t pos; 627 gfx_text_fmt_t fmt; 628 errno_t rc; 629 630 resource = ui_window_get_res(scrollbar->window); 631 ui_scrollbar_get_geom(scrollbar, &geom); 632 633 /* Paint scrollbar through */ 634 635 gfx_text_fmt_init(&fmt); 636 fmt.font = resource->font; 637 fmt.color = resource->sbar_through_color; 638 fmt.halign = gfx_halign_left; 639 fmt.valign = gfx_valign_top; 640 641 pos.x = scrollbar->rect.p0.x; 642 for (pos.y = geom.through_rect.p0.y; pos.y < geom.through_rect.p1.y; 643 pos.y++) { 644 rc = gfx_puttext(&pos, &fmt, "\u2592"); 645 if (rc != EOK) 646 goto error; 647 } 648 649 /* Paint scrollbar thumb */ 650 651 pos.x = geom.thumb_rect.p0.x; 652 for (pos.y = geom.thumb_rect.p0.y; pos.y < geom.thumb_rect.p1.y; 653 pos.y++) { 654 rc = gfx_puttext(&pos, &fmt, "\u25a0"); 655 if (rc != EOK) 656 goto error; 657 } 658 659 rc = ui_pbutton_paint(scrollbar->up_btn); 660 if (rc != EOK) 661 goto error; 662 663 rc = ui_pbutton_paint(scrollbar->down_btn); 664 if (rc != EOK) 665 goto error; 666 667 rc = gfx_update(resource->gc); 668 if (rc != EOK) 669 goto error; 670 671 return EOK; 672 error: 673 return rc; 674 } 675 603 676 /** Paint scrollbar. 604 677 * … … 610 683 ui_resource_t *resource = ui_window_get_res(scrollbar->window); 611 684 612 if (resource->textmode) 613 return ui_scrollbar_paint_text(scrollbar); 614 else 685 if (resource->textmode) { 686 if (scrollbar->dir == ui_sbd_horiz) 687 return ui_scrollbar_paint_text_horiz(scrollbar); 688 else 689 return ui_scrollbar_paint_text_vert(scrollbar); 690 } else { 615 691 return ui_scrollbar_paint_gfx(scrollbar); 692 } 616 693 } 617 694 … … 646 723 } 647 724 648 /* Up button */ 649 geom->up_btn_rect.p0.x = orect.p0.x; 650 geom->up_btn_rect.p0.y = orect.p0.y; 651 geom->up_btn_rect.p1.x = orect.p0.x + btn_len; 652 geom->up_btn_rect.p1.y = orect.p1.y; 653 654 /* Through */ 655 geom->through_rect.p0.x = geom->up_btn_rect.p1.x; 656 geom->through_rect.p0.y = irect.p0.y; 657 geom->through_rect.p1.x = orect.p1.x - btn_len; 658 geom->through_rect.p1.y = irect.p1.y; 659 660 /* Thumb */ 661 geom->thumb_rect.p0.x = geom->up_btn_rect.p1.x + scrollbar->pos; 662 geom->thumb_rect.p0.y = orect.p0.y; 663 geom->thumb_rect.p1.x = geom->thumb_rect.p0.x + scrollbar->thumb_len; 664 geom->thumb_rect.p1.y = orect.p1.y; 665 666 /* Up through */ 667 geom->up_through_rect.p0 = geom->through_rect.p0; 668 geom->up_through_rect.p1.x = geom->thumb_rect.p0.x; 669 geom->up_through_rect.p1.y = geom->through_rect.p1.y; 670 671 /* Down through */ 672 geom->down_through_rect.p0.x = geom->thumb_rect.p1.x; 673 geom->down_through_rect.p0.y = geom->through_rect.p0.y; 674 geom->down_through_rect.p1 = geom->through_rect.p1; 675 676 /* Down button */ 677 geom->down_btn_rect.p0.x = geom->through_rect.p1.x; 678 geom->down_btn_rect.p0.y = orect.p0.y; 679 geom->down_btn_rect.p1.x = orect.p1.x; 680 geom->down_btn_rect.p1.y = orect.p1.y; 725 if (scrollbar->dir == ui_sbd_horiz) { 726 /* Up button */ 727 geom->up_btn_rect.p0.x = orect.p0.x; 728 geom->up_btn_rect.p0.y = orect.p0.y; 729 geom->up_btn_rect.p1.x = orect.p0.x + btn_len; 730 geom->up_btn_rect.p1.y = orect.p1.y; 731 732 /* Through */ 733 geom->through_rect.p0.x = geom->up_btn_rect.p1.x; 734 geom->through_rect.p0.y = irect.p0.y; 735 geom->through_rect.p1.x = orect.p1.x - btn_len; 736 geom->through_rect.p1.y = irect.p1.y; 737 738 /* Thumb */ 739 geom->thumb_rect.p0.x = geom->up_btn_rect.p1.x + 740 scrollbar->pos; 741 geom->thumb_rect.p0.y = orect.p0.y; 742 geom->thumb_rect.p1.x = geom->thumb_rect.p0.x + 743 scrollbar->thumb_len; 744 geom->thumb_rect.p1.y = orect.p1.y; 745 746 /* Up through */ 747 geom->up_through_rect.p0 = geom->through_rect.p0; 748 geom->up_through_rect.p1.x = geom->thumb_rect.p0.x; 749 geom->up_through_rect.p1.y = geom->through_rect.p1.y; 750 751 /* Down through */ 752 geom->down_through_rect.p0.x = geom->thumb_rect.p1.x; 753 geom->down_through_rect.p0.y = geom->through_rect.p0.y; 754 geom->down_through_rect.p1 = geom->through_rect.p1; 755 756 /* Down button */ 757 geom->down_btn_rect.p0.x = geom->through_rect.p1.x; 758 geom->down_btn_rect.p0.y = orect.p0.y; 759 geom->down_btn_rect.p1.x = orect.p1.x; 760 geom->down_btn_rect.p1.y = orect.p1.y; 761 } else { 762 /* Up button */ 763 geom->up_btn_rect.p0.x = orect.p0.x; 764 geom->up_btn_rect.p0.y = orect.p0.y; 765 geom->up_btn_rect.p1.x = orect.p1.x; 766 geom->up_btn_rect.p1.y = orect.p0.y + btn_len; 767 768 /* Through */ 769 geom->through_rect.p0.x = irect.p0.x; 770 geom->through_rect.p0.y = geom->up_btn_rect.p1.y; 771 geom->through_rect.p1.x = irect.p1.x; 772 geom->through_rect.p1.y = orect.p1.y - btn_len; 773 774 /* Thumb */ 775 geom->thumb_rect.p0.x = orect.p0.x; 776 geom->thumb_rect.p0.y = geom->up_btn_rect.p1.y + 777 scrollbar->pos; 778 geom->thumb_rect.p1.x = orect.p1.x; 779 geom->thumb_rect.p1.y = geom->thumb_rect.p0.y + 780 scrollbar->thumb_len; 781 782 /* Up through */ 783 geom->up_through_rect.p0 = geom->through_rect.p0; 784 geom->up_through_rect.p1.x = geom->through_rect.p1.x; 785 geom->up_through_rect.p1.y = geom->thumb_rect.p0.y; 786 787 /* Down through */ 788 geom->down_through_rect.p0.x = geom->through_rect.p0.x; 789 geom->down_through_rect.p0.y = geom->thumb_rect.p1.y; 790 geom->down_through_rect.p1 = geom->through_rect.p1; 791 792 /* Down button */ 793 geom->down_btn_rect.p0.x = orect.p0.x; 794 geom->down_btn_rect.p0.y = geom->through_rect.p1.y; 795 geom->down_btn_rect.p1.x = orect.p1.x; 796 geom->down_btn_rect.p1.y = orect.p1.y; 797 } 681 798 } 682 799 … … 790 907 } 791 908 792 /** Pointer moved.909 /** Scrollbar handler for pointer movement. 793 910 * 794 911 * @param scrollbar Scrollbar … … 800 917 801 918 if (scrollbar->thumb_held) { 802 spos = scrollbar->last_pos + pos->x - scrollbar->press_pos.x; 919 if (scrollbar->dir == ui_sbd_horiz) 920 spos = scrollbar->last_pos + pos->x - scrollbar->press_pos.x; 921 else 922 spos = scrollbar->last_pos + pos->y - scrollbar->press_pos.y; 923 803 924 ui_scrollbar_set_pos(scrollbar, spos); 804 925 }
Note:
See TracChangeset
for help on using the changeset viewer.