Changeset 96c6a00 in mainline
- Timestamp:
- 2022-03-10T13:44:10Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c88d7f99
- Parents:
- ca2680d
- git-author:
- Jiri Svoboda <jiri@…> (2022-03-09 18:44:00)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-03-10 13:44:10)
- Location:
- uspace
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/calculator/calculator.c
rca2680d r96c6a00 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * Copyright (c) 2016 Martin Decky 4 4 * All rights reserved. … … 896 896 } 897 897 898 rc = ui_menu_create(calc.menubar, " File", &mfile);898 rc = ui_menu_create(calc.menubar, "~F~ile", &mfile); 899 899 if (rc != EOK) { 900 900 printf("Error creating menu.\n"); … … 910 910 ui_menu_entry_set_cb(mexit, calc_file_exit, (void *) &calc); 911 911 912 rc = ui_menu_create(calc.menubar, " Edit", &medit);912 rc = ui_menu_create(calc.menubar, "~E~dit", &medit); 913 913 if (rc != EOK) { 914 914 printf("Error creating menu.\n"); -
uspace/app/edit/edit.c
rca2680d r96c6a00 430 430 } 431 431 432 rc = ui_menu_create(edit->menubar, " File", &mfile);432 rc = ui_menu_create(edit->menubar, "~F~ile", &mfile); 433 433 if (rc != EOK) { 434 434 printf("Error creating menu.\n"); … … 466 466 ui_menu_entry_set_cb(mexit, edit_file_exit, (void *) edit); 467 467 468 rc = ui_menu_create(edit->menubar, " Edit", &medit);468 rc = ui_menu_create(edit->menubar, "~E~dit", &medit); 469 469 if (rc != EOK) { 470 470 printf("Error creating menu.\n"); … … 518 518 ui_menu_entry_set_cb(mselall, edit_edit_select_all, (void *) edit); 519 519 520 rc = ui_menu_create(edit->menubar, " Search", &msearch);520 rc = ui_menu_create(edit->menubar, "~S~earch", &msearch); 521 521 if (rc != EOK) { 522 522 printf("Error creating menu.\n"); -
uspace/app/nav/menu.c
rca2680d r96c6a00 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 72 72 goto error; 73 73 74 rc = ui_menu_create(menu->menubar, " File", &mfile);74 rc = ui_menu_create(menu->menubar, "~F~ile", &mfile); 75 75 if (rc != EOK) 76 76 goto error; -
uspace/lib/ui/include/ui/menu.h
rca2680d r96c6a00 45 45 #include <types/ui/menubar.h> 46 46 #include <types/ui/event.h> 47 #include <uchar.h> 47 48 48 49 extern errno_t ui_menu_create(ui_menu_bar_t *, const char *, ui_menu_t **); … … 54 55 extern const char *ui_menu_caption(ui_menu_t *); 55 56 extern void ui_menu_get_rect(ui_menu_t *, gfx_coord2_t *, gfx_rect_t *); 57 extern char32_t ui_menu_get_accel(ui_menu_t *); 56 58 extern errno_t ui_menu_open(ui_menu_t *, gfx_rect_t *); 57 59 extern void ui_menu_close(ui_menu_t *); -
uspace/lib/ui/meson.build
rca2680d r96c6a00 29 29 deps = [ 'gfx', 'gfxfont', 'memgfx', 'display', 'congfx' ] 30 30 src = files( 31 'src/accel.c', 31 32 'src/checkbox.c', 32 33 'src/control.c', … … 54 55 55 56 test_src = files( 57 'test/accel.c', 56 58 'test/checkbox.c', 57 59 'test/control.c', -
uspace/lib/ui/src/menu.c
rca2680d r96c6a00 43 43 #include <stdlib.h> 44 44 #include <str.h> 45 #include <uchar.h> 46 #include <ui/accel.h> 45 47 #include <ui/control.h> 46 48 #include <ui/paint.h> … … 251 253 ui_menu_get_geom(menu, spos, &geom); 252 254 *rect = geom.outer_rect; 255 } 256 257 /** Get menu accelerator character. 258 * 259 * @param menu Menu 260 * @return Accelerator character (lowercase) or the null character if 261 * the menu has no accelerator. 262 */ 263 char32_t ui_menu_get_accel(ui_menu_t *menu) 264 { 265 return ui_accel_get(menu->caption); 253 266 } 254 267 -
uspace/lib/ui/src/menubar.c
rca2680d r96c6a00 252 252 old_menu = mbar->selected; 253 253 254 if (mbar->selected != menu) 255 mbar->selected = menu; 256 else 257 mbar->selected = NULL; 254 mbar->selected = menu; 258 255 259 256 /* Close previously open menu */ … … 333 330 { 334 331 gfx_rect_t rect; 332 ui_menu_t *menu; 333 char32_t maccel; 335 334 336 335 if (event->key == KC_F10) { … … 361 360 362 361 return ui_claimed; 362 } 363 364 if (event->c != '\0' && !ui_menu_is_open(mbar->selected)) { 365 /* Check if it is an accelerator. */ 366 367 menu = ui_menu_first(mbar); 368 while (menu != NULL) { 369 maccel = ui_menu_get_accel(menu); 370 if (event->c == maccel) { 371 ui_menu_bar_select(mbar, menu, true); 372 return ui_claimed; 373 } 374 375 menu = ui_menu_next(menu); 376 } 363 377 } 364 378 … … 428 442 gfx_pix_inside_rect(&ppos, &rect)) { 429 443 mbar->active = true; 430 ui_menu_bar_select(mbar, menu, true); 444 445 /* Open the menu, close if already open. */ 446 if (menu == mbar->selected) 447 ui_menu_bar_select(mbar, NULL, false); 448 else 449 ui_menu_bar_select(mbar, menu, true); 450 431 451 return ui_claimed; 432 452 } -
uspace/lib/ui/src/paint.c
rca2680d r96c6a00 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <gfx/render.h> 40 40 #include <gfx/text.h> 41 #include <ui/accel.h> 41 42 #include <ui/paint.h> 42 43 #include <stdlib.h> … … 566 567 } 567 568 568 /** Process text with '~' markup.569 *570 * Parse text with tilde markup into a list of strings. @a *rbuf is set571 * to point to a newly allocated buffer containing consecutive null-terminated572 * strings.573 *574 * Each part between two '~' becomes one string. '~~' is translated into575 * a literal '~' character. @a *endptr is set to point to the first character576 * beyond the end of the list.577 *578 * @param str String with tilde markup579 * @param rbuf Place to store pointer to newly allocated buffer.580 * @param endptr Place to store end pointer (just after last character)581 * @return EOK on success or an error code582 */583 static int ui_text_process(const char *str, char **rbuf, char **endptr)584 {585 const char *sp;586 char *dp;587 char *buf;588 589 buf = malloc(str_size(str) + 1);590 if (buf == NULL)591 return ENOMEM;592 593 /* Break down string into list of (non)highlighted parts */594 sp = str;595 dp = buf;596 while (*sp != '\0') {597 if (*sp == '~') {598 if (sp[1] == '~') {599 sp += 2;600 *dp++ = '~';601 } else {602 ++sp;603 *dp++ = '\0';604 }605 } else {606 *dp++ = *sp++;607 }608 }609 610 *dp++ = '\0';611 *rbuf = buf;612 *endptr = dp;613 614 return EOK;615 }616 617 569 /** Compute UI text width. 618 570 * … … 664 616 665 617 /* Break down string into list of (non)highlighted parts */ 666 rc = ui_ text_process(str, &buf, &endptr);618 rc = ui_accel_process(str, &buf, &endptr); 667 619 if (rc != EOK) 668 620 return rc; -
uspace/lib/ui/test/main.c
rca2680d r96c6a00 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 31 31 PCUT_INIT; 32 32 33 PCUT_IMPORT(accel); 33 34 PCUT_IMPORT(control); 34 35 PCUT_IMPORT(checkbox); -
uspace/lib/ui/test/menubar.c
rca2680d r96c6a00 187 187 188 188 event.type = KEY_PRESS; 189 event.key = KC_ESCAPE; 189 event.key = KC_F10; 190 event.mods = 0; 190 191 claimed = ui_menu_bar_kbd_event(mbar, &event); 191 192 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 249 250 } 250 251 251 /** Calling ui_menu_bar_select() with the same menu twice deselects it */252 PCUT_TEST(select_same)253 {254 ui_t *ui = NULL;255 ui_window_t *window = NULL;256 ui_wnd_params_t params;257 ui_menu_bar_t *mbar = NULL;258 ui_menu_t *menu = NULL;259 errno_t rc;260 261 rc = ui_create_disp(NULL, &ui);262 PCUT_ASSERT_ERRNO_VAL(EOK, rc);263 264 ui_wnd_params_init(¶ms);265 params.caption = "Hello";266 267 rc = ui_window_create(ui, ¶ms, &window);268 PCUT_ASSERT_ERRNO_VAL(EOK, rc);269 PCUT_ASSERT_NOT_NULL(window);270 271 rc = ui_menu_bar_create(ui, window, &mbar);272 PCUT_ASSERT_ERRNO_VAL(EOK, rc);273 PCUT_ASSERT_NOT_NULL(mbar);274 275 rc = ui_menu_create(mbar, "Test", &menu);276 PCUT_ASSERT_ERRNO_VAL(EOK, rc);277 PCUT_ASSERT_NOT_NULL(menu);278 279 ui_menu_bar_select(mbar, menu, true);280 PCUT_ASSERT_EQUALS(menu, mbar->selected);281 282 /* Selecting again should unselect the menu */283 ui_menu_bar_select(mbar, menu, true);284 PCUT_ASSERT_NULL(mbar->selected);285 286 ui_menu_bar_destroy(mbar);287 ui_window_destroy(window);288 ui_destroy(ui);289 }290 291 252 /** Calling ui_menu_bar_select() with another menu selects it */ 292 253 PCUT_TEST(select_different)
Note:
See TracChangeset
for help on using the changeset viewer.