Changeset 81ec7e1 in mainline for uspace/lib/ui/src


Ignore:
Timestamp:
2021-08-31T08:57:24Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b79c91cc
Parents:
ff6e91b
git-author:
Jiri Svoboda <jiri@…> (2021-08-30 20:57:08)
git-committer:
Jiri Svoboda <jiri@…> (2021-08-31 08:57:24)
Message:

Brace for a text mode menu separator entry

Pun intended.

Location:
uspace/lib/ui/src
Files:
2 edited

Legend:

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

    rff6e91b r81ec7e1  
    349349
    350350        if (mentry->separator) {
    351                 rect.p0 = geom.caption_pos;
    352                 rect.p1.x = geom.shortcut_pos.x;
    353                 rect.p1.y = rect.p0.y + 2;
    354                 rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color,
    355                     res->wnd_highlight_color, 1, NULL);
    356                 if (rc != EOK)
    357                         goto error;
     351                if (res->textmode) {
     352                        rect = geom.outer_rect;
     353                        rect.p0.x -= 1;
     354                        rect.p1.x += 1;
     355
     356                        rc = ui_paint_text_hbrace(res, &rect, ui_box_single,
     357                            res->wnd_face_color);
     358                        if (rc != EOK)
     359                                goto error;
     360                } else {
     361                        rect.p0 = geom.caption_pos;
     362                        rect.p1.x = geom.shortcut_pos.x;
     363                        rect.p1.y = rect.p0.y + 2;
     364                        rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color,
     365                            res->wnd_highlight_color, 1, NULL);
     366                        if (rc != EOK)
     367                                goto error;
     368                }
    358369        }
    359370
  • uspace/lib/ui/src/paint.c

    rff6e91b r81ec7e1  
    6262};
    6363
     64/** Single horizontal brace characters */
     65static ui_brace_chars_t single_hbrace_chars = {
     66        .start = "\u251c",
     67        .middle = "\u2500",
     68        .end = "\u2524"
     69};
     70
     71/** Double horizontal brace characters */
     72static ui_brace_chars_t double_hbrace_chars = {
     73        .start = "\u2560",
     74        .middle = "\u2550",
     75        .end = "\u2563"
     76};
     77
    6478/** Paint bevel.
    6579 *
     
    462476}
    463477
     478/** Paint a text horizontal brace.
     479 *
     480 * @param resource UI resource
     481 * @param rect Rectangle inside which to paint the brace (height should
     482 *             be 1).
     483 * @param style Box style
     484 * @param color Color
     485 * @return EOK on success or an error code
     486 */
     487errno_t ui_paint_text_hbrace(ui_resource_t *resource, gfx_rect_t *rect,
     488    ui_box_style_t style, gfx_color_t *color)
     489{
     490        errno_t rc;
     491        gfx_text_fmt_t fmt;
     492        gfx_rect_t srect;
     493        gfx_coord2_t pos;
     494        gfx_coord2_t dim;
     495        size_t bufsz;
     496        size_t off;
     497        int i;
     498        char *str = NULL;
     499        ui_brace_chars_t *hbc = NULL;
     500
     501        gfx_rect_points_sort(rect, &srect);
     502        gfx_rect_dims(&srect, &dim);
     503
     504        /* Is rectangle large enough to hold brace? */
     505        if (dim.x < 2 || dim.y < 1)
     506                return EOK;
     507
     508        switch (style) {
     509        case ui_box_single:
     510                hbc = &single_hbrace_chars;
     511                break;
     512        case ui_box_double:
     513                hbc = &double_hbrace_chars;
     514                break;
     515        }
     516
     517        if (hbc == NULL)
     518                return EINVAL;
     519
     520        gfx_text_fmt_init(&fmt);
     521        fmt.color = color;
     522
     523        bufsz = str_size(hbc->start) +
     524            str_size(hbc->middle) * (dim.x - 2) +
     525            str_size(hbc->end) + 1;
     526
     527        str = malloc(bufsz);
     528        if (str == NULL)
     529                return ENOMEM;
     530
     531        str_cpy(str, bufsz, hbc->start);
     532        off = str_size(hbc->start);
     533
     534        for (i = 1; i < dim.x - 1; i++) {
     535                str_cpy(str + off, bufsz - off, hbc->middle);
     536                off += str_size(hbc->middle);
     537        }
     538
     539        str_cpy(str + off, bufsz - off, hbc->end);
     540        off += str_size(hbc->end);
     541        str[off] = '\0';
     542
     543        pos = rect->p0;
     544        rc = gfx_puttext(resource->font, &pos, &fmt, str);
     545        if (rc != EOK)
     546                goto error;
     547
     548        free(str);
     549        return EOK;
     550error:
     551        if (str != NULL)
     552                free(str);
     553        return rc;
     554}
     555
    464556/** @}
    465557 */
Note: See TracChangeset for help on using the changeset viewer.