Changeset ef4d684 in mainline for uspace/lib/ui/src/scrollbar.c


Ignore:
Timestamp:
2023-11-29T12:39:32Z (5 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, topic/simplify-dev-export
Children:
0e2eee1
Parents:
84d29a2
Message:

It should be 'trough', not 'through', dummy! (thx thepinballroom)

Who said watching a guy making a pinball machine was a waste of time?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/scrollbar.c

    r84d29a2 ref4d684  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3535 * Anatomy of a horizontal scrollbar:
    3636 *
    37  *       Up                Down
    38  *      through           through
    39  * +---+------+--------+---------+---+
    40  * | < |      |   |||  |         | > |
    41  * +---+------+--------+---------+---+
    42  *  Up           Thumb           Down
    43  * button                       button
    44  *
    45  *     +-------- Through --------+
     37 *        Upper             Lower
     38 *       trough            trough
     39 *  +---+------+--------+---------+---+
     40 *  | < |      |   |||  |         | > |
     41 *  +---+------+--------+---------+---+
     42 *   Up           Thumb           Down
     43 * button                        button
     44 *
     45 *     +-------- Trough --------+
    4646 *
    4747 * Scrollbar uses the same terminology whether it is running in horizontal
     
    5151 * The thumb can be dragged to a specific position, resulting in a move
    5252 * 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  * Pressing and holding down mouse button on up / down button or up / down
    56  * through will auto-scroll (using clickmatic).
     53 * button on the upper/lower trough generates page up / page down events.
     54 *
     55 * Pressing and holding down mouse button on up / down button or upper /
     56 * lower trough will auto-scroll (using clickmatic).
    5757 */
    5858
     
    360360}
    361361
    362 /** Determine scrollbar through length.
     362/** Determine scrollbar trough length.
    363363 *
    364364 * Return the size of the space within which the thumb can move
     
    366366 *
    367367 * @param scrollbar Scrollbar
    368  * @return Scrollbar through length in pixels
    369  */
    370 gfx_coord_t ui_scrollbar_through_length(ui_scrollbar_t *scrollbar)
     368 * @return Scrollbar trough length in pixels
     369 */
     370gfx_coord_t ui_scrollbar_trough_length(ui_scrollbar_t *scrollbar)
    371371{
    372372        ui_resource_t *resource;
     
    396396gfx_coord_t ui_scrollbar_move_length(ui_scrollbar_t *scrollbar)
    397397{
    398         return ui_scrollbar_through_length(scrollbar) -
     398        return ui_scrollbar_trough_length(scrollbar) -
    399399            scrollbar->thumb_len;
    400400}
     
    417417            ui_scrollbar_min_thumb_len;
    418418
    419         max_len = ui_scrollbar_through_length(scrollbar);
     419        max_len = ui_scrollbar_trough_length(scrollbar);
    420420        if (len < min_len)
    421421                len = min_len;
     
    459459                scrollbar->pos = pos;
    460460                (void) ui_scrollbar_paint(scrollbar);
    461                 ui_scrollbar_throughs_update(scrollbar,
     461                ui_scrollbar_troughs_update(scrollbar,
    462462                    &scrollbar->last_curs_pos);
    463463        }
     
    487487                goto error;
    488488
    489         /* Paint scrollbar up through */
     489        /* Paint scrollbar upper trough */
    490490        rc = gfx_set_color(resource->gc,
    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 */
     491            scrollbar->upper_trough_held && scrollbar->upper_trough_inside ?
     492            resource->sbar_act_trough_color :
     493            resource->sbar_trough_color);
     494        if (rc != EOK)
     495                goto error;
     496
     497        rc = gfx_fill_rect(resource->gc, &geom.upper_trough_rect);
     498        if (rc != EOK)
     499                goto error;
     500
     501        /* Paint scrollbar lower trough */
    502502
    503503        rc = gfx_set_color(resource->gc,
    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);
     504            scrollbar->lower_trough_held && scrollbar->lower_trough_inside ?
     505            resource->sbar_act_trough_color :
     506            resource->sbar_trough_color);
     507        if (rc != EOK)
     508                goto error;
     509
     510        rc = gfx_fill_rect(resource->gc, &geom.lower_trough_rect);
    511511        if (rc != EOK)
    512512                goto error;
     
    561561        ui_scrollbar_get_geom(scrollbar, &geom);
    562562
    563         /* Paint scrollbar through */
    564 
    565         rc = ui_paint_text_rect(resource, &geom.through_rect,
    566             resource->sbar_through_color, "\u2592");
     563        /* Paint scrollbar trough */
     564
     565        rc = ui_paint_text_rect(resource, &geom.trough_rect,
     566            resource->sbar_trough_color, "\u2592");
    567567        if (rc != EOK)
    568568                goto error;
     
    571571
    572572        rc = ui_paint_text_rect(resource, &geom.thumb_rect,
    573             resource->sbar_through_color, "\u25a0");
     573            resource->sbar_trough_color, "\u25a0");
    574574        if (rc != EOK)
    575575                goto error;
     
    647647                geom->up_btn_rect.p1.y = orect.p1.y;
    648648
    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;
     649                /* Trough */
     650                geom->trough_rect.p0.x = geom->up_btn_rect.p1.x;
     651                geom->trough_rect.p0.y = irect.p0.y;
     652                geom->trough_rect.p1.x = orect.p1.x - btn_len;
     653                geom->trough_rect.p1.y = irect.p1.y;
    654654
    655655                /* Thumb */
     
    661661                geom->thumb_rect.p1.y = orect.p1.y;
    662662
    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;
     663                /* Upper trough */
     664                geom->upper_trough_rect.p0 = geom->trough_rect.p0;
     665                geom->upper_trough_rect.p1.x = geom->thumb_rect.p0.x;
     666                geom->upper_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;
    672672
    673673                /* Down button */
    674                 geom->down_btn_rect.p0.x = geom->through_rect.p1.x;
     674                geom->down_btn_rect.p0.x = geom->trough_rect.p1.x;
    675675                geom->down_btn_rect.p0.y = orect.p0.y;
    676676                geom->down_btn_rect.p1.x = orect.p1.x;
     
    683683                geom->up_btn_rect.p1.y = orect.p0.y + btn_len;
    684684
    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;
     685                /* Trough */
     686                geom->trough_rect.p0.x = irect.p0.x;
     687                geom->trough_rect.p0.y = geom->up_btn_rect.p1.y;
     688                geom->trough_rect.p1.x = irect.p1.x;
     689                geom->trough_rect.p1.y = orect.p1.y - btn_len;
    690690
    691691                /* Thumb */
     
    697697                    scrollbar->thumb_len;
    698698
    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;
     699                /* Upper trough */
     700                geom->upper_trough_rect.p0 = geom->trough_rect.p0;
     701                geom->upper_trough_rect.p1.x = geom->trough_rect.p1.x;
     702                geom->upper_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;
    708708
    709709                /* Down button */
    710710                geom->down_btn_rect.p0.x = orect.p0.x;
    711                 geom->down_btn_rect.p0.y = geom->through_rect.p1.y;
     711                geom->down_btn_rect.p0.y = geom->trough_rect.p1.y;
    712712                geom->down_btn_rect.p1.x = orect.p1.x;
    713713                geom->down_btn_rect.p1.y = orect.p1.y;
     
    732732}
    733733
    734 /** Press down scrollbar up through.
    735  *
    736  * @param scrollbar Scrollbar
    737  */
    738 void ui_scrollbar_up_through_press(ui_scrollbar_t *scrollbar)
     734/** Press down scrollbar upper trough.
     735 *
     736 * @param scrollbar Scrollbar
     737 */
     738void ui_scrollbar_upper_trough_press(ui_scrollbar_t *scrollbar)
    739739{
    740740        ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
    741741
    742         scrollbar->up_through_held = true;
    743         scrollbar->up_through_inside = true;
     742        scrollbar->upper_trough_held = true;
     743        scrollbar->upper_trough_inside = true;
    744744
    745745        ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_up_cb,
     
    748748}
    749749
    750 /** Press down scrollbar down through.
    751  *
    752  * @param scrollbar Scrollbar
    753  */
    754 void ui_scrollbar_down_through_press(ui_scrollbar_t *scrollbar)
     750/** Press down scrollbar lower trough.
     751 *
     752 * @param scrollbar Scrollbar
     753 */
     754void ui_scrollbar_lower_trough_press(ui_scrollbar_t *scrollbar)
    755755{
    756756        ui_clickmatic_t *clickmatic = ui_get_clickmatic(scrollbar->ui);
    757757
    758         scrollbar->down_through_held = true;
    759         scrollbar->down_through_inside = true;
     758        scrollbar->lower_trough_held = true;
     759        scrollbar->lower_trough_inside = true;
    760760
    761761        ui_clickmatic_set_cb(clickmatic, &ui_scrollbar_clickmatic_page_down_cb,
     
    778778        }
    779779
    780         if (scrollbar->up_through_held || scrollbar->down_through_held) {
     780        if (scrollbar->upper_trough_held || scrollbar->lower_trough_held) {
    781781                clickmatic = ui_get_clickmatic(scrollbar->ui);
    782782                ui_clickmatic_release(clickmatic);
    783783                ui_clickmatic_set_cb(clickmatic, NULL, NULL);
    784784
    785                 scrollbar->up_through_held = false;
    786                 scrollbar->down_through_held = false;
     785                scrollbar->upper_trough_held = false;
     786                scrollbar->lower_trough_held = false;
    787787                (void) ui_scrollbar_paint(scrollbar);
    788788        }
     
    791791/** Update state of scrollbar throuhgs.
    792792 *
    793  * Update state of scrollbar throughs after mouse cursor or thumb has moved.
     793 * Update state of scrollbar troughs after mouse cursor or thumb has moved.
    794794 *
    795795 * @param scrollbar Scrollbar
    796796 * @param pos Mouse cursor position
    797797 */
    798 void ui_scrollbar_throughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
     798void ui_scrollbar_troughs_update(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
    799799{
    800800        ui_scrollbar_geom_t geom;
     
    804804        ui_scrollbar_get_geom(scrollbar, &geom);
    805805
    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;
     806        inside_up = gfx_pix_inside_rect(pos, &geom.upper_trough_rect);
     807        inside_down = gfx_pix_inside_rect(pos, &geom.lower_trough_rect);
     808
     809        if (inside_up && !scrollbar->upper_trough_inside) {
     810                scrollbar->upper_trough_inside = true;
    811811                (void) ui_scrollbar_paint(scrollbar);
    812         } else if (!inside_up && scrollbar->up_through_inside) {
    813                 scrollbar->up_through_inside = false;
     812        } else if (!inside_up && scrollbar->upper_trough_inside) {
     813                scrollbar->upper_trough_inside = false;
    814814                (void) ui_scrollbar_paint(scrollbar);
    815815        }
    816816
    817         if (inside_down && !scrollbar->down_through_inside) {
    818                 scrollbar->down_through_inside = true;
     817        if (inside_down && !scrollbar->lower_trough_inside) {
     818                scrollbar->lower_trough_inside = true;
    819819                (void) ui_scrollbar_paint(scrollbar);
    820         } else if (!inside_down && scrollbar->down_through_inside) {
    821                 scrollbar->down_through_inside = false;
     820        } else if (!inside_down && scrollbar->lower_trough_inside) {
     821                scrollbar->lower_trough_inside = false;
    822822                (void) ui_scrollbar_paint(scrollbar);
    823823        }
     
    843843        }
    844844
    845         ui_scrollbar_throughs_update(scrollbar, pos);
     845        ui_scrollbar_troughs_update(scrollbar, pos);
    846846}
    847847
     
    866866}
    867867
    868 /** Scrollbar up through was pressed.
     868/** Scrollbar upper trough was pressed.
    869869 *
    870870 * @param scrollbar Scrollbar
     
    876876}
    877877
    878 /** Scrollbar down through was pressed.
     878/** Scrollbar lower trough was pressed.
    879879 *
    880880 * @param scrollbar Scrollbar
     
    927927                        return ui_claimed;
    928928                }
    929                 if (gfx_pix_inside_rect(&pos, &geom.up_through_rect)) {
    930                         ui_scrollbar_up_through_press(scrollbar);
     929                if (gfx_pix_inside_rect(&pos, &geom.upper_trough_rect)) {
     930                        ui_scrollbar_upper_trough_press(scrollbar);
    931931                        return ui_claimed;
    932932                }
    933                 if (gfx_pix_inside_rect(&pos, &geom.down_through_rect)) {
    934                         ui_scrollbar_down_through_press(scrollbar);
     933                if (gfx_pix_inside_rect(&pos, &geom.lower_trough_rect)) {
     934                        ui_scrollbar_lower_trough_press(scrollbar);
    935935                        return ui_claimed;
    936936                }
    937937                break;
    938938        case POS_RELEASE:
    939                 if (scrollbar->thumb_held || scrollbar->up_through_held ||
    940                     scrollbar->down_through_held) {
     939                if (scrollbar->thumb_held || scrollbar->upper_trough_held ||
     940                    scrollbar->lower_trough_held) {
    941941                        ui_scrollbar_release(scrollbar, &pos);
    942942                        return ui_claimed;
     
    11181118}
    11191119
    1120 /** Scrollbar clickmatic up through click event.
     1120/** Scrollbar clickmatic upper trough click event.
    11211121 *
    11221122 * @param clickmatic Clickmatic
     
    11271127        ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
    11281128
    1129         if (scrollbar->up_through_inside)
     1129        if (scrollbar->upper_trough_inside)
    11301130                ui_scrollbar_page_up(scrollbar);
    11311131}
    11321132
    1133 /** Scrollbar clickmatic down through click event.
     1133/** Scrollbar clickmatic lower trough click event.
    11341134 *
    11351135 * @param clickmatic Clickmatic
     
    11401140        ui_scrollbar_t *scrollbar = (ui_scrollbar_t *)arg;
    11411141
    1142         if (scrollbar->down_through_inside)
     1142        if (scrollbar->lower_trough_inside)
    11431143                ui_scrollbar_page_down(scrollbar);
    11441144}
Note: See TracChangeset for help on using the changeset viewer.