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


Ignore:
Timestamp:
2024-02-13T20:13:48Z (3 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
10657856
Parents:
242e3c3
Message:

Moving start menu entry up and down

File:
1 edited

Legend:

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

    r242e3c3 r28ca31ed  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    711711}
    712712
     713/** Move UI list entry one position up.
     714 *
     715 * @parm entry UI list entry
     716 */
     717void ui_list_entry_move_up(ui_list_entry_t *entry)
     718{
     719        ui_list_t *list = entry->list;
     720        ui_list_entry_t *prev;
     721
     722        prev = ui_list_prev(entry);
     723        if (prev == NULL) {
     724                /* Entry is already on first position, nothing to do. */
     725                return;
     726        }
     727
     728        list_remove(&entry->lentries);
     729        list_insert_before(&entry->lentries, &prev->lentries);
     730
     731        /* Make sure page stays on the same position/idx as it was before */
     732        if (list->page == entry) {
     733                list->page = prev;
     734        } else if (list->page == prev) {
     735                list->page = entry;
     736        }
     737
     738        /*
     739         * Return cursor to the same position/idx as it was before,
     740         * but then move it using ui_list_cursor_move() to the new
     741         * position (this ensures scrolling when needed).
     742         */
     743        if (list->cursor == entry) {
     744                list->cursor = prev;
     745                ui_list_cursor_move(list, entry, list->cursor_idx - 1);
     746        } else if (list->cursor == prev) {
     747                list->cursor = entry;
     748                ui_list_cursor_move(list, prev, list->cursor_idx + 1);
     749        }
     750}
     751
     752/** Move UI list entry one position down.
     753 *
     754 * @parm entry UI list entry
     755 */
     756void ui_list_entry_move_down(ui_list_entry_t *entry)
     757{
     758        ui_list_t *list = entry->list;
     759        ui_list_entry_t *next;
     760
     761        next = ui_list_next(entry);
     762        if (next == NULL) {
     763                /* Entry is already on last position, nothing to do. */
     764                return;
     765        }
     766
     767        list_remove(&entry->lentries);
     768        list_insert_after(&entry->lentries, &next->lentries);
     769
     770        /* Make sure page stays on the same position/idx as it was before */
     771        if (list->page == entry) {
     772                list->page = next;
     773        } else if (list->page == next) {
     774                list->page = entry;
     775        }
     776
     777        /*
     778         * Return cursor to the same position/idx as it was before,
     779         * but then move it using ui_list_cursor_move() to the new
     780         * position (this ensures scrolling when needed).
     781         */
     782        if (list->cursor == entry) {
     783                list->cursor = next;
     784                ui_list_cursor_move(list, entry, list->cursor_idx + 1);
     785        } else if (list->cursor == next) {
     786                list->cursor = entry;
     787                ui_list_cursor_move(list, next, list->cursor_idx - 1);
     788        }
     789}
     790
    713791/** Destroy UI list entry.
    714792 *
Note: See TracChangeset for help on using the changeset viewer.