Text

The text widget is the basic widget used to display text, which can be used to output text in different fonts, different colors, and different sizes to the screen. In order to draw text, the font file can be a standard .ttf file or a customized .bin file.

Features

Text widgets can support the following features.

  • UTF-8/UTF16/UTF-32 support

  • Multi language support

  • Text typesetting support

  • Word wrap and texts scrolling

  • Anti-aliasing

  • Multi fonts support

  • Multi font sizes support

  • Thirty-two bit true color support

  • Emoji support

  • Custom animation effects support

  • Supports bitmap fonts and vector fonts

  • Self-developed font files support

Note

Multilingual support covers standard Latin character languages (such as English, French), major Asian languages (such as Chinese, Japanese, Korean), and languages requiring complex character rendering (such as Arabic, Persian, Thai, etc., including transformed, combined, or modified character texts).

Note

Only certain chips support vector fonts.

Usage

Using functions to load font files and display text.

Font Files

To render text, font files containing font information need to be loaded into the system.

Font files can be generated using the Realtek font converter, and there are two types: bitmap fonts and vector fonts. Font files can be pre-initialized, allowing the font to be automatically retrieved by the control's font size for rendering, or unique fonts can be set individually for text controls.

To initialize custom bin font files, you need to choose to call either gui_font_mem_init_mem() or gui_font_mem_init_ftl() based on the system's file reading method.

Create Text Widget

To create a text widget, you can use gui_text_create(), The coordinates on the screen and text box size have been identified after create. These attributes also can be modified whenever you want.

Note

The size of the text box should be larger than the string to be shown; out-of-range text will be hidden.

Set Text Attributes

Set Text

To add some texts or characters to a text widget and set text attributes with gui_text_set().

Note

The text length must be less than or equal to the set character length. For bitmap fonts, the text font size must match the size of the loaded font file; for vector fonts, the font size can be set dynamically.

Font Type

The text widget supports font type setting. Developers can call gui_text_type_set() to set the font source. You can set the address of font files and specify the font source mode.

Text Content

This interface can be used to set the content that needs to be displayed by the text widget gui_text_content_set().

Text Encoding

The text widget supports input formats in UTF-8, UTF-16, and UTF-32 encodings simultaneously. Developers can use gui_text_encoding_set() to change the encoding format.

Convert to Img

By using this function gui_text_convert_to_img(), the text in the text widget will be converted into an image, stored in memory, and rendered using the image. It also supports image transformations such as scaling and rotation. This only applies to bitmap fonts.

Note

Because the content and font size information of the text widget is needed, it should be called after set text. If the content, font size, position, and other attributes of the text have been modified, you need to reuse this interface for conversion.

Text Color

Developers can use the function gui_text_color_set() to set the text color.

Font Size

Developers can use the function gui_text_size_set() to set the font size. For vector fonts using FreeType, width and height can be set separately; for bitmap fonts, only the height parameter is effective as the font size.

Word Wrap

Developers can use the function gui_text_wordwrap_set() to enable or disable automatic word wrapping for English words.

Letter and Line Spacing

Developers can use the function gui_text_extra_letter_spacing_set() to set extra letter spacing, and gui_text_extra_line_spacing_set() to set extra line spacing.

Matrix Transformation

Developers can use the function gui_text_set_matrix() to set a transformation matrix for the text widget, enabling effects like rotation and scaling. Using gui_text_use_matrix_by_img() enables image-based matrix rendering, suitable for complex transformations.

Minimum Scale

Developers can use the function gui_text_set_min_scale() to set the minimum scale ratio for text.

Font Render Mode

For vector fonts, developers can use the function gui_text_rendermode_set() to set the rasterization render mode (1/2/4/8).

Font Source Mode

Developers can use the function gui_text_font_mode_set() to set the font source mode, such as loading fonts from memory address, FTL, or file system.

Bold Setting

Developers can use the function gui_text_bold_set() to set the bold weight and bold mode for text. Bold weight ranges from 0 (normal) to 8 (boldest), and bold mode supports horizontal bold (fast) and omnidirectional bold.

Note

Bold functionality is only effective for TTF vector fonts; bitmap fonts do not support this setting.

Emoji

Developers can use the function gui_text_emoji_set() to set the path and size of emoji image files. Requires use with a file system.

Text Modes

The text control currently supports 36 types of layout modes, including the following categories:

  • Single-line layout modes (3 types): Suitable for scenarios displaying only one line of text, such as single-line centered, left-aligned, right-aligned, etc.

  • Multi-line layout modes (3 types): Used for displaying multiple lines of text, supporting various arrangements like multi-line centered, multi-line left-aligned, multi-line right-aligned, etc.

  • Single-line middle layout modes (3 types): Single-line text vertically centered, supporting left-aligned, centered, and right-aligned.

  • Multi-line middle layout modes (3 types): Multi-line text vertically centered, supporting left-aligned, centered, and right-aligned.

  • Single-line bottom layout modes (3 types): Single-line text anchored to the bottom edge, supporting left-aligned, centered, and right-aligned.

  • Multi-line bottom layout modes (3 types): Multi-line text anchored to the bottom edge, supporting left-aligned, centered, and right-aligned.

  • Scrolling layout modes (6 types): Ideal for displaying content that exceeds the display area by scrolling, including horizontal scrolling (top and middle) and vertical scrolling.

  • Vertical layout modes (6 types): Supports vertical text display from top to bottom, and can also be used as a general layout method for rotated text, including top alignment, middle alignment, and bottom alignment.

  • RTL (right-to-left) layout modes (6 types): Designed for languages written from right to left, such as Arabic and Hebrew, supporting corresponding layout modes.

Each layout mode can be selected based on the actual application scenario to meet diverse text display needs. Use gui_text_mode_set() to set the text layout mode.

Top and middle modes truncate the text at the widget's bottom edge. Bottom modes instead anchor the last line to that edge, so when the content is taller than the widget the top of the text is clipped rather than the end.

All type setting modes are as follows.

Text Mode

Type

Line Type

X Direction

Y Direction

Widget

LEFT

Single-line

Left

Top

Text widget (Default)

CENTER

Single-line

Center

Top

Text widget

RIGHT

Single-line

Right

Top

Text widget

MULTI_LEFT

Multi-line

Left

Top

Text widget

MULTI_CENTER

Multi-line

Center

Top

Text widget

MULTI_RIGHT

Multi-line

Right

Top

Text widget

MID_LEFT

Single-line

Left

Mid

Text widget

MID_CENTER

Single-line

Center

Mid

Text widget

MID_RIGHT

Single-line

Right

Mid

Text widget

MULTI_MID_LEFT

Multi-line

Left

Mid

Text widget

MULTI_MID_CENTER

Multi-line

Center

Mid

Text widget

MULTI_MID_RIGHT

Multi-line

Right

Mid

Text widget

BOT_LEFT

Single-line

Left

Bottom

Text widget

BOT_CENTER

Single-line

Center

Bottom

Text widget

BOT_RIGHT

Single-line

Right

Bottom

Text widget

MULTI_BOT_LEFT

Multi-line

Left

Bottom

Text widget

MULTI_BOT_CENTER

Multi-line

Center

Bottom

Text widget

MULTI_BOT_RIGHT

Multi-line

Right

Bottom

Text widget

SCROLL_X

Single-line

Right to Left

Top

Scroll text widget

SCROLL_X_REVERSE

Single-line

Left to Right

Top

Scroll text widget

SCROLL_X_MID

Single-line

Right to Left

Mid

Scroll text widget

SCROLL_X_MID_REVERSE

Single-line

Left to Right

Mid

Scroll text widget

SCROLL_Y

Multi-line

Left

Bottom to Top

Scroll text widget

SCROLL_Y_REVERSE

Multi-line

Right

Top to Bottom

Scroll text widget

VERTICAL_LEFT_TOP

Multi-line

Left

Top to Bottom, top aligned

Text widget

VERTICAL_LEFT_MID

Multi-line

Left

Top to Bottom, middle aligned

Text widget

VERTICAL_LEFT_BOT

Multi-line

Left

Top to Bottom, bottom aligned

Text widget

VERTICAL_RIGHT_TOP

Multi-line

Right

Bottom to Top, top aligned

Text widget

VERTICAL_RIGHT_MID

Multi-line

Right

Bottom to Top, middle aligned

Text widget

VERTICAL_RIGHT_BOT

Multi-line

Right

Bottom to Top, bottom aligned

Text widget

RTL_RIGHT

Multi-line

Right

Top

Text widget

RTL_CENTER

Multi-line

Center

Top

Text widget

RTL_LEFT

Multi-line

Left

Top

Text widget

RTL_MULTI_RIGHT

Multi-line

Right

Top

Text widget

RTL_MULTI_CENTER

Multi-line

Center

Top

Text widget

RTL_MULTI_LEFT

Multi-line

Left

Top

Text widget

typedef enum
{
    /* TOP */
    LEFT                 = 0x00,
    CENTER               = 0x01,
    RIGHT                = 0x02,
    MULTI_LEFT           = 0x03,
    MULTI_CENTER         = 0x04,
    MULTI_RIGHT          = 0x05,
    /* MID */
    MID_LEFT             = 0x10,
    MID_CENTER           = 0x11,
    MID_RIGHT            = 0x12,
    MULTI_MID_LEFT       = 0x13,
    MULTI_MID_CENTER     = 0x14,
    MULTI_MID_RIGHT      = 0x15,
    /* BOT */
    BOT_LEFT             = 0x20,
    BOT_CENTER           = 0x21,
    BOT_RIGHT            = 0x22,
    MULTI_BOT_LEFT       = 0x23,
    MULTI_BOT_CENTER     = 0x24,
    MULTI_BOT_RIGHT      = 0x25,
    /* SCROLL */
    SCROLL_X             = 0x30,
    SCROLL_X_REVERSE     = 0x31,
    SCROLL_X_MID         = 0X32,
    SCROLL_X_MID_REVERSE = 0x33,

    SCROLL_Y             = 0x38,
    SCROLL_Y_REVERSE     = 0x39,
    /* VERTICAL LEFT
    &  CLOCKWISE*/
    VERTICAL_LEFT_TOP    = 0x40,
    VERTICAL_LEFT_MID    = 0x41,
    VERTICAL_LEFT_BOT    = 0x42,
    /* VERTICAL RIGHT
    &  COUNTERCLOCKWISE*/
    VERTICAL_RIGHT_TOP   = 0x50,
    VERTICAL_RIGHT_MID   = 0x51,
    VERTICAL_RIGHT_BOT   = 0x52,
    /* RTL */
    RTL_RIGHT            = 0x60,
    RTL_CENTER           = 0x61,
    RTL_LEFT             = 0x62,
    RTL_MULTI_RIGHT      = 0x63,
    RTL_MULTI_CENTER     = 0x64,
    RTL_MULTI_LEFT       = 0x65,
} TEXT_MODE;

Text Move

It is possible to use this function gui_text_move() to move text to a specified location.

Text Layout Measurement

Developers can call gui_text_layout_measure() to obtain text layout information before rendering. This function triggers the full font loading and layout pipeline, writing results back to the following widget fields:

  • char_width_sum: Total pixel width of text content (single-line width or sum of all character widths in multi-line mode)

  • char_height_sum: Total pixel height of all laid-out lines

  • char_line_sum: Number of lines after layout

  • active_font_len: Number of characters visible within the bounding box

  • font_len: Total character count (including clipped ones)

This function supports all font types (BMP/TTF/STB/MAT) and all layout modes, correctly handling word wrap, word break protection, letter spacing, line spacing, and complex text shaping for Arabic, Thai, Hebrew, etc.

Note

Must be called after setting text content and font attributes (e.g., gui_text_set, gui_text_mode_set, etc.).

Scope Clipping

Developers can use the function gui_text_set_scope() to set a clip scope on the text widget. Only the portion of text inside the scope rectangle will be drawn. The coordinates are relative to the text widget's own top-left corner.

Additionally, gui_text_set_scope_absolute() can be used to set the clip scope using absolute screen coordinates.

Example

The text widget provides multiple examples and test cases located in example/widget/text/. Enable the desired test in app_init of example_text.c.

Example List

#

Function

Description

1

text_widget_example()

Basic text widget with click event and timer callback

2

scroll_text_widget_example()

Horizontal (SCROLL_X) and vertical (SCROLL_Y) auto-scroll

3

custom_font_rendering_demo()

Custom font engine with user-defined load/draw/unload/destroy

4

text_font_rendering_test()

Swipeable views: bitmap (1/2/4/8-bit), vector, bold, matrix, img, bench

5

text_font_layout_test()

Swipeable views: single-line, multi-line, scroll, vertical, RTL

6

text_multi_language_test()

Language list with per-language rendering (AR, EN, ZH, TH, HE)

7

text_font_scroll_function_test()

Scroll X/Y/reverse with stop/reset/pause/resume and alignment modes

8

text_font_scroll_loop_test()

Scroll loop (marquee) for X/Y forward and reverse directions

9

text_font_source_mode_test()

3x4 grid: source (MEMADDR/FTL/FILESYS) x type (BMP/IMG/MAT/TTF)

10

text_wordwrap_test()

Word wrap with oversized word break protection

11

text_measure_test()

Layout measure: BMP/TTF single-line and multi-line metrics

12

text_clip_test()

Partial text display using win clip (top/bottom/right/center)

13

text_font_typo_rendering_test()

Typography rendering: bitmap + vector baseline/line-height (swipeable)

14

text_font_fallback_test()

Mixed-language fallback: CJK+EN in one string with priority chain

Simple Text Widget (Example 1: text_widget_example)

Basic text widget with click event and periodic timer callback.

void text_widget_example(void)
{
    char *text_string = "HoneyGUI";
    gui_text_t *text = gui_text_create(gui_obj_get_root(), "text", 0, 0, 0, 0);
    gui_text_set(text, text_string, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(text_string), 32);
    gui_text_type_set(text, font32b2, FONT_SRC_MEMADDR);

    gui_obj_add_event_cb(text, (gui_event_cb_t)test_event_cb, GUI_EVENT_TOUCH_CLICKED, NULL);

    gui_obj_create_timer(&(text->base), 1000, true, test_timer_cb);
    gui_obj_start_timer(&(text->base));
}

API

Defines

GUI_TEXT_GRADIENT_MAX_STOPS 8
GUI_TEXT_GRADIENT_LUT_SIZE 256
GUI_TEXT_SUBSTITUTE_CHAIN_MAX 4

Maximum number of substitute code points in the chain.

Enums

enum gui_text_gradient_dir_t

Gradient direction, matching the rect widget's directions.

Values:

enumerator GUI_TEXT_GRADIENT_HORIZONTAL

Left to right.

enumerator GUI_TEXT_GRADIENT_VERTICAL

Top to bottom.

enumerator GUI_TEXT_GRADIENT_DIAGONAL_TL_BR

Top-left to bottom-right.

enumerator GUI_TEXT_GRADIENT_DIAGONAL_TR_BL

Top-right to bottom-left.

enum gui_text_gradient_box_t

Box the gradient handles are normalized against.

Values:

enumerator GUI_TEXT_GRADIENT_BOX_INK

Union of the glyph outlines.

enumerator GUI_TEXT_GRADIENT_BOX_LAYOUT

Pen advances x line boxes, like a Figma auto-size text.

enumerator GUI_TEXT_GRADIENT_BOX_WIDGET

Widget rectangle, like a Figma fixed-size text.

enum TEXT_MODE

Values:

enumerator LEFT
enumerator CENTER
enumerator RIGHT
enumerator MULTI_LEFT
enumerator MULTI_CENTER
enumerator MULTI_RIGHT
enumerator MID_LEFT
enumerator MID_CENTER
enumerator MID_RIGHT
enumerator MULTI_MID_LEFT
enumerator MULTI_MID_CENTER
enumerator MULTI_MID_RIGHT
enumerator BOT_LEFT
enumerator BOT_CENTER
enumerator BOT_RIGHT
enumerator MULTI_BOT_LEFT
enumerator MULTI_BOT_CENTER
enumerator MULTI_BOT_RIGHT
enumerator SCROLL_X
enumerator SCROLL_X_REVERSE
enumerator SCROLL_X_MID
enumerator SCROLL_X_MID_REVERSE
enumerator SCROLL_Y
enumerator SCROLL_Y_REVERSE
enumerator VERTICAL_LEFT_TOP
enumerator VERTICAL_LEFT_MID
enumerator VERTICAL_LEFT_BOT
enumerator VERTICAL_RIGHT_TOP
enumerator VERTICAL_RIGHT_MID
enumerator VERTICAL_RIGHT_BOT
enumerator RTL_RIGHT
enumerator RTL_CENTER
enumerator RTL_LEFT
enumerator RTL_MULTI_RIGHT
enumerator RTL_MULTI_CENTER
enumerator RTL_MULTI_LEFT

Functions

void gui_text_click(gui_text_t *this_widget, gui_event_cb_t event_cb, void *parameter)

Set textbox click event callback.

Parameters:
  • this_widget -- Text widget.

  • event_cb -- Callback function.

  • parameter -- Callback parameter.

void gui_text_pswd_done(gui_text_t *this_widget, gui_event_cb_t event_cb, void *parameter)

Set textbox password done event callback to handle password.

Parameters:
  • this_widget -- Text widget.

  • event_cb -- Callback function.

  • parameter -- Callback parameter.

void gui_text_set(gui_text_t *this_widget, void *text, FONT_SRC_TYPE text_type, gui_color_t color, uint16_t length, uint16_t font_size)

Set the string in a text box widget.

Note

The font size must match the font file.

Parameters:
  • this_widget -- Text box widget pointer.

  • text -- Text string.

  • text_type -- Text type.

  • color -- Text's color.

  • length -- Text string's length.

  • font_size -- Text string's font size.

void gui_text_mode_set(gui_text_t *this_widget, TEXT_MODE mode)

Set text mode of this_widget text widget.

Note

If text line count was more than one, it will display on the left even if it was set left or right.

Parameters:
  • this_widget -- Text widget pointer.

  • mode -- Text layout mode (e.g., LEFT, CENTER, RIGHT, MULTI_LEFT, BOT_LEFT, MULTI_BOT_CENTER, SCROLL_X, VERTICAL_LEFT_TOP, RTL_RIGHT, etc.).

void gui_text_input_set(gui_text_t *this_widget, bool inputable)

Set inputable.

Parameters:
  • this_widget -- Text box widget pointer.

  • inputable -- Inputable.

void gui_text_color_set(gui_text_t *this_widget, gui_color_t color)

Set font color.

Parameters:
  • this_widget -- Text box widget pointer.

  • color -- Font color.

void gui_text_wordwrap_set(gui_text_t *this_widget, bool wordwrap)

By setting wordwrap to enable English word wrapping.

Parameters:
  • this_widget -- Text box widget pointer.

  • wordwrap -- Wordwrap.

void gui_text_extra_letter_spacing_set(gui_text_t *this_widget, int8_t extra_letter_spacing)

Set extra letter spacing.

Parameters:
  • this_widget -- Text box widget pointer.

  • extra_letter_spacing -- Extra letter spacing.

void gui_text_extra_line_spacing_set(gui_text_t *this_widget, int8_t extra_line_spacing)

Set extra line spacing.

Parameters:
  • this_widget -- Text box widget pointer.

  • extra_line_spacing -- Extra line spacing.

void gui_text_set_line_height(gui_text_t *this_widget, int16_t line_height)

Set explicit line height for multi-line layout (Figma "Line height" property).

Parameters:
  • this_widget -- Text box widget pointer.

  • line_height -- Line height in pixels. 0 = use default calculated line height.

void gui_text_set_space_width(gui_text_t *this_widget, uint16_t space_width)

Set the fallback space width for legacy TTF fonts.

Parameters:
  • this_widget -- Text box widget pointer.

  • space_width -- Space width in pixels. 0 = use the default approximation.

void gui_text_set_missing_glyph_mode_global(gui_missing_glyph_mode_t mode)

Set the global behavior for code points with no glyph anywhere.

Parameters:

mode -- GUI_MISSING_GLYPH_SKIP or GUI_MISSING_GLYPH_SUBSTITUTE. GUI_MISSING_GLYPH_INHERIT is ignored, it is per-widget only.

void gui_text_set_missing_glyph_mode(gui_text_t *this_widget, gui_missing_glyph_mode_t mode)

Set this widget's behavior for characters missing from every font.

Overrides the global mode set by gui_text_set_missing_glyph_mode_global().

Parameters:
  • this_widget -- Text box widget pointer.

  • mode -- Missing-glyph mode; INHERIT follows the global mode.

bool gui_text_substitute_enabled(const gui_text_t *text)

Whether a text widget should substitute glyphs for missing characters.

Parameters:

text -- Text widget, may be NULL to query the global mode.

Returns:

true if substitution is enabled.

void gui_text_substitute_chain_set(const uint32_t *cps, uint8_t n)

Override the substitute code point chain.

Candidates are tried in order; the first one with a glyph wins. Takes effect when glyphs are loaded, so set it during init rather than per frame.

Parameters:
  • cps -- Candidate code points; ignored when NULL.

  • n -- Number of candidates, clamped to GUI_TEXT_SUBSTITUTE_CHAIN_MAX.

void gui_text_use_matrix_by_img(gui_text_t *this_widget, bool use_img_blit)

Enable/disable matrix-based image rendering for text.

Parameters:
  • this_widget -- Pointer to the text widget.

  • use_img_blit -- True = Use image matrix blitting (for complex transformations), False = Use standard rendering.

void gui_text_rendermode_set(gui_text_t *this_widget, uint8_t rendermode)

Set TTF raster render mode.

Parameters:
  • this_widget -- Text box widget pointer.

  • rendermode -- Render mode. 1/2/4/8.

void gui_text_bold_set(gui_text_t *this_widget, uint8_t bold_weight, BOLD_MODE bold_mode)

Set text bold weight and mode (only effective for vector fonts).

Parameters:
  • this_widget -- Text box widget pointer.

  • bold_weight -- Bold weight. 0 = normal, 1-8 = bold levels.

  • bold_mode -- Bold mode: BOLD_HORIZONTAL (fast) or BOLD_FULL.

void gui_text_set_min_scale(gui_text_t *this_widget, float min_scale)

Set text minimum scale.

Parameters:
  • this_widget -- Text box widget pointer.

  • min_scale -- Minimum scale.

void gui_text_move(gui_text_t *this_widget, int16_t x, int16_t y)

Move the text widget.

Parameters:
  • this_widget -- Text box widget pointer.

  • x -- X-axis coordinate of the text box.

  • y -- Y-axis coordinate of the text box.

void gui_text_size_set(gui_text_t *this_widget, uint16_t height, uint16_t width)

Set font size or width and height.

Note

If using FreeType, width and height are effective; otherwise, height will be applied as font size.

Parameters:
  • this_widget -- Text widget pointer.

  • height -- Font height or font size.

  • width -- Font width (only effective when FreeType is used).

void gui_text_font_mode_set(gui_text_t *this_widget, FONT_SRC_MODE font_mode)

Set text font mode.

Parameters:
  • this_widget -- Text widget pointer.

  • font_mode -- Font source mode.

void gui_text_type_set(gui_text_t *this_widget, void *font_source, FONT_SRC_MODE font_mode)

Set font type.

Note

The type must match the font size.

Note

With FONT_SRC_FILESYS on an XIP-capable VFS backend (romfs, ramfs) the font is read in place and the widget switches to FONT_SRC_MEMADDR. The file must stay mounted and unmodified while any widget uses the font.

Parameters:
  • this_widget -- Text widget pointer.

  • font_source -- Address of .ttf or .bin.

  • font_mode -- Font source mode.

void gui_text_emoji_set(gui_text_t *this_widget, uint8_t *path, uint8_t size)

Set emoji file path and emoji size.

Note

Requires ROMFS.

Note

Example of a full emoji image file path: 'font/emoji/emoji_u1f30d.bin'.

Parameters:
  • this_widget -- Text widget pointer.

  • path -- Path containing folder path and file name prefix. Path example: 'font/emoji/emoji_u'. Folder path is the emoji image file folder path, e.g., 'font/emoji/'. File name prefix is the prefix before the filename for Unicode sorting, e.g., 'emoji_u'.

  • size -- Emoji image file size, e.g., 32.

void gui_text_encoding_set(gui_text_t *this_widget, TEXT_CHARSET charset)

Set font encoding.

Note

UTF-8 or Unicode.

Parameters:
  • this_widget -- Text widget pointer.

  • charset -- Encoding type.

void gui_text_set_matrix(gui_text_t *this_widget, gui_matrix_t *matrix)

Set text matrix.

Note

Parameters:
  • this_widget -- Text widget pointer.

  • matrix -- Matrix pointer.

void gui_text_set_cache(gui_text_t *this_widget, bool enable)

Enable cross-frame glyph bitmap cache for TTF text.

When enabled, rasterized glyph bitmaps are kept alive across frames instead of being freed each frame, eliminating re-rasterization for static or purely translating/scrolling text. Only effective for identity / pure-translate transforms; scale/rotate always re-rasterizes per frame. Trades memory (resident glyph bitmaps until content change or destroy) for CPU.

Parameters:
  • this_widget -- Text widget pointer.

  • enable -- true to keep glyph bitmaps across frames, false (default) to free them each frame.

void gui_text_content_set(gui_text_t *this_widget, void *text, uint16_t length)

Set text content.

Parameters:
  • this_widget -- Text widget pointer.

  • text -- Text string.

  • length -- Text string's length.

void gui_text_convert_to_img(gui_text_t *this_widget, GUI_FormatType font_img_type)

Draw text by image so that text can be scaled.

Parameters:
  • this_widget -- Text widget pointer.

  • font_img_type -- Color format.

gui_text_t *gui_text_create(void *parent, const char *name, int16_t x, int16_t y, int16_t w, int16_t h)

Create a text box widget.

Note

The area of the text box should be larger than that of the string to be shown; otherwise, part of the text will be hidden.

Parameters:
  • parent -- Parent widget in which the text is nested.

  • name -- Widget's name.

  • x -- X-axis coordinate of the text box.

  • y -- Y-axis coordinate of the text box.

  • w -- Width of the text box.

  • h -- Height of the text box.

Returns:

Widget object pointer.

void gui_text_layout_measure(gui_text_t *this_widget)

Perform text layout measurement without rendering.

Triggers the full font loading and layout pipeline using the widget's current properties, then writes results back to the widget's fields: char_width_sum, char_height_sum, char_line_sum, active_font_len, font_len.

Can be called right after gui_text_set() / gui_text_mode_set() etc., before any draw cycle.

Parameters:

this_widget -- Text widget pointer (must have content and font set).

void gui_text_set_scope(gui_text_t *this_widget, int16_t x, int16_t y, int16_t w, int16_t h)

Set a clip scope on the text widget (relative to text position).

Only the portion of text inside the scope rectangle will be drawn. Coordinates are relative to the text widget's own top-left corner.

Parameters:
  • this_widget -- Text widget pointer.

  • x -- X offset of the visible area relative to text.

  • y -- Y offset of the visible area relative to text.

  • w -- Width of the visible area.

  • h -- Height of the visible area.

void gui_text_set_scope_absolute(gui_text_t *this_widget, int16_t x, int16_t y, int16_t w, int16_t h)

Set an absolute clip scope on the text widget (screen coordinates).

Parameters:
  • this_widget -- Text widget pointer.

  • x -- X coordinate on screen.

  • y -- Y coordinate on screen.

  • w -- Width of the visible area.

  • h -- Height of the visible area.

void gui_text_set_font_blend_mode(gui_text_t *this_widget, BLEND_MODE_TYPE blend_mode)

Set font blend mode for text rendering.

Parameters:
  • this_widget -- Text widget pointer.

  • blend_mode -- Blend mode (e.g., IMG_PLUS_DARKER for darken blend).

void gui_text_set_gradient(gui_text_t *this_widget, gui_text_gradient_dir_t dir, const gui_text_gradient_stop_t *stops, uint8_t count)

Fill the text with a linear gradient.

Replaces the text color's RGB; its alpha and the widget opacity still apply. Only vector (TTF) text drawn without scale or rotation on an RGB565 or ARGB8888 display shows the gradient; other cases keep the flat color. Resets the handles to the preset of dir; the box mode is kept.

Parameters:
  • this_widget -- Text widget pointer.

  • dir -- Gradient direction preset.

  • stops -- Color stops, positions in 0.0 to 1.0; at most GUI_TEXT_GRADIENT_MAX_STOPS are used.

  • count -- Number of stops. NULL stops or count < 2 clears the gradient.

void gui_text_set_gradient_box(gui_text_t *this_widget, gui_text_gradient_box_t box)

Select the box the gradient handles are normalized against.

Default is GUI_TEXT_GRADIENT_BOX_INK. No effect before gui_text_set_gradient().

Parameters:
  • this_widget -- Text widget pointer.

  • box -- Box mode.

void gui_text_set_gradient_handles(gui_text_t *this_widget, float x0, float y0, float x1, float y1)

Place the gradient start and end handles, overriding the dir preset.

Coordinates are normalized to the box: (0, 0) top-left, (1, 1) bottom-right, matching Figma's gradientHandlePositions. Each value is clamped to -1.0..2.0. Handles closer than 1/16 of the box draw the first stop's color. No effect before gui_text_set_gradient().

Parameters:
  • this_widget -- Text widget pointer.

  • x0 -- Start handle X, stop position 0.0.

  • y0 -- Start handle Y.

  • x1 -- End handle X, stop position 1.0.

  • y1 -- End handle Y.

gui_inline bool gui_text_rect_hit (gui_text_rect_t *a, gui_rect_t *b)
gui_inline bool gui_text_scope_rect_hit (gui_text_rect_t *a, gui_rect_t *b)

Variables

uint32_t gui_text_substitute_chain[GUI_TEXT_SUBSTITUTE_CHAIN_MAX + 1]

Substitute candidates for missing glyphs, 0x0000-terminated.

Default order: U+FFFD replacement char, U+25A1 white square, U+0020 space. The space is the last resort: nearly every font has it, so a missing character degrades to a blank of the font's own width instead of vanishing.

struct gui_text_gradient_stop_t

Gradient color stop.

Public Members

float position

Position from the start handle (0.0) to the end handle (1.0).

gui_color_t color

Color at this position, alpha included.

struct gui_text_gradient_t

Text gradient state, allocated by gui_text_set_gradient().

Public Members

gui_text_gradient_dir_t dir
gui_text_gradient_box_t box
float handle_x0

Start handle, normalized to the box.

float handle_y0
float handle_x1

End handle, normalized to the box.

float handle_y1
font_gradient_t view

Rebound by the font draw each time.

bool bounds_valid
uint32_t bounds_frame

Frame the box was measured in.

int16_t bounds_x0

Box in screen coordinates, inclusive.

int16_t bounds_y0
int16_t bounds_x1
int16_t bounds_y1
int16_t shift_x

Offset of the copy being drawn from the measured box.

int16_t shift_y

Set by scroll text for its loop copy; 0 otherwise.

uint32_t lut[GUI_TEXT_GRADIENT_LUT_SIZE]

ARGB8888 colors.

struct gui_text_t

Text widget structure.

Public Members

gui_obj_t base
gui_color_t color
gui_img_t *scale_img
uint8_t *emoji_path
float min_scale
void *content
void *data
void *path
gui_matrix_t *matrix
gui_text_gradient_t *gradient

Optional gradient fill, NULL = flat color.

uint16_t len
uint16_t font_len
uint16_t active_font_len
int16_t char_width_sum
int16_t char_height_sum
int16_t char_line_sum
int16_t offset_x
int16_t offset_y
uint16_t font_height
gui_rect_t scope_rect

self scope clip area (relative to text)

TEXT_MODE mode
TEXT_CHARSET charset
FONT_SRC_TYPE font_type
FONT_SRC_MODE font_mode
BLEND_MODE_TYPE font_blend_mode

blend mode for font rendering

uint8_t emoji_size
uint8_t checksum
int8_t extra_letter_spacing
int8_t extra_line_spacing
int16_t line_height

explicit line height (0 = use default)

uint16_t space_width

fallback space width (0 = use default)

uint8_t bold_weight
bool layout_refresh
bool content_refresh
bool use_img_blit
bool inputable
bool ispasswd
bool wordwrap
bool scope
bool scope_self

scope set by gui_text_set_scope

bool scope_absolute

0=relative to text, 1=absolute screen coords

bool arabic
bool thai
bool hebrew
uint8_t rendermode
uint8_t bold_mode

0=BOLD_HORIZONTAL (fast), 1=BOLD_FULL

bool font_cache_enable

cross-frame glyph bitmap cache (identity/translate only)

bool font_cache_static

internal: chr[].buf currently holds a cross-frame static cache

uint8_t missing_glyph_mode

gui_missing_glyph_mode_t, 0 = inherit global

struct gui_text_line_t

Text line structure.

Public Members

int16_t index
int16_t offset