Changeset 6186f9f in mainline
- Timestamp:
- 2021-04-13T17:20:20Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f3a7b0d
- Parents:
- b8b64a8
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rb8b64a8 r6186f9f 287 287 } 288 288 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 289 295 rc = ui_menu_entry_create(demo.mfile, "Exit", "Alt-F4", &mexit); 290 296 if (rc != EOK) { -
uspace/lib/ui/include/ui/menuentry.h
rb8b64a8 r6186f9f 45 45 extern errno_t ui_menu_entry_create(ui_menu_t *, const char *, const char *, 46 46 ui_menu_entry_t **); 47 extern errno_t ui_menu_entry_sep_create(ui_menu_t *, ui_menu_entry_t **); 47 48 extern void ui_menu_entry_destroy(ui_menu_entry_t *); 48 49 extern void ui_menu_entry_set_cb(ui_menu_entry_t *, ui_menu_entry_cb_t, -
uspace/lib/ui/private/menuentry.h
rb8b64a8 r6186f9f 53 53 /** Callbacks */ 54 54 ui_menu_entry_cb_t cb; 55 /** This entry is a separator entry */ 56 bool separator; 55 57 /** Menu entry is currently held down */ 56 58 bool held; -
uspace/lib/ui/src/menuentry.c
rb8b64a8 r6186f9f 55 55 menu_entry_vpad = 4, 56 56 menu_entry_column_pad = 8, 57 menu_entry_sep_height = 2, 57 58 menu_entry_hpad_text = 1, 58 59 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 60 62 }; 61 63 … … 107 109 } 108 110 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 */ 117 errno_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 109 135 /** Destroy menu entry. 110 136 * … … 238 264 } 239 265 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 242 278 return height + 2 * vpad; 243 279 } … … 255 291 gfx_color_t *bg_color; 256 292 ui_menu_entry_geom_t geom; 293 gfx_rect_t rect; 257 294 errno_t rc; 258 295 … … 292 329 goto error; 293 330 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 294 341 rc = gfx_update(res->gc); 295 342 if (rc != EOK) … … 309 356 { 310 357 if (mentry->held) 358 return; 359 360 if (mentry->separator) 311 361 return; 312 362 -
uspace/lib/ui/test/menuentry.c
rb8b64a8 r6186f9f 51 51 static void test_entry_cb(ui_menu_entry_t *, void *); 52 52 53 /** Create and destroy menu bar*/53 /** Create and destroy menu entry */ 54 54 PCUT_TEST(create_destroy) 55 55 { 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 */ 93 PCUT_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); 64 129 } 65 130
Note:
See TracChangeset
for help on using the changeset viewer.