Changeset dc5c303 in mainline for uspace/lib/ui/src/list.c
- Timestamp:
- 2023-12-28T13:59:23Z (2 years ago)
- Children:
- 6b66de6b
- Parents:
- 42c2e65 (diff), f87ff8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2023-12-28 13:59:23)
- git-committer:
- GitHub <noreply@…> (2023-12-28 13:59:23)
- File:
-
- 1 edited
-
uspace/lib/ui/src/list.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/list.c
r42c2e65 rdc5c303 149 149 list->cb = cb; 150 150 list->cb_arg = arg; 151 } 152 153 /** Get UI list callback argument. 154 * 155 * @param list UI list 156 * @return Callback argument 157 */ 158 void *ui_list_get_cb_arg(ui_list_t *list) 159 { 160 return list->cb_arg; 151 161 } 152 162 … … 701 711 } 702 712 703 /** Delete UI list entry. 713 /** Destroy UI list entry. 714 * 715 * This is the quick way, but does not update cursor or page position. 704 716 * 705 717 * @param entry UI list entry 706 718 */ 707 void ui_list_entry_de lete(ui_list_entry_t *entry)719 void ui_list_entry_destroy(ui_list_entry_t *entry) 708 720 { 709 721 if (entry->list->cursor == entry) … … 718 730 } 719 731 732 /** Delete UI list entry. 733 * 734 * If required, update cursor and page position and repaint. 735 * 736 * @param entry UI list entry 737 */ 738 void ui_list_entry_delete(ui_list_entry_t *entry) 739 { 740 ui_list_t *list = entry->list; 741 742 /* Try to make sure entry does not disappear under cursor or page */ 743 if (entry->list->cursor == entry) 744 ui_list_cursor_up(entry->list); 745 if (entry->list->cursor == entry) 746 ui_list_cursor_down(entry->list); 747 if (entry->list->page == entry) 748 ui_list_scroll_up(entry->list); 749 if (entry->list->page == entry) 750 ui_list_scroll_down(entry->list); 751 752 ui_list_entry_destroy(entry); 753 754 /* 755 * But it could still happen if there are not enough entries. 756 * In that case just move page and/or cursor to the first 757 * entry. 758 */ 759 if (list->page == NULL) { 760 list->page = ui_list_first(list); 761 list->page_idx = 0; 762 } else { 763 /* 764 * Entry index might have changed if earlier entry 765 * was deleted. 766 */ 767 list->page_idx = ui_list_entry_get_idx(list->page); 768 } 769 770 if (list->cursor == NULL) { 771 list->cursor = ui_list_first(list); 772 list->cursor_idx = 0; 773 } else { 774 /* 775 * Entry index might have changed if earlier entry 776 * was deleted. 777 */ 778 list->cursor_idx = ui_list_entry_get_idx(list->cursor); 779 } 780 } 781 720 782 /** Get entry argument. 721 783 * … … 728 790 } 729 791 792 /** Get containing list. 793 * 794 * @param entry UI list entry 795 * @return Containing list 796 */ 797 ui_list_t *ui_list_entry_get_list(ui_list_entry_t *entry) 798 { 799 return entry->list; 800 } 801 802 /** Change list entry caption. 803 * 804 * @param entry UI list entry 805 * @param caption New caption 806 * 807 * @return EOK on success, ENOMEM if out of memory 808 */ 809 errno_t ui_list_entry_set_caption(ui_list_entry_t *entry, const char *caption) 810 { 811 char *dcaption; 812 813 dcaption = str_dup(caption); 814 if (dcaption == NULL) 815 return ENOMEM; 816 817 free(entry->caption); 818 entry->caption = dcaption; 819 820 (void)ui_list_entry_paint(entry, ui_list_entry_get_idx(entry)); 821 return EOK; 822 } 823 730 824 /** Clear UI list entry list. 731 825 * … … 738 832 entry = ui_list_first(list); 739 833 while (entry != NULL) { 740 ui_list_entry_de lete(entry);834 ui_list_entry_destroy(entry); 741 835 entry = ui_list_first(list); 742 836 } … … 858 952 { 859 953 return list->cursor; 954 } 955 956 /** Set new cursor position. 957 * 958 * O(N) in list size, use with caution. 959 * 960 * @param list UI list 961 * @param entry New cursor position 962 */ 963 void ui_list_set_cursor(ui_list_t *list, ui_list_entry_t *entry) 964 { 965 size_t idx; 966 967 idx = ui_list_entry_get_idx(entry); 968 ui_list_cursor_move(list, entry, idx); 860 969 } 861 970 … … 912 1021 /* Find first page entry (go back rows - 1) */ 913 1022 e = entry; 914 for (i = 0; i < rows - 1; i++) {1023 for (i = 0; i + 1 < rows; i++) { 915 1024 e = ui_list_prev(e); 916 1025 } … … 1098 1207 ui_list_entry_t *prev; 1099 1208 1209 if (list->page == NULL) 1210 return; 1211 1100 1212 prev = ui_list_prev(list->page); 1101 1213 if (prev == NULL) … … 1120 1232 size_t i; 1121 1233 size_t rows; 1234 1235 if (list->page == NULL) 1236 return; 1122 1237 1123 1238 next = ui_list_next(list->page);
Note:
See TracChangeset
for help on using the changeset viewer.
