Changeset 8c72f533 in mainline for uspace/app/nav/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (2 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2fb49522
Parents:
be1d74c1
git-author:
Jiri Svoboda <jiri@…> (2021-10-12 19:41:17)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Page up and page down

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    rbe1d74c1 r8c72f533  
    137137
    138138        gfx_text_fmt_init(&fmt);
    139 
    140         rows = panel->rect.p1.y - panel->rect.p0.y - 2;
     139        rows = panel_page_size(panel);
    141140
    142141        /* Do not display entry outside of current page */
     
    201200                return rc;
    202201
    203         lines = panel->rect.p1.y - panel->rect.p0.y - 2;
     202        lines = panel_page_size(panel);
    204203        i = 0;
    205204
     
    244243                                panel_cursor_bottom(panel);
    245244                                break;
     245                        case KC_PAGE_UP:
     246                                panel_page_up(panel);
     247                                break;
     248                        case KC_PAGE_DOWN:
     249                                panel_page_down(panel);
     250                                break;
    246251                        default:
    247252                                break;
     
    282287{
    283288        panel->rect = *rect;
     289}
     290
     291/** Get panel page size.
     292 *
     293 * @param panel Panel
     294 * @return Number of entries that fit in panel at the same time.
     295 */
     296unsigned panel_page_size(panel_t *panel)
     297{
     298        return panel->rect.p1.y - panel->rect.p0.y - 2;
    284299}
    285300
     
    494509}
    495510
     511/** Move cursor to a new position, possibly scrolling.
     512 *
     513 * @param panel Panel
     514 * @param entry New entry under cursor
     515 * @param entry_idx Index of new entry under cursor
     516 */
    496517void panel_cursor_move(panel_t *panel, panel_entry_t *entry, size_t entry_idx)
    497518{
     
    503524        size_t i;
    504525
    505         rows = panel->rect.p1.y - panel->rect.p0.y - 2;
     526        rows = panel_page_size(panel);
    506527
    507528        old_cursor = panel->cursor;
     
    604625}
    605626
     627/** Move one page up.
     628 *
     629 * @param panel Panel
     630 */
     631void panel_page_up(panel_t *panel)
     632{
     633        gfx_context_t *gc = ui_window_get_gc(panel->window);
     634        panel_entry_t *old_page;
     635        panel_entry_t *old_cursor;
     636        size_t old_idx;
     637        size_t rows;
     638        panel_entry_t *entry;
     639        size_t i;
     640
     641        rows = panel_page_size(panel);
     642
     643        old_page = panel->page;
     644        old_cursor = panel->cursor;
     645        old_idx = panel->cursor_idx;
     646
     647        /* Move page by rows entries up (if possible) */
     648        for (i = 0; i < rows; i++) {
     649                entry = panel_prev(panel->page);
     650                if (entry != NULL) {
     651                        panel->page = entry;
     652                        --panel->page_idx;
     653                }
     654        }
     655
     656        /* Move cursor by rows entries up (if possible) */
     657
     658        for (i = 0; i < rows; i++) {
     659                entry = panel_prev(panel->cursor);
     660                if (entry != NULL) {
     661                        panel->cursor = entry;
     662                        --panel->cursor_idx;
     663                }
     664        }
     665
     666        if (panel->page != old_page) {
     667                /* We have scrolled. Need to repaint all entries */
     668                (void) panel_paint(panel);
     669        } else if (panel->cursor != old_cursor) {
     670                /* No scrolling, but cursor has moved */
     671                panel_entry_paint(old_cursor, old_idx);
     672                panel_entry_paint(panel->cursor, panel->cursor_idx);
     673
     674                (void) gfx_update(gc);
     675        }
     676}
     677
     678/** Move one page down.
     679 *
     680 * @param panel Panel
     681 */
     682void panel_page_down(panel_t *panel)
     683{
     684        gfx_context_t *gc = ui_window_get_gc(panel->window);
     685        panel_entry_t *old_page;
     686        panel_entry_t *old_cursor;
     687        size_t old_idx;
     688        size_t max_idx;
     689        size_t rows;
     690        panel_entry_t *entry;
     691        size_t i;
     692
     693        rows = panel_page_size(panel);
     694
     695        old_page = panel->page;
     696        old_cursor = panel->cursor;
     697        old_idx = panel->cursor_idx;
     698        max_idx = panel->entries_cnt - rows;
     699
     700        /* Move page by rows entries down (if possible) */
     701        for (i = 0; i < rows; i++) {
     702                entry = panel_next(panel->page);
     703                /* Do not scroll that results in a short page */
     704                if (entry != NULL && panel->page_idx < max_idx) {
     705                        panel->page = entry;
     706                        ++panel->page_idx;
     707                }
     708        }
     709
     710        /* Move cursor by rows entries down (if possible) */
     711
     712        for (i = 0; i < rows; i++) {
     713                entry = panel_next(panel->cursor);
     714                if (entry != NULL) {
     715                        panel->cursor = entry;
     716                        ++panel->cursor_idx;
     717                }
     718        }
     719
     720        if (panel->page != old_page) {
     721                /* We have scrolled. Need to repaint all entries */
     722                (void) panel_paint(panel);
     723        } else if (panel->cursor != old_cursor) {
     724                /* No scrolling, but cursor has moved */
     725                panel_entry_paint(old_cursor, old_idx);
     726                panel_entry_paint(panel->cursor, panel->cursor_idx);
     727
     728                (void) gfx_update(gc);
     729        }
     730}
     731
    606732/** @}
    607733 */
Note: See TracChangeset for help on using the changeset viewer.