Changeset 3e6c51f in mainline for uspace/app/nav/panel.c
- Timestamp:
- 2021-10-13T07:41:33Z (3 years ago)
- Children:
- b9d689b
- Parents:
- af2ea83
- git-author:
- Jiri Svoboda <jiri@…> (2021-10-12 19:41:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-10-13 07:41:33)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
raf2ea83 r3e6c51f 137 137 138 138 gfx_text_fmt_init(&fmt); 139 140 rows = panel->rect.p1.y - panel->rect.p0.y - 2; 139 rows = panel_page_size(panel); 141 140 142 141 /* Do not display entry outside of current page */ … … 201 200 return rc; 202 201 203 lines = panel ->rect.p1.y - panel->rect.p0.y - 2;202 lines = panel_page_size(panel); 204 203 i = 0; 205 204 … … 244 243 panel_cursor_bottom(panel); 245 244 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; 246 251 default: 247 252 break; … … 282 287 { 283 288 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 */ 296 unsigned panel_page_size(panel_t *panel) 297 { 298 return panel->rect.p1.y - panel->rect.p0.y - 2; 284 299 } 285 300 … … 494 509 } 495 510 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 */ 496 517 void panel_cursor_move(panel_t *panel, panel_entry_t *entry, size_t entry_idx) 497 518 { … … 503 524 size_t i; 504 525 505 rows = panel ->rect.p1.y - panel->rect.p0.y - 2;526 rows = panel_page_size(panel); 506 527 507 528 old_cursor = panel->cursor; … … 604 625 } 605 626 627 /** Move one page up. 628 * 629 * @param panel Panel 630 */ 631 void 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 */ 682 void 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 606 732 /** @} 607 733 */
Note:
See TracChangeset
for help on using the changeset viewer.