Changeset 112f70a in mainline


Ignore:
Timestamp:
2023-09-14T09:53:27Z (13 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8a6ebbb
Parents:
61643c8
git-author:
Jiri Svoboda <jiri@…> (2023-09-13 18:53:09)
git-committer:
Jiri Svoboda <jiri@…> (2023-09-14 09:53:27)
Message:

Allow menu entries to be disabled

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/uidemo/uidemo.c

    r61643c8 r112f70a  
    805805        }
    806806
     807        ui_menu_entry_set_disabled(mfoobar, true);
     808
    807809        rc = ui_menu_entry_sep_create(demo.mfile, &msep);
    808810        if (rc != EOK) {
  • uspace/lib/ui/include/ui/menuentry.h

    r61643c8 r112f70a  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5151extern void ui_menu_entry_set_cb(ui_menu_entry_t *, ui_menu_entry_cb_t,
    5252    void *);
     53extern void ui_menu_entry_set_disabled(ui_menu_entry_t *, bool);
     54extern bool ui_menu_entry_is_disabled(ui_menu_entry_t *);
    5355extern ui_menu_entry_t *ui_menu_entry_first(ui_menu_t *);
    5456extern ui_menu_entry_t *ui_menu_entry_last(ui_menu_t *);
  • uspace/lib/ui/private/menuentry.h

    r61643c8 r112f70a  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5353        /** Callbacks */
    5454        ui_menu_entry_cb_t cb;
     55        /** This entry is disabled */
     56        bool disabled;
    5557        /** This entry is a separator entry */
    5658        bool separator;
  • uspace/lib/ui/private/resource.h

    r61643c8 r112f70a  
    7979        /** Window text color */
    8080        gfx_color_t *wnd_text_color;
     81        /** Disabled text color */
     82        gfx_color_t *wnd_dis_text_color;
    8183        /** Window text highlight color */
    8284        gfx_color_t *wnd_text_hgl_color;
  • uspace/lib/ui/src/menu.c

    r61643c8 r112f70a  
    534534                break;
    535535        case KC_ENTER:
    536                 if (menu->selected != NULL)
     536                if (menu->selected != NULL &&
     537                    !ui_menu_entry_is_disabled(menu->selected))
    537538                        ui_menu_entry_activate(menu->selected);
    538539                break;
     
    543544                                c = ui_menu_entry_get_accel(mentry);
    544545                                if (c == (char32_t)tolower(event->c) &&
    545                                     menu->selected != NULL) {
     546                                    !ui_menu_entry_is_disabled(mentry)) {
    546547                                        ui_menu_entry_activate(mentry);
    547548                                        break;
  • uspace/lib/ui/src/menuentry.c

    r61643c8 r112f70a  
    163163}
    164164
     165/** Set menu entry disabled flag.
     166 *
     167 * @param mentry Menu entry
     168 * @param disabled @c true iff entry is to be disabled, @c false otherwise
     169 */
     170void ui_menu_entry_set_disabled(ui_menu_entry_t *mentry, bool disabled)
     171{
     172        mentry->disabled = disabled;
     173}
     174
     175/** Get menu entry disabled flag.
     176 *
     177 * @param mentry Menu entry
     178 * @return disabled @c true iff entry is disabled, @c false otherwise
     179 */
     180bool ui_menu_entry_is_disabled(ui_menu_entry_t *mentry)
     181{
     182        return mentry->disabled;
     183}
     184
    165185/** Get first menu entry in menu.
    166186 *
     
    372392                fmt.hgl_color = res->wnd_sel_text_hgl_color;
    373393                bg_color = res->wnd_sel_text_bg_color;
     394        } else if (mentry->disabled) {
     395                fmt.color = res->wnd_dis_text_color;
     396                fmt.hgl_color = res->wnd_dis_text_color;
     397                bg_color = res->wnd_face_color;
    374398        } else {
    375399                fmt.color = res->wnd_text_color;
  • uspace/lib/ui/src/resource.c

    r61643c8 r112f70a  
    6868        gfx_color_t *wnd_face_color = NULL;
    6969        gfx_color_t *wnd_text_color = NULL;
     70        gfx_color_t *wnd_dis_text_color = NULL;
    7071        gfx_color_t *wnd_text_hgl_color = NULL;
    7172        gfx_color_t *wnd_sel_text_color = NULL;
     
    140141                goto error;
    141142
     143        rc = gfx_color_new_rgb_i16(0x9696, 0x9696, 0x9696, &wnd_dis_text_color);
     144        if (rc != EOK)
     145                goto error;
     146
    142147        rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_hgl_color);
    143148        if (rc != EOK)
     
    239244        resource->wnd_face_color = wnd_face_color;
    240245        resource->wnd_text_color = wnd_text_color;
     246        resource->wnd_dis_text_color = wnd_dis_text_color;
    241247        resource->wnd_text_hgl_color = wnd_text_hgl_color;
    242248        resource->wnd_sel_text_color = wnd_sel_text_color;
     
    282288        if (wnd_text_color != NULL)
    283289                gfx_color_delete(wnd_text_color);
     290        if (wnd_dis_text_color != NULL)
     291                gfx_color_delete(wnd_dis_text_color);
    284292        if (wnd_text_hgl_color != NULL)
    285293                gfx_color_delete(wnd_text_hgl_color);
     
    350358        gfx_color_t *wnd_face_color = NULL;
    351359        gfx_color_t *wnd_text_color = NULL;
     360        gfx_color_t *wnd_dis_text_color = NULL;
    352361        gfx_color_t *wnd_text_hgl_color = NULL;
    353362        gfx_color_t *wnd_sel_text_color = NULL;
     
    416425                goto error;
    417426
     427        rc = gfx_color_new_ega(0x78, &wnd_dis_text_color);
     428        if (rc != EOK)
     429                goto error;
     430
    418431        rc = gfx_color_new_ega(0x74, &wnd_text_hgl_color);
    419432        if (rc != EOK)
     
    506519        resource->wnd_face_color = wnd_face_color;
    507520        resource->wnd_text_color = wnd_text_color;
     521        resource->wnd_dis_text_color = wnd_dis_text_color;
    508522        resource->wnd_text_hgl_color = wnd_text_hgl_color;
    509523        resource->wnd_sel_text_color = wnd_sel_text_color;
     
    549563        if (wnd_text_color != NULL)
    550564                gfx_color_delete(wnd_text_color);
     565        if (wnd_dis_text_color != NULL)
     566                gfx_color_delete(wnd_dis_text_color);
    551567        if (wnd_text_hgl_color != NULL)
    552568                gfx_color_delete(wnd_text_hgl_color);
     
    630646        gfx_color_delete(resource->wnd_face_color);
    631647        gfx_color_delete(resource->wnd_text_color);
     648        gfx_color_delete(resource->wnd_dis_text_color);
    632649        gfx_color_delete(resource->wnd_sel_text_color);
    633650        gfx_color_delete(resource->wnd_sel_text_bg_color);
Note: See TracChangeset for help on using the changeset viewer.