Changeset aefdccd in mainline for uspace/lib/ui


Ignore:
Timestamp:
2025-10-20T06:14:54Z (2 months ago)
Author:
GitHub <noreply@…>
Parents:
adbd7e1 (diff), 3e41cc4 (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@…> (2025-10-20 06:14:54)
git-committer:
GitHub <noreply@…> (2025-10-20 06:14:54)
Message:

Merge branch 'HelenOS:master' into ticket/packet-capture

Location:
uspace/lib/ui
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/types/ui/list.h

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838
    3939#include <gfx/color.h>
     40#include <stddef.h>
    4041
    4142struct ui_list;
     
    6768} ui_list_cb_t;
    6869
     70/** Saved list position. */
     71typedef struct {
     72        /** Page index */
     73        size_t page_idx;
     74        /** Cursor index */
     75        size_t cursor_idx;
     76} ui_list_pos_t;
     77
    6978#endif
    7079
  • uspace/lib/ui/include/ui/filelist.h

    radbd7e1 raefdccd  
    5151extern errno_t ui_file_list_read_dir(ui_file_list_t *, const char *);
    5252extern errno_t ui_file_list_activate(ui_file_list_t *);
     53extern errno_t ui_file_list_refresh(ui_file_list_t *);
    5354extern void ui_file_list_deactivate(ui_file_list_t *);
    5455extern errno_t ui_file_list_open(ui_file_list_t *, ui_file_list_entry_t *);
  • uspace/lib/ui/include/ui/list.h

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7171extern ui_list_entry_t *ui_list_prev(ui_list_entry_t *);
    7272extern bool ui_list_is_active(ui_list_t *);
     73extern void ui_list_save_pos(ui_list_t *, ui_list_pos_t *);
     74extern void ui_list_restore_pos(ui_list_t *, ui_list_pos_t *);
    7375
    7476#endif
  • uspace/lib/ui/include/ui/window.h

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5656extern void ui_window_add(ui_window_t *, ui_control_t *);
    5757extern void ui_window_remove(ui_window_t *, ui_control_t *);
    58 extern ui_window_t *ui_window_get_active(ui_t *);
    5958extern errno_t ui_window_resize(ui_window_t *, gfx_rect_t *);
    6059extern ui_t *ui_window_get_ui(ui_window_t *);
  • uspace/lib/ui/private/window.h

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    136136extern errno_t ui_window_size_change(ui_window_t *, gfx_rect_t *,
    137137    ui_wnd_sc_op_t);
     138extern ui_window_t *ui_window_get_active(ui_t *);
     139extern ui_window_t *ui_window_first(ui_t *);
     140extern ui_window_t *ui_window_next(ui_window_t *);
    138141
    139142#endif
  • uspace/lib/ui/src/filelist.c

    radbd7e1 raefdccd  
    349349                goto error;
    350350        }
     351
     352        ui_file_list_clear_entries(flist);
    351353
    352354        if (str_cmp(ndir, "/") != 0) {
     
    422424}
    423425
     426/** Re-read file list from directory.
     427 *
     428 * @param flist File list
     429 * @return EOK on success or an error code
     430 */
     431errno_t ui_file_list_refresh(ui_file_list_t *flist)
     432{
     433        errno_t rc;
     434        ui_list_pos_t pos;
     435
     436        ui_list_save_pos(flist->list, &pos);
     437        rc = ui_file_list_read_dir(flist, flist->dir);
     438        if (rc != EOK)
     439                return rc;
     440        ui_list_restore_pos(flist->list, &pos);
     441        return EOK;
     442}
     443
    424444/** Sort file list entries.
    425445 *
     
    593613                return ENOMEM;
    594614
    595         ui_file_list_clear_entries(flist);
    596 
    597615        rc = ui_file_list_read_dir(flist, dirname);
    598616        if (rc != EOK) {
  • uspace/lib/ui/src/list.c

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    16521652}
    16531653
     1654/** Save list position for later.
     1655 *
     1656 * The position will be valid even if the list is cleaned and re-populated
     1657 * (it just counts position from the top.)
     1658 *
     1659 * @param list UI list
     1660 * @param pos Place to store position
     1661 */
     1662void ui_list_save_pos(ui_list_t *list, ui_list_pos_t *pos)
     1663{
     1664        pos->page_idx = list->page_idx;
     1665        pos->cursor_idx = list->cursor_idx;
     1666}
     1667
     1668/** Restore saved list position.
     1669 *
     1670 * The position will be valid even if the list is cleaned and re-populated
     1671 * (it just counts position from the top.)
     1672 *
     1673 * @param list UI list
     1674 * @param pos Saved list position
     1675 */
     1676void ui_list_restore_pos(ui_list_t *list, ui_list_pos_t *pos)
     1677{
     1678        size_t idx, i;
     1679        ui_list_entry_t *entry, *next;
     1680
     1681        idx = 0;
     1682        entry = ui_list_first(list);
     1683
     1684        for (i = 0; i < pos->cursor_idx; i++) {
     1685                next = ui_list_next(entry);
     1686                if (next != NULL) {
     1687                        entry = next;
     1688                        ++idx;
     1689                }
     1690        }
     1691
     1692        list->cursor = entry;
     1693        list->cursor_idx = idx;
     1694
     1695        idx = 0;
     1696        entry = ui_list_first(list);
     1697
     1698        for (i = 0; i < pos->page_idx; i++) {
     1699                next = ui_list_next(entry);
     1700                if (next != NULL) {
     1701                        entry = next;
     1702                        ++idx;
     1703                }
     1704        }
     1705
     1706        list->page = entry;
     1707        list->page_idx = idx;
     1708}
     1709
    16541710/** @}
    16551711 */
  • uspace/lib/ui/src/msgdialog.c

    radbd7e1 raefdccd  
    285285        if (dialog->cb != NULL && dialog->cb->close != NULL)
    286286                dialog->cb->close(dialog, dialog->arg);
     287        else
     288                ui_msg_dialog_destroy(dialog);
    287289}
    288290
     
    310312                                dialog->cb->button(dialog, dialog->arg, 0);
    311313                                return;
     314                        } else {
     315                                ui_msg_dialog_destroy(dialog);
    312316                        }
    313317                } else if (event->key == KC_ESCAPE) {
     
    316320                                dialog->cb->close(dialog, dialog->arg);
    317321                                return;
     322                        } else {
     323                                ui_msg_dialog_destroy(dialog);
    318324                        }
    319325                }
     
    337343                                dialog->cb->button(dialog, dialog->arg, i);
    338344                }
     345        } else {
     346                ui_msg_dialog_destroy(dialog);
    339347        }
    340348}
  • uspace/lib/ui/src/ui.c

    radbd7e1 raefdccd  
    412412        errno_t rc;
    413413        gfx_context_t *gc;
    414         ui_window_t *awnd;
     414        ui_window_t *wnd;
    415415        gfx_color_t *color = NULL;
    416416
     
    439439        gfx_color_delete(color);
    440440
    441         /* XXX Should repaint all windows */
    442         awnd = ui_window_get_active(ui);
    443         if (awnd == NULL)
    444                 return EOK;
    445 
    446         rc = ui_wdecor_paint(awnd->wdecor);
    447         if (rc != EOK)
    448                 return rc;
    449 
    450         return ui_window_paint(awnd);
     441        /* Repaint all windows */
     442        wnd = ui_window_first(ui);
     443        while (wnd != NULL) {
     444                rc = ui_wdecor_paint(wnd->wdecor);
     445                if (rc != EOK)
     446                        return rc;
     447
     448                rc = ui_window_paint(wnd);
     449                if (rc != EOK)
     450                        return rc;
     451
     452                wnd = ui_window_next(wnd);
     453        }
     454
     455        return EOK;
    451456}
    452457
  • uspace/lib/ui/src/window.c

    radbd7e1 raefdccd  
    617617}
    618618
     619/** Get first (lowermost) window (only valid in fullscreen mode).
     620 *
     621 * @param ui User interface
     622 * @return First window
     623 */
     624ui_window_t *ui_window_first(ui_t *ui)
     625{
     626        link_t *link;
     627
     628        link = list_first(&ui->windows);
     629        if (link == NULL)
     630                return NULL;
     631
     632        return list_get_instance(link, ui_window_t, lwindows);
     633}
     634
     635/** Get next window (only valid in fullscreen mode).
     636 *
     637 * @param cur Current window
     638 * @return First window
     639 */
     640ui_window_t *ui_window_next(ui_window_t *cur)
     641{
     642        link_t *link;
     643
     644        link = list_next(&cur->lwindows, &cur->ui->windows);
     645        if (link == NULL)
     646                return NULL;
     647
     648        return list_get_instance(link, ui_window_t, lwindows);
     649}
     650
    619651/** Get active window (only valid in fullscreen mode).
    620652 *
  • uspace/lib/ui/test/filelist.c

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    665665}
    666666
     667/** ui_file_list_refresh() */
     668PCUT_TEST(refresh)
     669{
     670        ui_t *ui;
     671        ui_window_t *window;
     672        ui_wnd_params_t params;
     673        ui_file_list_t *flist;
     674        ui_file_list_entry_t *entry;
     675        char buf[L_tmpnam];
     676        char *fname;
     677        char *p;
     678        errno_t rc;
     679        FILE *f;
     680        int rv;
     681
     682        /* Create name for temporary directory */
     683        p = tmpnam(buf);
     684        PCUT_ASSERT_NOT_NULL(p);
     685
     686        /* Create temporary directory */
     687        rc = vfs_link_path(p, KIND_DIRECTORY, NULL);
     688        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     689
     690        rv = asprintf(&fname, "%s/%s", p, "a");
     691        PCUT_ASSERT_TRUE(rv >= 0);
     692
     693        f = fopen(fname, "wb");
     694        PCUT_ASSERT_NOT_NULL(f);
     695
     696        rv = fprintf(f, "X");
     697        PCUT_ASSERT_TRUE(rv >= 0);
     698
     699        rv = fclose(f);
     700        PCUT_ASSERT_INT_EQUALS(0, rv);
     701
     702        rc = ui_create_disp(NULL, &ui);
     703        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     704
     705        ui_wnd_params_init(&params);
     706        params.caption = "Test";
     707
     708        rc = ui_window_create(ui, &params, &window);
     709        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     710
     711        rc = ui_file_list_create(window, true, &flist);
     712        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     713
     714        rc = ui_file_list_read_dir(flist, p);
     715        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     716
     717        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
     718
     719        entry = ui_file_list_first(flist);
     720        PCUT_ASSERT_NOT_NULL(entry);
     721        PCUT_ASSERT_STR_EQUALS("..", entry->name);
     722
     723        entry = ui_file_list_next(entry);
     724        PCUT_ASSERT_NOT_NULL(entry);
     725        PCUT_ASSERT_STR_EQUALS("a", entry->name);
     726        PCUT_ASSERT_INT_EQUALS(1, entry->size);
     727
     728        rv = remove(fname);
     729        PCUT_ASSERT_INT_EQUALS(0, rv);
     730        free(fname);
     731
     732        rv = asprintf(&fname, "%s/%s", p, "b");
     733        PCUT_ASSERT_TRUE(rv >= 0);
     734
     735        f = fopen(fname, "wb");
     736        PCUT_ASSERT_NOT_NULL(f);
     737
     738        rv = fprintf(f, "X");
     739        PCUT_ASSERT_TRUE(rv >= 0);
     740
     741        rv = fclose(f);
     742        PCUT_ASSERT_INT_EQUALS(0, rv);
     743
     744        rc = ui_file_list_refresh(flist);
     745        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     746
     747        entry = ui_file_list_first(flist);
     748        PCUT_ASSERT_NOT_NULL(entry);
     749        PCUT_ASSERT_STR_EQUALS("..", entry->name);
     750
     751        entry = ui_file_list_next(entry);
     752        PCUT_ASSERT_NOT_NULL(entry);
     753        PCUT_ASSERT_STR_EQUALS("b", entry->name);
     754        PCUT_ASSERT_INT_EQUALS(1, entry->size);
     755
     756        rv = remove(fname);
     757        PCUT_ASSERT_INT_EQUALS(0, rv);
     758        free(fname);
     759
     760        rv = remove(p);
     761        PCUT_ASSERT_INT_EQUALS(0, rv);
     762
     763        ui_file_list_destroy(flist);
     764
     765        ui_window_destroy(window);
     766        ui_destroy(ui);
     767}
     768
    667769/** ui_file_list_list_compare compares two file list entries */
    668770PCUT_TEST(list_compare)
  • uspace/lib/ui/test/list.c

    radbd7e1 raefdccd  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    30643064}
    30653065
     3066/** ui_list_save_pos() / ui_list_restore_pos() saves/restores position */
     3067PCUT_TEST(save_pos_restore_pos)
     3068{
     3069        ui_t *ui;
     3070        ui_window_t *window;
     3071        ui_wnd_params_t params;
     3072        ui_list_t *list;
     3073        ui_list_entry_t *a, *b;
     3074        ui_list_entry_attr_t attr;
     3075        ui_list_pos_t pos;
     3076        test_resp_t resp;
     3077        errno_t rc;
     3078
     3079        rc = ui_create_disp(NULL, &ui);
     3080        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3081
     3082        ui_wnd_params_init(&params);
     3083        params.caption = "Test";
     3084
     3085        rc = ui_window_create(ui, &params, &window);
     3086        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3087
     3088        rc = ui_list_create(window, true, &list);
     3089        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3090
     3091        ui_list_set_cb(list, &test_cb, &resp);
     3092
     3093        ui_list_entry_attr_init(&attr);
     3094
     3095        attr.caption = "a";
     3096        attr.arg = (void *)2;
     3097        rc = ui_list_entry_append(list, &attr, &a);
     3098        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3099
     3100        attr.caption = "b";
     3101        attr.arg = (void *)1;
     3102        rc = ui_list_entry_append(list, &attr, &b);
     3103        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3104
     3105        ui_list_set_cursor(list, b);
     3106
     3107        ui_list_save_pos(list, &pos);
     3108
     3109        /* Empty and re-build list. */
     3110
     3111        ui_list_entry_destroy(a);
     3112        ui_list_entry_destroy(b);
     3113
     3114        ui_list_entry_attr_init(&attr);
     3115
     3116        attr.caption = "a";
     3117        attr.arg = (void *)2;
     3118        rc = ui_list_entry_append(list, &attr, &a);
     3119        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3120
     3121        attr.caption = "b";
     3122        attr.arg = (void *)1;
     3123        rc = ui_list_entry_append(list, &attr, &b);
     3124        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     3125
     3126        ui_list_restore_pos(list, &pos);
     3127
     3128        PCUT_ASSERT_STR_EQUALS("b", list->cursor->caption);
     3129
     3130        ui_list_destroy(list);
     3131        ui_window_destroy(window);
     3132        ui_destroy(ui);
     3133}
     3134
    30663135static void test_list_activate_req(ui_list_t *list, void *arg)
    30673136{
Note: See TracChangeset for help on using the changeset viewer.