|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
Caller-owned, read-only styled text. More...
#include "font.h"#include "text.h"#include "text_shape.h"#include "input.h"#include "draw_target.h"#include "host.h"#include "style_ext.h"#include "a11y_types.h"#include "ui_context.h"Data Structures | |
| struct | rmgui_richtext_span_t |
| rmgui_richtext_span_t.font_px More... | |
| struct | rmgui_richtext_paragraph_t |
| rmgui_richtext_paragraph_t.start, rmgui_richtext_paragraph_t.end More... | |
| struct | rmgui_richtext_document_t |
| struct | rmgui_richtext_fonts_t |
| struct | rmgui_richtext_style_t |
| struct | rmgui_richtext_line_t |
| struct | rmgui_richtext_layout_t |
| struct | rmgui_richtext_t |
| rmgui_richtext_t.host More... | |
| struct | rmgui_richtext_view_t |
| Rich text state with an optional borrowed inline painter and its user data. More... | |
| struct | rmgui_richtext_hit_t |
| struct | rmgui_richtext_markdown_t |
| Tiny deterministic Markdown (not CommonMark): bold, italic, mono, [text](target), #..###### headings, '- '/'* ' bullets. More... | |
| struct | rmgui_richtext_markdown_run_t |
| One half-open source range and its corresponding display range, in UTF-8 bytes. More... | |
| struct | rmgui_richtext_markdown_map_t |
| struct | rmgui_richtext_markdown_options_t |
| Opt-in grammar for rmgui_richtext_markdown_mapped_ex. More... | |
Macros | |
| #define | RMGUI_RICHTEXT_BOLD 1u |
| #define | RMGUI_RICHTEXT_ITALIC 2u |
| #define | RMGUI_RICHTEXT_MONO 4u |
| #define | RMGUI_RICHTEXT_UNDERLINE 8u |
| #define | RMGUI_RICHTEXT_STRIKE 16u |
| #define | RMGUI_RICHTEXT_COLOR 32u |
| #define | RMGUI_RICHTEXT_BACKGROUND 64u |
| #define | RMGUI_RICHTEXT_COPY 1 |
| Copies selected UTF-8 plus NUL, writes byte length. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_STRICT_LINKS 1u |
| Strict link candidates. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_LABEL_STYLES 2u |
| Emphasis, bold, mono and backslash escapes are recognized inside a valid link label, with the same delimiter rules as elsewhere, confined to the label. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_LITERAL_BULLETS 4u |
| A line that starts with - or * emits the four bytes U+2022 followed by one ASCII space into the display text, with no paragraph bullet decoration (bullet stays zero and no indent column is reserved), so layout, search, selection and copy all see the same bytes. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_HEADING_TEXT 8u |
| A heading needs at least one byte after its marker and ASCII space: # alone or # alone on a line stays literal. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_CHAT_INLINE 16u |
| The inline grammar of the Automugen Chat message module, replacing the default inline rules; STRICT_LINKS and LABEL_STYLES then have no further effect. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_MARKER_TEXT 32u |
| A heading marker or a bullet marker (- or * ) needs at least one byte after its ASCII space that is not a carriage return or line feed. | |
| #define | RMGUI_RICHTEXT_MARKDOWN_FLAGS 63u |
| All defined RMGUI_RICHTEXT_MARKDOWN_* flag bits. | |
Typedefs | |
| typedef void(*) | rmgui_richtext_inline_fn(void *, rmgui_target_t *, rmgui_rect_t box, rmgui_rect_t clip, unsigned glyph) |
| Inline spans contain exactly one UTF-8 codepoint (typically U+FFFC). | |
Enumerations | |
| enum | rmgui_richtext_align_t { RMGUI_RICHTEXT_LEFT , RMGUI_RICHTEXT_CENTER , RMGUI_RICHTEXT_RIGHT } |
Functions | |
| int | rmgui_richtext_style (const rmgui_style_ext_resolved_t *, const rmgui_richtext_style_t *defaults, rmgui_richtext_style_t *out) |
| Optional resolved extension names: font-size, line-gap, text, background, selection, link. | |
| int | rmgui_richtext_prepare (const rmgui_ui_t *, const rmgui_richtext_view_t *) |
| Stage the current layout's text before recording. | |
| int | rmgui_richtext_draw (const rmgui_ui_t *, const rmgui_richtext_view_t *, rmgui_rect_t) |
| Draw with the current layout's fonts and style and the optional inline callback. | |
| int | rmgui_richtext_layout (const rmgui_richtext_t *, const rmgui_richtext_document_t *, const rmgui_richtext_fonts_t *, const rmgui_richtext_style_t *, int width, rmgui_richtext_layout_t *cache) |
| A document's spans exactly partition text; paragraphs do too, end at a newline or document end. | |
| int | rmgui_richtext_init (rmgui_richtext_t *, const rmgui_richtext_layout_t *) |
| Bind resets selection/capture/scroll; no cache/text copies. | |
| int | rmgui_richtext_hit (const rmgui_richtext_layout_t *, int x, int y, rmgui_richtext_hit_t *out) |
| Coordinates relative to the content origin, including scroll already. | |
| int | rmgui_richtext_select (rmgui_richtext_t *, size_t anchor, size_t caret) |
| int | rmgui_richtext_copy (const rmgui_richtext_t *, char *, size_t capacity, size_t *length) |
| rmgui_input_result_t | rmgui_richtext_input (rmgui_richtext_t *, rmgui_rect_t, const rmgui_input_t *) |
| Pointer drag selection, link click activation (value=link_id), hover cursor; focus-gated arrows/home/end/up/down/page keys, Shift extension, Ctrl/Meta A/C. | |
| int | rmgui_richtext_prepare_to (const rmgui_richtext_t *, rmgui_target_t *) |
| void | rmgui_richtext_paint_to (rmgui_target_t *, const rmgui_richtext_t *, rmgui_rect_t rect, rmgui_rect_t clip, rmgui_richtext_inline_fn, void *) |
| Binary-searches first visible cached line, then visits only visible lines and their spans. | |
| void | rmgui_richtext_paint (rmgui_fb_t *, const rmgui_richtext_t *, rmgui_rect_t rect, rmgui_rect_t clip, rmgui_richtext_inline_fn, void *) |
| int | rmgui_a11y_from_richtext (const rmgui_richtext_t *, size_t span, const char *name, rmgui_a11y_record_t *out) |
| span=SIZE_MAX builds TEXT; a link span builds LINK. | |
| int | rmgui_a11y_richtext_selection (const rmgui_richtext_t *, size_t start, size_t end, rmgui_rect_t *rects, size_t capacity, size_t *count) |
| int | rmgui_richtext_a11y_action (rmgui_richtext_t *, size_t span, rmgui_input_result_t *out) |
| Accessibility PRESS on a link span; other host actions use input/select. | |
| int | rmgui_richtext_markdown (const char *source, size_t length, int base_px, rmgui_richtext_markdown_t *out) |
| int | rmgui_richtext_markdown_mapped (const char *source, size_t length, int base_px, rmgui_richtext_markdown_t *out, rmgui_richtext_markdown_map_t *map) |
| Like rmgui_richtext_markdown, with an optional map of ordered, coalesced runs covering the entire source. | |
| int | rmgui_richtext_markdown_mapped_ex (const char *source, size_t length, int base_px, const rmgui_richtext_markdown_options_t *options, rmgui_richtext_markdown_t *out, rmgui_richtext_markdown_map_t *map) |
| Like rmgui_richtext_markdown_mapped, parsed with options (NULL is the default grammar). | |
Caller-owned, read-only styled text.
No widget operation allocates. All offsets are UTF-8 bytes. Borrowed text/fonts/arrays stay immutable from layout through hit/input/paint. Re-layout after changing any of them. Status functions return 0 or -1; refusal leaves outputs/storage unchanged. NULL required pointers refuse (void painters simply do nothing). Capacities count elements, text capacities count bytes including the terminating NUL. Integer geometry saturates at INT_MAX; alignment division truncates toward zero. Fonts are selected, not synthesized; absent variants use regular. Font CPU glyph caches retain their normal font.h preparation contract.
| #define RMGUI_RICHTEXT_BOLD 1u |
| #define RMGUI_RICHTEXT_ITALIC 2u |
| #define RMGUI_RICHTEXT_MONO 4u |
| #define RMGUI_RICHTEXT_UNDERLINE 8u |
| #define RMGUI_RICHTEXT_STRIKE 16u |
| #define RMGUI_RICHTEXT_COLOR 32u |
| #define RMGUI_RICHTEXT_BACKGROUND 64u |
| #define RMGUI_RICHTEXT_COPY 1 |
Copies selected UTF-8 plus NUL, writes byte length.
No clipboard API calls. Host handles ACTION value RMGUI_RICHTEXT_COPY by invoking this function.
| #define RMGUI_RICHTEXT_MARKDOWN_STRICT_LINKS 1u |
Strict link candidates.
The label and the destination must each be nonempty. The destination ends at the first ) that balances the opening (: a ( inside it opens a level, a backslash-escaped parenthesis does not count, and the escaped byte stays in the target. Any byte of ASCII 32 or below in the destination, escaped or not, rejects the candidate, and a carriage return ends the candidate before it can close. A rejected candidate is literal text: the [ is kept as an ordinary byte and scanning continues after it, so nothing of the label syntax is hidden. The link target is the borrowed source bytes between the opening and balancing parentheses.
| #define RMGUI_RICHTEXT_MARKDOWN_LABEL_STYLES 2u |
Emphasis, bold, mono and backslash escapes are recognized inside a valid link label, with the same delimiter rules as elsewhere, confined to the label.
Each styled piece carries the link id and target of its link and keeps its style flags together with RMGUI_RICHTEXT_UNDERLINE. A [ inside a label is literal: links never nest. Delimiters and escapes are hidden runs in the map. Without this flag the label is emitted verbatim as one underlined span.
| #define RMGUI_RICHTEXT_MARKDOWN_LITERAL_BULLETS 4u |
A line that starts with - or * emits the four bytes U+2022 followed by one ASCII space into the display text, with no paragraph bullet decoration (bullet stays zero and no indent column is reserved), so layout, search, selection and copy all see the same bytes.
The two source marker bytes are a hidden run; the four generated display bytes belong to no run and sit between that hidden run's display_start and the display_start of the next run, so every later visible run maps by its own display_start.
| #define RMGUI_RICHTEXT_MARKDOWN_HEADING_TEXT 8u |
A heading needs at least one byte after its marker and ASCII space: # alone or # alone on a line stays literal.
Without the flag such a line hides its marker.
| #define RMGUI_RICHTEXT_MARKDOWN_CHAT_INLINE 16u |
The inline grammar of the Automugen Chat message module, replacing the default inline rules; STRICT_LINKS and LABEL_STYLES then have no further effect.
Block rules (headings, bullets) are unchanged and come from the other flags. Inline scans work within one line. A carriage return ends every scan (code, label, destination) and drops all open emphasis frames, which become literal; a link label is its own scope for emphasis.
Delimiters, escapes and link syntax are hidden runs in the map.
| #define RMGUI_RICHTEXT_MARKDOWN_MARKER_TEXT 32u |
A heading marker or a bullet marker (- or * ) needs at least one byte after its ASCII space that is not a carriage return or line feed.
- , * before a line feed, # and # before a carriage return stay literal, while - (one more space) is a bullet whose text is one space. It applies to layout and literal bullets and to headings, with or without HEADING_TEXT. A heading's size applies up to the first carriage return on its line; the rest of the line, carriage return included, is parsed as ordinary text at the base size.
| #define RMGUI_RICHTEXT_MARKDOWN_FLAGS 63u |
All defined RMGUI_RICHTEXT_MARKDOWN_* flag bits.
| typedef void(*) rmgui_richtext_inline_fn(void *, rmgui_target_t *, rmgui_rect_t box, rmgui_rect_t clip, unsigned glyph) |
Inline spans contain exactly one UTF-8 codepoint (typically U+FFFC).
The hook paints the supplied box through the supplied target and clip; it is called only for visible lines and must not allocate. NULL hook leaves its reserved box empty. Copy preserves the replacement codepoint.
| int rmgui_richtext_style | ( | const rmgui_style_ext_resolved_t * | , |
| const rmgui_richtext_style_t * | defaults, | ||
| rmgui_richtext_style_t * | out ) |
Optional resolved extension names: font-size, line-gap, text, background, selection, link.
Missing properties retain defaults; wrong kind refuses.
| int rmgui_richtext_prepare | ( | const rmgui_ui_t * | , |
| const rmgui_richtext_view_t * | ) |
Stage the current layout's text before recording.
CPU targets need no staging. Inline callbacks are not invoked; their resources are the host's responsibility. Returns 0 on success or -1 on error.
| int rmgui_richtext_draw | ( | const rmgui_ui_t * | , |
| const rmgui_richtext_view_t * | , | ||
| rmgui_rect_t | ) |
Draw with the current layout's fonts and style and the optional inline callback.
Returns -1 for invalid arguments, otherwise 0; paint failures latch on the target.
| int rmgui_richtext_layout | ( | const rmgui_richtext_t * | , |
| const rmgui_richtext_document_t * | , | ||
| const rmgui_richtext_fonts_t * | , | ||
| const rmgui_richtext_style_t * | , | ||
| int | width, | ||
| rmgui_richtext_layout_t * | cache ) |
A document's spans exactly partition text; paragraphs do too, end at a newline or document end.
Empty documents may use NULL arrays/count zero. width > 0. Two-pass transactional layout uses the existing text breaker. Caller cache holds ALL lines; insufficient capacity refuses unchanged.
| int rmgui_richtext_init | ( | rmgui_richtext_t * | , |
| const rmgui_richtext_layout_t * | ) |
Bind resets selection/capture/scroll; no cache/text copies.
| int rmgui_richtext_hit | ( | const rmgui_richtext_layout_t * | , |
| int | x, | ||
| int | y, | ||
| rmgui_richtext_hit_t * | out ) |
Coordinates relative to the content origin, including scroll already.
Outside positions clamp to the nearest row and UTF-8 caret boundary. Exact midpoint ties choose the following boundary.
| int rmgui_richtext_select | ( | rmgui_richtext_t * | , |
| size_t | anchor, | ||
| size_t | caret ) |
| int rmgui_richtext_copy | ( | const rmgui_richtext_t * | , |
| char * | , | ||
| size_t | capacity, | ||
| size_t * | length ) |
| rmgui_input_result_t rmgui_richtext_input | ( | rmgui_richtext_t * | , |
| rmgui_rect_t | , | ||
| const rmgui_input_t * | ) |
Pointer drag selection, link click activation (value=link_id), hover cursor; focus-gated arrows/home/end/up/down/page keys, Shift extension, Ctrl/Meta A/C.
Optional host.clipboard_set receives selected bytes directly on COPY; callback refusal reports REFUSED without changing selection. Cursor requests also call host.request_cursor when supplied. Do not reenter from callbacks. Wheel and keyboard caret movement clamp/adjust scroll_y. The host may also set scroll_y directly (painters clamp it). Disabled press returns REFUSED.
| int rmgui_richtext_prepare_to | ( | const rmgui_richtext_t * | , |
| rmgui_target_t * | ) |
| void rmgui_richtext_paint_to | ( | rmgui_target_t * | , |
| const rmgui_richtext_t * | , | ||
| rmgui_rect_t | rect, | ||
| rmgui_rect_t | clip, | ||
| rmgui_richtext_inline_fn | , | ||
| void * | ) |
Binary-searches first visible cached line, then visits only visible lines and their spans.
Paint is O(log lines + visible bytes/spans), not total text. RECORD requires caller-prepared glyphs for every used font/size, including bullet U+2022. Inline hooks follow the same target resource contract.
| void rmgui_richtext_paint | ( | rmgui_fb_t * | , |
| const rmgui_richtext_t * | , | ||
| rmgui_rect_t | rect, | ||
| rmgui_rect_t | clip, | ||
| rmgui_richtext_inline_fn | , | ||
| void * | ) |
| int rmgui_a11y_from_richtext | ( | const rmgui_richtext_t * | , |
| size_t | span, | ||
| const char * | name, | ||
| rmgui_a11y_record_t * | out ) |
span=SIZE_MAX builds TEXT; a link span builds LINK.
Name is borrowed.
| int rmgui_a11y_richtext_selection | ( | const rmgui_richtext_t * | , |
| size_t | start, | ||
| size_t | end, | ||
| rmgui_rect_t * | rects, | ||
| size_t | capacity, | ||
| size_t * | count ) |
| int rmgui_richtext_a11y_action | ( | rmgui_richtext_t * | , |
| size_t | span, | ||
| rmgui_input_result_t * | out ) |
Accessibility PRESS on a link span; other host actions use input/select.
| int rmgui_richtext_markdown | ( | const char * | source, |
| size_t | length, | ||
| int | base_px, | ||
| rmgui_richtext_markdown_t * | out ) |
| int rmgui_richtext_markdown_mapped | ( | const char * | source, |
| size_t | length, | ||
| int | base_px, | ||
| rmgui_richtext_markdown_t * | out, | ||
| rmgui_richtext_markdown_map_t * | map ) |
Like rmgui_richtext_markdown, with an optional map of ordered, coalesced runs covering the entire source.
Set runs and capacity; count is written on success. NULL runs is valid for an empty map; NULL map skips mapping. All buffers must be disjoint. On failure, neither output is modified.
Pass a caller-owned rmgui_richtext_markdown_map_t with runs and capacity to collect source-to-display ranges while parsing. Pass NULL for the same behavior as rmgui_richtext_markdown. Success sets count; failure leaves the document, map, and all buffers unchanged. A capacity of length runs always suffices: each run contains at least one source byte. Empty input needs no runs.
Runs cover the source in order, with no gaps or overlap. Adjacent ranges of the same kind are coalesced even if their styles differ. Visible ranges copy bytes verbatim: for a source byte p inside a visible run, its display byte is display_start + (p - source_start). Hidden ranges have display_length == 0; their display_start is the insertion boundary, not a displayed byte. Escapes hide the backslash, links hide the brackets, parentheses and destination, and formatting, heading and list markers are hidden when recognized. Literal unmatched syntax keeps its original bytes. The generated list bullet is a layout decoration, not a display byte.
To highlight a source range, intersect it with the visible runs and project only those intersections. In [a](https://host/b)b, the b inside the destination is hidden and the final b maps to byte 1 of ab.
| int rmgui_richtext_markdown_mapped_ex | ( | const char * | source, |
| size_t | length, | ||
| int | base_px, | ||
| const rmgui_richtext_markdown_options_t * | options, | ||
| rmgui_richtext_markdown_t * | out, | ||
| rmgui_richtext_markdown_map_t * | map ) |
Like rmgui_richtext_markdown_mapped, parsed with options (NULL is the default grammar).
All inputs, outputs and the refusal contract are those of rmgui_richtext_markdown_mapped, and invalid options refuse before any output is written. Escapes, UTF-8 validation, the nonempty and no-leading-or-trailing space delimiter rules, one-based link ids and the source map invariants (runs cover the source in order, with no gaps or overlap; visible runs are verbatim; hidden runs have zero display length) are unchanged. Hidden delimiters and destinations never reach the display text, so selection and copy cannot expose them.