Changeset 1026cc4 in mainline for uspace/lib/ui/src/scrollbar.c
- Timestamp:
- 2022-03-20T19:51:09Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 26c90dd
- Parents:
- 5ef85c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/scrollbar.c
r5ef85c0 r1026cc4 32 32 /** 33 33 * @file Scrollbar 34 * 35 * Anatomy of a horizontal scrollbar: 36 * 37 * Up Down 38 * through through 39 * +---+------+--------+---------+---+ 40 * | < | | ||| | | > | 41 * +---+------+--------+---------+---+ 42 * Up Thumb Down 43 * button button 44 * 45 * +-------- Through --------+ 46 * 47 * Scrollbar uses the same terminology whether it is running in horizontal 48 * or vertical mode, in horizontal mode up means left, down means right 49 * (i.e. lower and higher coordinates, respectively). 50 * 51 * The thumb can be dragged to a specific position, resulting in a move 52 * event. The up/down buttons generate up/down events. Pressing a mouse 53 * button on the up/down through generates page up / page down events. 54 * 55 * TODO: Up/down buttons/throughs should be equipped with an autorepeat 56 * mechanism: after an initial delay, start repeating at a preset rate. 34 57 */ 35 58 … … 391 414 goto error; 392 415 393 /* Paint scrollbar through */ 394 416 /* Paint scrollbar up through */ 395 417 rc = gfx_set_color(scrollbar->res->gc, 418 scrollbar->up_through_held ? 419 scrollbar->res->sbar_act_through_color : 396 420 scrollbar->res->sbar_through_color); 397 421 if (rc != EOK) 398 422 goto error; 399 423 400 rc = gfx_fill_rect(scrollbar->res->gc, &geom.through_rect); 424 rc = gfx_fill_rect(scrollbar->res->gc, &geom.up_through_rect); 425 if (rc != EOK) 426 goto error; 427 428 /* Paint scrollbar down through */ 429 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); 401 438 if (rc != EOK) 402 439 goto error; … … 582 619 geom->thumb_rect.p1.y = orect.p1.y; 583 620 621 /* Up through */ 622 geom->up_through_rect.p0 = geom->through_rect.p0; 623 geom->up_through_rect.p1.x = geom->thumb_rect.p0.x; 624 geom->up_through_rect.p1.y = geom->through_rect.p1.y; 625 626 /* Down through */ 627 geom->down_through_rect.p0.x = geom->thumb_rect.p1.x; 628 geom->down_through_rect.p0.y = geom->through_rect.p0.y; 629 geom->down_through_rect.p1 = geom->through_rect.p1; 630 584 631 /* Down button */ 585 632 geom->down_btn_rect.p0.x = geom->through_rect.p1.x; … … 618 665 } 619 666 620 /** Press down scrollbar .667 /** Press down scrollbar thumb. 621 668 * 622 669 * @param scrollbar Scrollbar 623 670 * @param pos Pointer position 624 671 */ 625 void ui_scrollbar_ press(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)626 { 627 if (scrollbar-> held)672 void ui_scrollbar_thumb_press(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos) 673 { 674 if (scrollbar->thumb_held) 628 675 return; 629 676 630 scrollbar-> held = true;677 scrollbar->thumb_held = true; 631 678 scrollbar->press_pos = *pos; 632 679 scrollbar->last_pos = scrollbar->pos; … … 635 682 } 636 683 684 /** Press down scrollbar up through. 685 * 686 * @param scrollbar Scrollbar 687 */ 688 void ui_scrollbar_up_through_press(ui_scrollbar_t *scrollbar) 689 { 690 if (scrollbar->up_through_held) 691 return; 692 693 scrollbar->up_through_held = true; 694 (void) ui_scrollbar_paint(scrollbar); 695 696 ui_scrollbar_page_up(scrollbar); 697 } 698 699 /** Press down scrollbar down through. 700 * 701 * @param scrollbar Scrollbar 702 */ 703 void ui_scrollbar_down_through_press(ui_scrollbar_t *scrollbar) 704 { 705 if (scrollbar->down_through_held) 706 return; 707 708 scrollbar->down_through_held = true; 709 (void) ui_scrollbar_paint(scrollbar); 710 711 ui_scrollbar_page_down(scrollbar); 712 } 713 637 714 /** Release scrollbar. 638 715 * … … 642 719 void ui_scrollbar_release(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos) 643 720 { 644 if (!scrollbar->held) 645 return; 646 647 ui_scrollbar_update(scrollbar, pos); 648 scrollbar->held = false; 721 if (scrollbar->thumb_held) { 722 ui_scrollbar_update(scrollbar, pos); 723 scrollbar->thumb_held = false; 724 } 725 726 if (scrollbar->up_through_held || scrollbar->down_through_held) { 727 scrollbar->up_through_held = false; 728 scrollbar->down_through_held = false; 729 (void) ui_scrollbar_paint(scrollbar); 730 } 649 731 } 650 732 … … 658 740 gfx_coord_t spos; 659 741 660 if (scrollbar-> held) {742 if (scrollbar->thumb_held) { 661 743 spos = scrollbar->last_pos + pos->x - scrollbar->press_pos.x; 662 744 ui_scrollbar_set_pos(scrollbar, spos); … … 680 762 void ui_scrollbar_down(ui_scrollbar_t *scrollbar) 681 763 { 682 if (scrollbar->cb != NULL && scrollbar->cb-> up!= NULL)764 if (scrollbar->cb != NULL && scrollbar->cb->down != NULL) 683 765 scrollbar->cb->down(scrollbar, scrollbar->arg); 766 } 767 768 /** Scrollbar up through was pressed. 769 * 770 * @param scrollbar Scrollbar 771 */ 772 void ui_scrollbar_page_up(ui_scrollbar_t *scrollbar) 773 { 774 if (scrollbar->cb != NULL && scrollbar->cb->page_up != NULL) 775 scrollbar->cb->page_up(scrollbar, scrollbar->arg); 776 } 777 778 /** Scrollbar down through was pressed. 779 * 780 * @param scrollbar Scrollbar 781 */ 782 void ui_scrollbar_page_down(ui_scrollbar_t *scrollbar) 783 { 784 if (scrollbar->cb != NULL && scrollbar->cb->page_down != NULL) 785 scrollbar->cb->page_down(scrollbar, scrollbar->arg); 684 786 } 685 787 … … 703 805 { 704 806 gfx_coord2_t pos; 705 gfx_rect_t rect;706 807 ui_evclaim_t claimed; 808 ui_scrollbar_geom_t geom; 809 810 ui_scrollbar_get_geom(scrollbar, &geom); 707 811 708 812 pos.x = event->hpos; … … 719 823 switch (event->type) { 720 824 case POS_PRESS: 721 ui_scrollbar_thumb_rect(scrollbar, &rect); 722 if (gfx_pix_inside_rect(&pos, &rect)) { 723 ui_scrollbar_press(scrollbar, &pos); 724 scrollbar->press_pos = pos; 825 if (gfx_pix_inside_rect(&pos, &geom.thumb_rect)) { 826 ui_scrollbar_thumb_press(scrollbar, &pos); 827 return ui_claimed; 828 } 829 if (gfx_pix_inside_rect(&pos, &geom.up_through_rect)) { 830 ui_scrollbar_up_through_press(scrollbar); 831 return ui_claimed; 832 } 833 if (gfx_pix_inside_rect(&pos, &geom.down_through_rect)) { 834 ui_scrollbar_down_through_press(scrollbar); 725 835 return ui_claimed; 726 836 } 727 837 break; 728 838 case POS_RELEASE: 729 if (scrollbar->held) { 839 if (scrollbar->thumb_held || scrollbar->up_through_held || 840 scrollbar->down_through_held) { 730 841 ui_scrollbar_release(scrollbar, &pos); 731 842 return ui_claimed;
Note:
See TracChangeset
for help on using the changeset viewer.