Changeset 9eb8d12 in mainline for uspace/lib/gfxfont/src/text.c


Ignore:
Timestamp:
2021-07-19T22:35:19Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c9722c1
Parents:
ead72f2
Message:

Entry text selection (using keyboard)

Text can be selected with movement keys while holding down Shift.
Selection can be deleted by pressing Backspace, Delete or typing
in replacement text.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/src/text.c

    read72f2 r9eb8d12  
    174174 * @param str String
    175175 * @param spos Place to store starting position
    176  * @return EOK on success or an error code
    177176 */
    178177void gfx_text_start_pos(gfx_font_t *font, gfx_coord2_t *pos,
     
    333332}
    334333
     334/** Get text continuation parameters.
     335 *
     336 * Return the anchor position and format needed to continue printing
     337 * text after the specified string. It is allowed for the sources
     338 * (@a pos, @a fmt) and destinations (@a cpos, @a cfmt) to point
     339 * to the same objects, respectively.
     340 *
     341 * @param font Font
     342 * @param pos Anchor position
     343 * @param fmt Text formatting
     344 * @param str String
     345 * @param cpos Place to store anchor position for continuation
     346 * @param cfmt Place to store format for continuation
     347 */
     348void gfx_text_cont(gfx_font_t *font, gfx_coord2_t *pos,
     349    gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *cpos,
     350    gfx_text_fmt_t *cfmt)
     351{
     352        gfx_coord2_t spos;
     353        gfx_text_fmt_t tfmt;
     354
     355        /* Continuation should start where the current string ends */
     356        gfx_text_start_pos(font, pos, fmt, str, &spos);
     357        cpos->x = spos.x + gfx_text_width(font, str);
     358        cpos->y = spos.y;
     359
     360        /*
     361         * Formatting is the same, except the text should be aligned
     362         * so that it starts at the anchor point.
     363         */
     364        tfmt = *fmt;
     365        tfmt.halign = gfx_halign_left;
     366        tfmt.valign = gfx_valign_baseline;
     367
     368        *cfmt = tfmt;
     369}
     370
     371/** Get text bounding rectangle.
     372 *
     373 * @param font Font
     374 * @param pos Anchor position
     375 * @param fmt Text formatting
     376 * @param str String
     377 * @param rect Place to store bounding rectangle
     378 */
     379void gfx_text_rect(gfx_font_t *font, gfx_coord2_t *pos,
     380    gfx_text_fmt_t *fmt, const char *str, gfx_rect_t *rect)
     381{
     382        gfx_coord2_t spos;
     383
     384        gfx_text_start_pos(font, pos, fmt, str, &spos);
     385
     386        rect->p0.x = spos.x;
     387        rect->p0.y = spos.y - font->metrics.ascent;
     388        rect->p1.x = spos.x + gfx_text_width(font, str);
     389        rect->p1.y = spos.y + font->metrics.descent + 1;
     390}
     391
    335392/** @}
    336393 */
Note: See TracChangeset for help on using the changeset viewer.