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


Ignore:
Timestamp:
2022-03-20T19:51:09Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
26c90dd
Parents:
5ef85c0
Message:

Clicking scrollbar through to generate page up / page down

File:
1 edited

Legend:

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

    r5ef85c0 r1026cc4  
    3232/**
    3333 * @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.
    3457 */
    3558
     
    391414                goto error;
    392415
    393         /* Paint scrollbar through */
    394 
     416        /* Paint scrollbar up through */
    395417        rc = gfx_set_color(scrollbar->res->gc,
     418            scrollbar->up_through_held ?
     419            scrollbar->res->sbar_act_through_color :
    396420            scrollbar->res->sbar_through_color);
    397421        if (rc != EOK)
    398422                goto error;
    399423
    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);
    401438        if (rc != EOK)
    402439                goto error;
     
    582619        geom->thumb_rect.p1.y = orect.p1.y;
    583620
     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
    584631        /* Down button */
    585632        geom->down_btn_rect.p0.x = geom->through_rect.p1.x;
     
    618665}
    619666
    620 /** Press down scrollbar.
     667/** Press down scrollbar thumb.
    621668 *
    622669 * @param scrollbar Scrollbar
    623670 * @param pos Pointer position
    624671 */
    625 void ui_scrollbar_press(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
    626 {
    627         if (scrollbar->held)
     672void ui_scrollbar_thumb_press(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
     673{
     674        if (scrollbar->thumb_held)
    628675                return;
    629676
    630         scrollbar->held = true;
     677        scrollbar->thumb_held = true;
    631678        scrollbar->press_pos = *pos;
    632679        scrollbar->last_pos = scrollbar->pos;
     
    635682}
    636683
     684/** Press down scrollbar up through.
     685 *
     686 * @param scrollbar Scrollbar
     687 */
     688void 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 */
     703void 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
    637714/** Release scrollbar.
    638715 *
     
    642719void ui_scrollbar_release(ui_scrollbar_t *scrollbar, gfx_coord2_t *pos)
    643720{
    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        }
    649731}
    650732
     
    658740        gfx_coord_t spos;
    659741
    660         if (scrollbar->held) {
     742        if (scrollbar->thumb_held) {
    661743                spos = scrollbar->last_pos + pos->x - scrollbar->press_pos.x;
    662744                ui_scrollbar_set_pos(scrollbar, spos);
     
    680762void ui_scrollbar_down(ui_scrollbar_t *scrollbar)
    681763{
    682         if (scrollbar->cb != NULL && scrollbar->cb->up != NULL)
     764        if (scrollbar->cb != NULL && scrollbar->cb->down != NULL)
    683765                scrollbar->cb->down(scrollbar, scrollbar->arg);
     766}
     767
     768/** Scrollbar up through was pressed.
     769 *
     770 * @param scrollbar Scrollbar
     771 */
     772void 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 */
     782void 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);
    684786}
    685787
     
    703805{
    704806        gfx_coord2_t pos;
    705         gfx_rect_t rect;
    706807        ui_evclaim_t claimed;
     808        ui_scrollbar_geom_t geom;
     809
     810        ui_scrollbar_get_geom(scrollbar, &geom);
    707811
    708812        pos.x = event->hpos;
     
    719823        switch (event->type) {
    720824        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);
    725835                        return ui_claimed;
    726836                }
    727837                break;
    728838        case POS_RELEASE:
    729                 if (scrollbar->held) {
     839                if (scrollbar->thumb_held || scrollbar->up_through_held ||
     840                    scrollbar->down_through_held) {
    730841                        ui_scrollbar_release(scrollbar, &pos);
    731842                        return ui_claimed;
Note: See TracChangeset for help on using the changeset viewer.