Changeset c0757e1f in mainline for uspace/lib/ui/src/list.c


Ignore:
Timestamp:
2023-04-19T11:13:06Z (20 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
37087c8
Parents:
ec8ef12
Message:

UI display configuration utility

In addition to the command-line utility 'disp', we introduce its UI
equivalent 'display-cfg'. Currently this allows the user to configure
seats in a very comfortable way.

File:
1 edited

Legend:

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

    rec8ef12 rc0757e1f  
    149149        list->cb = cb;
    150150        list->cb_arg = arg;
     151}
     152
     153/** Get UI list callback argument.
     154 *
     155 * @param list UI list
     156 * @return Callback argument
     157 */
     158void *ui_list_get_cb_arg(ui_list_t *list)
     159{
     160        return list->cb_arg;
    151161}
    152162
     
    701711}
    702712
    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.
    704716 *
    705717 * @param entry UI list entry
    706718 */
    707 void ui_list_entry_delete(ui_list_entry_t *entry)
     719void ui_list_entry_destroy(ui_list_entry_t *entry)
    708720{
    709721        if (entry->list->cursor == entry)
     
    718730}
    719731
     732/** Delete UI list entry.
     733 *
     734 * If required, update cursor and page position and repaint.
     735 *
     736 * @param entry UI list entry
     737 */
     738void ui_list_entry_delete(ui_list_entry_t *entry)
     739{
     740        /* Try to make sure entry does not disappear between cursor and page */
     741        if (entry->list->cursor == entry)
     742                ui_list_cursor_up(entry->list);
     743        if (entry->list->cursor == entry)
     744                ui_list_cursor_down(entry->list);
     745        if (entry->list->page == entry)
     746                ui_list_scroll_up(entry->list);
     747        if (entry->list->page == entry)
     748                ui_list_scroll_down(entry->list);
     749
     750        ui_list_entry_destroy(entry);
     751}
     752
    720753/** Get entry argument.
    721754 *
     
    728761}
    729762
     763/** Get containing list.
     764 *
     765 * @param entry UI list entry
     766 * @return Containing list
     767 */
     768ui_list_t *ui_list_entry_get_list(ui_list_entry_t *entry)
     769{
     770        return entry->list;
     771}
     772
    730773/** Clear UI list entry list.
    731774 *
     
    738781        entry = ui_list_first(list);
    739782        while (entry != NULL) {
    740                 ui_list_entry_delete(entry);
     783                ui_list_entry_destroy(entry);
    741784                entry = ui_list_first(list);
    742785        }
     
    858901{
    859902        return list->cursor;
     903}
     904
     905/** Set new cursor position.
     906 *
     907 * O(N) in list size, use with caution.
     908 *
     909 * @param list UI list
     910 * @param entry New cursor position
     911 */
     912void ui_list_set_cursor(ui_list_t *list, ui_list_entry_t *entry)
     913{
     914        size_t idx;
     915
     916        idx = ui_list_entry_get_idx(entry);
     917        ui_list_cursor_move(list, entry, idx);
    860918}
    861919
     
    912970                                /* Find first page entry (go back rows - 1) */
    913971                                e = entry;
    914                                 for (i = 0; i < rows - 1; i++) {
     972                                for (i = 0; i + 1 < rows; i++) {
    915973                                        e = ui_list_prev(e);
    916974                                }
     
    10981156        ui_list_entry_t *prev;
    10991157
     1158        if (list->page == NULL)
     1159                return;
     1160
    11001161        prev = ui_list_prev(list->page);
    11011162        if (prev == NULL)
     
    11201181        size_t i;
    11211182        size_t rows;
     1183
     1184        if (list->page == NULL)
     1185                return;
    11221186
    11231187        next = ui_list_next(list->page);
Note: See TracChangeset for help on using the changeset viewer.