Changeset 96c6a00 in mainline for uspace/lib/ui/src
- 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/lib/ui/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.