Changeset 6186f9f in mainline


Ignore:
Timestamp:
2021-04-13T17:20:20Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f3a7b0d
Parents:
b8b64a8
Message:

Add menu separator entry

Location:
uspace
Files:
5 edited

Legend:

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

    rb8b64a8 r6186f9f  
    287287        }
    288288
     289        rc = ui_menu_entry_sep_create(demo.mfile, &mexit);
     290        if (rc != EOK) {
     291                printf("Error creating menu.\n");
     292                return rc;
     293        }
     294
    289295        rc = ui_menu_entry_create(demo.mfile, "Exit", "Alt-F4", &mexit);
    290296        if (rc != EOK) {
  • uspace/lib/ui/include/ui/menuentry.h

    rb8b64a8 r6186f9f  
    4545extern errno_t ui_menu_entry_create(ui_menu_t *, const char *, const char *,
    4646    ui_menu_entry_t **);
     47extern errno_t ui_menu_entry_sep_create(ui_menu_t *, ui_menu_entry_t **);
    4748extern void ui_menu_entry_destroy(ui_menu_entry_t *);
    4849extern void ui_menu_entry_set_cb(ui_menu_entry_t *, ui_menu_entry_cb_t,
  • uspace/lib/ui/private/menuentry.h

    rb8b64a8 r6186f9f  
    5353        /** Callbacks */
    5454        ui_menu_entry_cb_t cb;
     55        /** This entry is a separator entry */
     56        bool separator;
    5557        /** Menu entry is currently held down */
    5658        bool held;
  • uspace/lib/ui/src/menuentry.c

    rb8b64a8 r6186f9f  
    5555        menu_entry_vpad = 4,
    5656        menu_entry_column_pad = 8,
     57        menu_entry_sep_height = 2,
    5758        menu_entry_hpad_text = 1,
    5859        menu_entry_vpad_text = 0,
    59         menu_entry_column_pad_text = 2
     60        menu_entry_column_pad_text = 2,
     61        menu_entry_sep_height_text = 1
    6062};
    6163
     
    107109}
    108110
     111/** Create new separator menu entry.
     112 *
     113 * @param menu Menu
     114 * @param rmentry Place to store pointer to new menu entry
     115 * @return EOK on success, ENOMEM if out of memory
     116 */
     117errno_t ui_menu_entry_sep_create(ui_menu_t *menu, ui_menu_entry_t **rmentry)
     118{
     119        ui_menu_entry_t *mentry;
     120        errno_t rc;
     121
     122        rc = ui_menu_entry_create(menu, "", "", &mentry);
     123        if (rc != EOK)
     124                return rc;
     125
     126        /* Need to adjust menu height when changing to separator */
     127        menu->total_h -= ui_menu_entry_height(mentry);
     128        mentry->separator = true;
     129        menu->total_h += ui_menu_entry_height(mentry);
     130
     131        *rmentry = mentry;
     132        return EOK;
     133}
     134
    109135/** Destroy menu entry.
    110136 *
     
    238264        }
    239265
    240         gfx_font_get_metrics(res->font, &metrics);
    241         height = metrics.ascent + metrics.descent + 1;
     266        if (mentry->separator) {
     267                /* Separator menu entry */
     268                if (res->textmode)
     269                        height = menu_entry_sep_height_text;
     270                else
     271                        height = menu_entry_sep_height;
     272        } else {
     273                /* Normal menu entry */
     274                gfx_font_get_metrics(res->font, &metrics);
     275                height = metrics.ascent + metrics.descent + 1;
     276        }
     277
    242278        return height + 2 * vpad;
    243279}
     
    255291        gfx_color_t *bg_color;
    256292        ui_menu_entry_geom_t geom;
     293        gfx_rect_t rect;
    257294        errno_t rc;
    258295
     
    292329                goto error;
    293330
     331        if (mentry->separator) {
     332                rect.p0 = geom.caption_pos;
     333                rect.p1.x = geom.shortcut_pos.x;
     334                rect.p1.y = rect.p0.y + 2;
     335                rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color,
     336                    res->wnd_highlight_color, 1, NULL);
     337                if (rc != EOK)
     338                        goto error;
     339        }
     340
    294341        rc = gfx_update(res->gc);
    295342        if (rc != EOK)
     
    309356{
    310357        if (mentry->held)
     358                return;
     359
     360        if (mentry->separator)
    311361                return;
    312362
  • uspace/lib/ui/test/menuentry.c

    rb8b64a8 r6186f9f  
    5151static void test_entry_cb(ui_menu_entry_t *, void *);
    5252
    53 /** Create and destroy menu bar */
     53/** Create and destroy menu entry */
    5454PCUT_TEST(create_destroy)
    5555{
    56         ui_menu_bar_t *mbar = NULL;
    57         errno_t rc;
    58 
    59         rc = ui_menu_bar_create(NULL, &mbar);
    60         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    61         PCUT_ASSERT_NOT_NULL(mbar);
    62 
    63         ui_menu_bar_destroy(mbar);
     56        dummy_gc_t *dgc;
     57        gfx_context_t *gc;
     58        ui_resource_t *resource = NULL;
     59        ui_menu_bar_t *mbar = NULL;
     60        ui_menu_t *menu = NULL;
     61        ui_menu_entry_t *mentry = NULL;
     62        errno_t rc;
     63
     64        rc = dummygc_create(&dgc);
     65        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     66
     67        gc = dummygc_get_ctx(dgc);
     68
     69        rc = ui_resource_create(gc, false, &resource);
     70        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     71        PCUT_ASSERT_NOT_NULL(resource);
     72
     73        rc = ui_menu_bar_create(resource, &mbar);
     74        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     75        PCUT_ASSERT_NOT_NULL(mbar);
     76
     77        rc = ui_menu_create(mbar, "Test", &menu);
     78        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     79        PCUT_ASSERT_NOT_NULL(menu);
     80
     81        rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry);
     82        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     83        PCUT_ASSERT_NOT_NULL(mentry);
     84
     85        /* Just for sake of test. Menu entry is destroyed along with menu */
     86        ui_menu_entry_destroy(mentry);
     87
     88        ui_menu_bar_destroy(mbar);
     89        dummygc_destroy(dgc);
     90}
     91
     92/** Create and destroy separator menu entry */
     93PCUT_TEST(create_sep_destroy)
     94{
     95        dummy_gc_t *dgc;
     96        gfx_context_t *gc;
     97        ui_resource_t *resource = NULL;
     98        ui_menu_bar_t *mbar = NULL;
     99        ui_menu_t *menu = NULL;
     100        ui_menu_entry_t *mentry = NULL;
     101        errno_t rc;
     102
     103        rc = dummygc_create(&dgc);
     104        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     105
     106        gc = dummygc_get_ctx(dgc);
     107
     108        rc = ui_resource_create(gc, false, &resource);
     109        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     110        PCUT_ASSERT_NOT_NULL(resource);
     111
     112        rc = ui_menu_bar_create(resource, &mbar);
     113        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     114        PCUT_ASSERT_NOT_NULL(mbar);
     115
     116        rc = ui_menu_create(mbar, "Test", &menu);
     117        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     118        PCUT_ASSERT_NOT_NULL(menu);
     119
     120        rc = ui_menu_entry_sep_create(menu, &mentry);
     121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     122        PCUT_ASSERT_NOT_NULL(mentry);
     123
     124        /* Just for sake of test. Menu entry is destroyed along with menu */
     125        ui_menu_entry_destroy(mentry);
     126
     127        ui_menu_bar_destroy(mbar);
     128        dummygc_destroy(dgc);
    64129}
    65130
Note: See TracChangeset for help on using the changeset viewer.