Changeset 96c6a00 in mainline for uspace/lib/ui/src/paint.c


Ignore:
Timestamp:
2022-03-10T13:44:10Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
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)
Message:

Menu accelerators

Open a menu by pressing F10, then accelerator key (e.g. 'F').

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/paint.c

    rca2680d r96c6a00  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <gfx/render.h>
    4040#include <gfx/text.h>
     41#include <ui/accel.h>
    4142#include <ui/paint.h>
    4243#include <stdlib.h>
     
    566567}
    567568
    568 /** Process text with '~' markup.
    569  *
    570  * Parse text with tilde markup into a list of strings. @a *rbuf is set
    571  * to point to a newly allocated buffer containing consecutive null-terminated
    572  * strings.
    573  *
    574  * Each part between two '~' becomes one string. '~~' is translated into
    575  * a literal '~' character. @a *endptr is set to point to the first character
    576  * beyond the end of the list.
    577  *
    578  * @param str String with tilde markup
    579  * @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 code
    582  */
    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 
    617569/** Compute UI text width.
    618570 *
     
    664616
    665617        /* 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);
    667619        if (rc != EOK)
    668620                return rc;
Note: See TracChangeset for help on using the changeset viewer.