Changeset f2cb80a in mainline for uspace/lib/ui


Ignore:
Timestamp:
2024-02-23T17:57:23Z (2 years ago)
Author:
GitHub <noreply@…>
Children:
192019f
Parents:
86f862c (diff), 90ba06c (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@…> (2024-02-23 17:57:23)
git-committer:
GitHub <noreply@…> (2024-02-23 17:57:23)
Message:

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

Location:
uspace/lib/ui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/include/ui/checkbox.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5252extern void ui_checkbox_set_cb(ui_checkbox_t *, ui_checkbox_cb_t *, void *);
    5353extern void ui_checkbox_set_rect(ui_checkbox_t *, gfx_rect_t *);
     54extern bool ui_checkbox_get_checked(ui_checkbox_t *);
     55extern void ui_checkbox_set_checked(ui_checkbox_t *, bool);
    5456extern errno_t ui_checkbox_paint(ui_checkbox_t *);
    5557extern void ui_checkbox_press(ui_checkbox_t *);
  • uspace/lib/ui/include/ui/list.h

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5757extern errno_t ui_list_entry_append(ui_list_t *,
    5858    ui_list_entry_attr_t *, ui_list_entry_t **);
     59extern void ui_list_entry_move_up(ui_list_entry_t *);
     60extern void ui_list_entry_move_down(ui_list_entry_t *);
    5961extern void ui_list_entry_delete(ui_list_entry_t *);
    6062extern void *ui_list_entry_get_arg(ui_list_entry_t *);
  • uspace/lib/ui/src/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    139139}
    140140
    141 /** Set button rectangle.
    142  *
    143  * @param checkbox Button
    144  * @param rect New button rectangle
     141/** Set check box rectangle.
     142 *
     143 * @param checkbox Check box
     144 * @param rect New check box rectangle
    145145 */
    146146void ui_checkbox_set_rect(ui_checkbox_t *checkbox, gfx_rect_t *rect)
    147147{
    148148        checkbox->rect = *rect;
     149}
     150
     151/** Return if check box is checked.
     152 *
     153 * @param checkbox Check box
     154 * @return @c true iff check box is checked
     155 */
     156bool ui_checkbox_get_checked(ui_checkbox_t *checkbox)
     157{
     158        return checkbox->checked;
     159}
     160
     161/** Set check box checked state.
     162 *
     163 * @param checkbox Check box
     164 * @param checked @c true iff checkbox should be checked
     165 */
     166void ui_checkbox_set_checked(ui_checkbox_t *checkbox, bool checked)
     167{
     168        checkbox->checked = checked;
    149169}
    150170
  • uspace/lib/ui/src/list.c

    r86f862c rf2cb80a  
    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 *
  • uspace/lib/ui/test/checkbox.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    151151}
    152152
     153/** Get check box checked returns internal field */
     154PCUT_TEST(get_checked)
     155{
     156        ui_checkbox_t *checkbox;
     157        errno_t rc;
     158
     159        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     160        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     161
     162        checkbox->checked = false;
     163        PCUT_ASSERT_FALSE(ui_checkbox_get_checked(checkbox));
     164        checkbox->checked = true;
     165        PCUT_ASSERT_TRUE(ui_checkbox_get_checked(checkbox));
     166
     167        ui_checkbox_destroy(checkbox);
     168}
     169
     170/** Set check box checked sets internal field */
     171PCUT_TEST(set_checked)
     172{
     173        ui_checkbox_t *checkbox;
     174        errno_t rc;
     175
     176        rc = ui_checkbox_create(NULL, "Hello", &checkbox);
     177        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     178
     179        ui_checkbox_set_checked(checkbox, true);
     180        PCUT_ASSERT_TRUE(checkbox->checked);
     181        ui_checkbox_set_checked(checkbox, false);
     182        PCUT_ASSERT_FALSE(checkbox->checked);
     183
     184        ui_checkbox_destroy(checkbox);
     185}
     186
    153187/** Paint check box in graphics mode */
    154188PCUT_TEST(paint_gfx)
  • uspace/lib/ui/test/list.c

    r86f862c rf2cb80a  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    904904}
    905905
     906/** ui_list_entry_move_up() moves entry up */
     907PCUT_TEST(entry_move_up)
     908{
     909        ui_t *ui;
     910        ui_window_t *window;
     911        ui_wnd_params_t params;
     912        ui_list_t *list;
     913        ui_list_entry_attr_t attr;
     914        ui_list_entry_t *e1, *e2, *e3;
     915        ui_list_entry_t *e;
     916        errno_t rc;
     917
     918        rc = ui_create_disp(NULL, &ui);
     919        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     920
     921        ui_wnd_params_init(&params);
     922        params.caption = "Test";
     923
     924        rc = ui_window_create(ui, &params, &window);
     925        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     926
     927        rc = ui_list_create(window, true, &list);
     928        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     929
     930        ui_list_entry_attr_init(&attr);
     931
     932        /* Create entries */
     933
     934        attr.caption = "a";
     935        attr.arg = (void *)1;
     936        rc = ui_list_entry_append(list, &attr, &e1);
     937        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     938
     939        attr.caption = "b";
     940        attr.arg = (void *)2;
     941        rc = ui_list_entry_append(list, &attr, &e2);
     942        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     943
     944        attr.caption = "c";
     945        attr.arg = (void *)3;
     946        rc = ui_list_entry_append(list, &attr, &e3);
     947        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     948
     949        e = ui_list_first(list);
     950        PCUT_ASSERT_EQUALS(e1, e);
     951
     952        /* Moving first entry up should have no effect */
     953        ui_list_entry_move_up(e1);
     954
     955        e = ui_list_first(list);
     956        PCUT_ASSERT_EQUALS(e1, e);
     957
     958        e = ui_list_next(e);
     959        PCUT_ASSERT_EQUALS(e2, e);
     960
     961        e = ui_list_next(e);
     962        PCUT_ASSERT_EQUALS(e3, e);
     963
     964        e = ui_list_next(e);
     965        PCUT_ASSERT_NULL(e);
     966
     967        /* Move second entry up */
     968        ui_list_entry_move_up(e2);
     969
     970        e = ui_list_first(list);
     971        PCUT_ASSERT_EQUALS(e2, e);
     972
     973        e = ui_list_next(e);
     974        PCUT_ASSERT_EQUALS(e1, e);
     975
     976        e = ui_list_next(e);
     977        PCUT_ASSERT_EQUALS(e3, e);
     978
     979        e = ui_list_next(e);
     980        PCUT_ASSERT_NULL(e);
     981
     982        ui_list_destroy(list);
     983        ui_window_destroy(window);
     984        ui_destroy(ui);
     985}
     986
     987/** ui_list_entry_move_down() moves entry down */
     988PCUT_TEST(entry_move_down)
     989{
     990        ui_t *ui;
     991        ui_window_t *window;
     992        ui_wnd_params_t params;
     993        ui_list_t *list;
     994        ui_list_entry_attr_t attr;
     995        ui_list_entry_t *e1, *e2, *e3;
     996        ui_list_entry_t *e;
     997        errno_t rc;
     998
     999        rc = ui_create_disp(NULL, &ui);
     1000        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1001
     1002        ui_wnd_params_init(&params);
     1003        params.caption = "Test";
     1004
     1005        rc = ui_window_create(ui, &params, &window);
     1006        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1007
     1008        rc = ui_list_create(window, true, &list);
     1009        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1010
     1011        ui_list_entry_attr_init(&attr);
     1012
     1013        /* Create entries */
     1014
     1015        attr.caption = "a";
     1016        attr.arg = (void *)1;
     1017        rc = ui_list_entry_append(list, &attr, &e1);
     1018        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1019
     1020        attr.caption = "b";
     1021        attr.arg = (void *)2;
     1022        rc = ui_list_entry_append(list, &attr, &e2);
     1023        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1024
     1025        attr.caption = "c";
     1026        attr.arg = (void *)3;
     1027        rc = ui_list_entry_append(list, &attr, &e3);
     1028        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1029
     1030        e = ui_list_first(list);
     1031        PCUT_ASSERT_EQUALS(e1, e);
     1032
     1033        /* Moving last entry down should have no effect */
     1034        ui_list_entry_move_down(e3);
     1035
     1036        e = ui_list_first(list);
     1037        PCUT_ASSERT_EQUALS(e1, e);
     1038
     1039        e = ui_list_next(e);
     1040        PCUT_ASSERT_EQUALS(e2, e);
     1041
     1042        e = ui_list_next(e);
     1043        PCUT_ASSERT_EQUALS(e3, e);
     1044
     1045        e = ui_list_next(e);
     1046        PCUT_ASSERT_NULL(e);
     1047
     1048        /* Move second-to-last entry down */
     1049        ui_list_entry_move_down(e2);
     1050
     1051        e = ui_list_first(list);
     1052        PCUT_ASSERT_EQUALS(e1, e);
     1053
     1054        e = ui_list_next(e);
     1055        PCUT_ASSERT_EQUALS(e3, e);
     1056
     1057        e = ui_list_next(e);
     1058        PCUT_ASSERT_EQUALS(e2, e);
     1059
     1060        e = ui_list_next(e);
     1061        PCUT_ASSERT_NULL(e);
     1062
     1063        ui_list_destroy(list);
     1064        ui_window_destroy(window);
     1065        ui_destroy(ui);
     1066}
     1067
    9061068/** ui_list_entry_delete() deletes entry */
    9071069PCUT_TEST(entry_delete)
Note: See TracChangeset for help on using the changeset viewer.