Changes in uspace/lib/ui/src/scrollbar.c [ef4d684:14b4577] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/scrollbar.c
ref4d684 r14b4577 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 * Anatomy of a horizontal scrollbar: 36 36 * 37 * Upper Lower38 * trough trough39 * 40 * 41 * 42 * 43 * button 44 * 45 * +-------- T rough --------+37 * Up Down 38 * through through 39 * +---+------+--------+---------+---+ 40 * | < | | ||| | | > | 41 * +---+------+--------+---------+---+ 42 * Up Thumb Down 43 * button button 44 * 45 * +-------- Through --------+ 46 46 * 47 47 * Scrollbar uses the same terminology whether it is running in horizontal … … 51 51 * The thumb can be dragged to a specific position, resulting in a move 52 52 * event. The up/down buttons generate up/down events. Pressing a mouse 53 * button on the up per/lower trough generates page up / page down events.54 * 55 * Pressing and holding down mouse button on up / down button or up per /56 * lower trough will auto-scroll (using clickmatic).53 * button on the up/down through generates page up / page down events. 54 * 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 … … 360 360 } 361 361 362 /** Determine scrollbar t rough length.362 /** Determine scrollbar through length. 363 363 * 364 364 * Return the size of the space within which the thumb can move … … 366 366 * 367 367 * @param scrollbar Scrollbar 368 * @return Scrollbar t rough length in pixels369 */ 370 gfx_coord_t ui_scrollbar_t rough_length(ui_scrollbar_t *scrollbar)368 * @return Scrollbar through length in pixels 369 */ 370 gfx_coord_t ui_scrollbar_through_length(ui_scrollbar_t *scrollbar) 371 371 { 372 372 ui_resource_t *resource; … … 396 396 gfx_coord_t ui_scrollbar_move_length(ui_scrollbar_t *scrollbar) 397 397 { 398 return ui_scrollbar_t rough_length(scrollbar) -398 return ui_scrollbar_through_length(scrollbar) - 399 399 scrollbar->thumb_len; 400 400 } … … 417 417 ui_scrollbar_min_thumb_len; 418 418 419 max_len = ui_scrollbar_t rough_length(scrollbar);419 max_len = ui_scrollbar_through_length(scrollbar); 420 420 if (len < min_len) 421 421 len = min_len; … … 459 459 scrollbar->pos = pos; 460 460 (void) ui_scrollbar_paint(scrollbar); 461 ui_scrollbar_t roughs_update(scrollbar,461 ui_scrollbar_throughs_update(scrollbar, 462 462 &scrollbar->last_curs_pos); 463 463 } … … 487 487 goto error; 488 488 489 /* Paint scrollbar up per trough */489 /* Paint scrollbar up through */ 490 490 rc = gfx_set_color(resource->gc, 491 scrollbar->up per_trough_held && scrollbar->upper_trough_inside ?492 resource->sbar_act_t rough_color :493 resource->sbar_t rough_color);494 if (rc != EOK) 495 goto error; 496 497 rc = gfx_fill_rect(resource->gc, &geom.up per_trough_rect);498 if (rc != EOK) 499 goto error; 500 501 /* Paint scrollbar lower trough */491 scrollbar->up_through_held && scrollbar->up_through_inside ? 492 resource->sbar_act_through_color : 493 resource->sbar_through_color); 494 if (rc != EOK) 495 goto error; 496 497 rc = gfx_fill_rect(resource->gc, &geom.up_through_rect); 498 if (rc != EOK) 499 goto error; 500 501 /* Paint scrollbar down through */ 502 502 503 503 rc = gfx_set_color(resource->gc, 504 scrollbar-> lower_trough_held && scrollbar->lower_trough_inside ?505 resource->sbar_act_t rough_color :506 resource->sbar_t rough_color);507 if (rc != EOK) 508 goto error; 509 510 rc = gfx_fill_rect(resource->gc, &geom. lower_trough_rect);504 scrollbar->down_through_held && scrollbar->down_through_inside ? 505 resource->sbar_act_through_color : 506 resource->sbar_through_color); 507 if (rc != EOK) 508 goto error; 509 510 rc = gfx_fill_rect(resource->gc, &geom.down_through_rect); 511 511 if (rc != EOK) 512 512 goto error; … … 561 561 ui_scrollbar_get_geom(scrollbar, &geom); 562 562 563 /* Paint scrollbar t rough */564 565 rc = ui_paint_text_rect(resource, &geom.t rough_rect,566 resource->sbar_t rough_color, "\u2592");563 /* Paint scrollbar through */ 564 565 rc = ui_paint_text_rect(resource, &geom.through_rect, 566 resource->sbar_through_color, "\u2592"); 567 567 if (rc != EOK) 568 568 goto error; … … 571 571 572 572 rc = ui_paint_text_rect(resource, &geom.thumb_rect, 573 resource->sbar_t rough_color, "\u25a0");573 resource->sbar_through_color, "\u25a0"); 574 574 if (rc != EOK) 575 575 goto error; … … 647 647 geom->up_btn_rect.p1.y = orect.p1.y; 648 648 649 /* T rough */650 geom->t rough_rect.p0.x = geom->up_btn_rect.p1.x;651 geom->t rough_rect.p0.y = irect.p0.y;652 geom->t rough_rect.p1.x = orect.p1.x - btn_len;653 geom->t rough_rect.p1.y = irect.p1.y;649 /* Through */ 650 geom->through_rect.p0.x = geom->up_btn_rect.p1.x; 651 geom->through_rect.p0.y = irect.p0.y; 652 geom->through_rect.p1.x = orect.p1.x - btn_len; 653 geom->through_rect.p1.y = irect.p1.y; 654 654 655 655 /* Thumb */ … … 661 661 geom->thumb_rect.p1.y = orect.p1.y; 662 662 663 /* Up per trough */664 geom->up per_trough_rect.p0 = geom->trough_rect.p0;665 geom->up per_trough_rect.p1.x = geom->thumb_rect.p0.x;666 geom->up per_trough_rect.p1.y = geom->trough_rect.p1.y;667 668 /* Lower trough */669 geom-> lower_trough_rect.p0.x = geom->thumb_rect.p1.x;670 geom-> lower_trough_rect.p0.y = geom->trough_rect.p0.y;671 geom-> lower_trough_rect.p1 = geom->trough_rect.p1;663 /* Up through */ 664 geom->up_through_rect.p0 = geom->through_rect.p0; 665 geom->up_through_rect.p1.x = geom->thumb_rect.p0.x; 666 geom->up_through_rect.p1.y = geom->through_rect.p1.y; 667 668 /* Down through */ 669 geom->down_through_rect.p0.x = geom->thumb_rect.p1.x; 670 geom->down_through_rect.p0.y = geom->through_rect.p0.y; 671 geom->down_through_rect.p1 = geom->through_rect.p1; 672 672 673 673 /* Down button */ 674 geom->down_btn_rect.p0.x = geom->t rough_rect.p1.x;674 geom->down_btn_rect.p0.x = geom->through_rect.p1.x; 675 675 geom->down_btn_rect.p0.y = orect.p0.y; 676 676 geom->down_btn_rect.p1.x = orect.p1.x; … … 683 683 geom->up_btn_rect.p1.y = orect.p0.y + btn_len; 684 684 685 /* T rough */686 geom->t rough_rect.p0.x = irect.p0.x;687 geom->t rough_rect.p0.y = geom->up_btn_rect.p1.y;688 geom->t rough_rect.p1.x = irect.p1.x;689 geom->t rough_rect.p1.y = orect.p1.y - btn_len;685 /* Through */ 686 geom->through_rect.p0.x = irect.p0.x; 687 geom->through_rect.p0.y = geom->up_btn_rect.p1.y; 688 geom->through_rect.p1.x = irect.p1.x; 689 geom->through_rect.p1.y = orect.p1.y - btn_len; 690 690 691 691 /* Thumb */ … … 697 697 scrollbar->thumb_len; 698 698 699 /* Up per trough */700 geom->up per_trough_rect.p0 = geom->trough_rect.p0;701 geom->up per_trough_rect.p1.x = geom->trough_rect.p1.x;702 geom->up per_trough_rect.p1.y = geom->thumb_rect.p0.y;703 704 /* Lower trough */705 geom-> lower_trough_rect.p0.x = geom->trough_rect.p0.x;706 geom-> lower_trough_rect.p0.y = geom->thumb_rect.p1.y;707 geom-> lower_trough_rect.p1 = geom->trough_rect.p1;699 /* Up through */ 700 geom->up_through_rect.p0 = geom->through_rect.p0; 701 geom->up_through_rect.p1.x = geom->through_rect.p1.x; 702 geom->up_through_rect.p1.y = geom->thumb_rect.p0.y; 703 704 /* Down through */ 705 geom->down_through_rect.p0.x = geom->through_rect.p0.x; 706 geom->down_through_rect.p0.y = geom->thumb_rect.p1.y; 707 geom->down_through_rect.p1 = geom->through_rect.p1; 708 708 709 709 /* Down button */ 710 710 geom->down_btn_rect.p0.x = orect.p0.x; 711 geom->down_btn_rect.p0.y = geom->t rough_rect.p1.y;711 geom->down_btn_rect.p0.y = geom->through_rect.p1.y; 712 712 geom->down_btn_rect.p1.x = orect.p1.x; 713 713 geom->down_btn_rect.p1.y = orect.p1.y; … … 732 732 } 733 733 734 /** Press down scrollbar up per trough.735 * 736 * @param scrollbar Scrollbar 737 */ 738 void ui_scrollbar_up per_trough_press(ui_scrollbar_t *scrollbar)734 /** Press down scrollbar up through. 735 * 736 * @param scrollbar Scrollbar 737 */ 738 void ui_scrollbar_up_through_press(ui_scrollbar_t *scrollbar) 739 739 { 740 740 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 741 741 742 scrollbar->up per_trough_held = true;743 scrollbar->up per_trough_inside = true;742 scrollbar->up_through_held = true; 743 scrollbar->up_through_inside = true; 744 744 745 745 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_up_cb, … … 748 748 } 749 749 750 /** Press down scrollbar lower trough.751 * 752 * @param scrollbar Scrollbar 753 */ 754 void ui_scrollbar_ lower_trough_press(ui_scrollbar_t *scrollbar)750 /** Press down scrollbar down through. 751 * 752 * @param scrollbar Scrollbar 753 */ 754 void ui_scrollbar_down_through_press(ui_scrollbar_t *scrollbar) 755 755 { 756 756 ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui); 757 757 758 scrollbar-> lower_trough_held = true;759 scrollbar-> lower_trough_inside = true;758 scrollbar->down_through_held = true; 759 scrollbar->down_through_inside = true; 760 760 761 761 ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_down_cb, … … 778 778 } 779 779 780 if (scrollbar->up per_trough_held || scrollbar->lower_trough_held) {780 if (scrollbar->up_through_held || scrollbar->down_through_held) { 781 781 clickmatic = ui_get_clickmatic(scrollbar->ui); 782 782 ui_clickmatic_release(clickmatic); 783 783 ui_clickmatic_set_cb(clickmatic, NULL, NULL); 784 784 785 scrollbar->up per_trough_held = false;786 scrollbar-> lower_trough_held = false;785 scrollbar->up_through_held = false; 786 scrollbar->down_through_held = false; 787 787 (void) ui_scrollbar_paint(scrollbar); 788 788 } … … 791 791 /** Update state of scrollbar throuhgs. 792 792 * 793 * Update state of scrollbar t roughs after mouse cursor or thumb has moved.793 * Update state of scrollbar throughs after mouse cursor or thumb has moved. 794 794 * 795 795 * @param scrollbar Scrollbar 796 796 * @param pos Mouse cursor position 797 797 */ 798 void ui_scrollbar_t roughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)798 void ui_scrollbar_throughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos) 799 799 { 800 800 ui_scrollbar_geom_t geom; … … 804 804 ui_scrollbar_get_geom(scrollbar, &geom); 805 805 806 inside_up = gfx_pix_inside_rect(pos, &geom.up per_trough_rect);807 inside_down = gfx_pix_inside_rect(pos, &geom. lower_trough_rect);808 809 if (inside_up && !scrollbar->up per_trough_inside) {810 scrollbar->up per_trough_inside = true;806 inside_up = gfx_pix_inside_rect(pos, &geom.up_through_rect); 807 inside_down = gfx_pix_inside_rect(pos, &geom.down_through_rect); 808 809 if (inside_up && !scrollbar->up_through_inside) { 810 scrollbar->up_through_inside = true; 811 811 (void) ui_scrollbar_paint(scrollbar); 812 } else if (!inside_up && scrollbar->up per_trough_inside) {813 scrollbar->up per_trough_inside = false;812 } else if (!inside_up && scrollbar->up_through_inside) { 813 scrollbar->up_through_inside = false; 814 814 (void) ui_scrollbar_paint(scrollbar); 815 815 } 816 816 817 if (inside_down && !scrollbar-> lower_trough_inside) {818 scrollbar-> lower_trough_inside = true;817 if (inside_down && !scrollbar->down_through_inside) { 818 scrollbar->down_through_inside = true; 819 819 (void) ui_scrollbar_paint(scrollbar); 820 } else if (!inside_down && scrollbar-> lower_trough_inside) {821 scrollbar-> lower_trough_inside = false;820 } else if (!inside_down && scrollbar->down_through_inside) { 821 scrollbar->down_through_inside = false; 822 822 (void) ui_scrollbar_paint(scrollbar); 823 823 } … … 843 843 } 844 844 845 ui_scrollbar_t roughs_update(scrollbar, pos);845 ui_scrollbar_throughs_update(scrollbar, pos); 846 846 } 847 847 … … 866 866 } 867 867 868 /** Scrollbar up per trough was pressed.868 /** Scrollbar up through was pressed. 869 869 * 870 870 * @param scrollbar Scrollbar … … 876 876 } 877 877 878 /** Scrollbar lower trough was pressed.878 /** Scrollbar down through was pressed. 879 879 * 880 880 * @param scrollbar Scrollbar … … 927 927 return ui_claimed; 928 928 } 929 if (gfx_pix_inside_rect(&pos, &geom.up per_trough_rect)) {930 ui_scrollbar_up per_trough_press(scrollbar);929 if (gfx_pix_inside_rect(&pos, &geom.up_through_rect)) { 930 ui_scrollbar_up_through_press(scrollbar); 931 931 return ui_claimed; 932 932 } 933 if (gfx_pix_inside_rect(&pos, &geom. lower_trough_rect)) {934 ui_scrollbar_ lower_trough_press(scrollbar);933 if (gfx_pix_inside_rect(&pos, &geom.down_through_rect)) { 934 ui_scrollbar_down_through_press(scrollbar); 935 935 return ui_claimed; 936 936 } 937 937 break; 938 938 case POS_RELEASE: 939 if (scrollbar->thumb_held || scrollbar->up per_trough_held ||940 scrollbar-> lower_trough_held) {939 if (scrollbar->thumb_held || scrollbar->up_through_held || 940 scrollbar->down_through_held) { 941 941 ui_scrollbar_release(scrollbar, &pos); 942 942 return ui_claimed; … … 1118 1118 } 1119 1119 1120 /** Scrollbar clickmatic up per trough click event.1120 /** Scrollbar clickmatic up through click event. 1121 1121 * 1122 1122 * @param clickmatic Clickmatic … … 1127 1127 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1128 1128 1129 if (scrollbar->up per_trough_inside)1129 if (scrollbar->up_through_inside) 1130 1130 ui_scrollbar_page_up(scrollbar); 1131 1131 } 1132 1132 1133 /** Scrollbar clickmatic lower trough click event.1133 /** Scrollbar clickmatic down through click event. 1134 1134 * 1135 1135 * @param clickmatic Clickmatic … … 1140 1140 ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg; 1141 1141 1142 if (scrollbar-> lower_trough_inside)1142 if (scrollbar->down_through_inside) 1143 1143 ui_scrollbar_page_down(scrollbar); 1144 1144 }
Note:
See TracChangeset
for help on using the changeset viewer.