RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
Layout, text and accessibility

Layout and snapshot storage

Attribute Rule
Storage Caller-owned arrays, including two snapshot buffers. Sizes are not compile-time limits.
Borrowed data Grid columns stay immutable until reset; text and retained lines outlive every snapshot that uses them.
Refusal Exhausted records or scratch return -1 without changing outputs or replacing a published snapshot.
Invalidation Setters invalidate affected declarations and ancestor measurements. Setting text invalidates even when the pointer is unchanged. Invalid setters do not mutate.
Damage Repaint the scene clipped to kernel.damage[0..damage_count), not just the changed node. No changes means zero rectangles; exhaustion collapses to one union and sets damage_collapsed.

RMGUI_LAYOUT_STORAGE(arena, 3, 0, 0, 0, 128, 256, 8) reserves three nodes, no grid/scroll/overlay records, 128 integer work slots, 256 text scratch bytes and eight damage rectangles. Initialize with rmgui_layout_init(&kernel, &arena.storage) and check its result.

Layout contract · Layout storage / damage in the showcase

Value types across modules

Three cross-module edges to know. core/image.h includes core/layout.h to paint published IMAGE artwork. core/layout.h includes effects/layer.h and embeds its rmgui_layer_transform_t / rmgui_layer_shadow_t by value in every layout node's visual record — those two types are shared value types, part of the layout ABI wherever they are declared. Size layer and layout storage from matching headers, using sizeof or the storage macros rather than hard-coded byte counts. effects/element_motion.h includes core/style.h: it turns a class's resolved record (rmgui_style_resolved_t) into a layer transform and shadow, and a dragged element's sway into a layer rotation. rmgui.h includes core, then elements, then effects.

Text flow and shaping

Text flow has no library text-length ceiling. rmgui_text_flow_line and rmgui_text_flow_line_prefix take char *scratch, size_t scratch_capacity before the output line. Fallback measurement needs enough disjoint caller scratch for the remaining paragraph through its next newline plus NUL; insufficient scratch returns -1 with the output unchanged. An exact prefix provider needs no scratch (NULL, 0), including for layout ellipsis. Retained paragraph line-array exhaustion likewise refuses rather than truncating. Text fields retain their separate editable-buffer capacity.

Optional bidi, fallback and shaping modules provide the explicit text_shape.h pipeline; legacy font/text calls are unchanged. Unicode 17.0.0 UAX #9 resolves embeddings, isolates, brackets and per-line visual ordering. Fonts are borrowed in priority order, with complete-cluster coverage, optional sticky preference and a host resolver. rmgui_shaper_t accepts a borrowed UTF-8 run, script, direction and language and returns face glyph ids, logical byte clusters and integer positions into caller storage. The built-in adapter preserves Latin cmap/kerning rounding; Arabic joining and complex scripts need a host shaper such as HarfBuzz, which is not bundled.

rmgui_text_options_t borrows all workspace arrays. Capacity exhaustion returns -1 without publishing a result; workspace contents may change even on refusal. Prepare shaped layouts for their CPU/record target before painting; shaping and painting allocate nothing, while glyph preparation uses the existing raster cache. Carets carry boundary affinity; logical arrows skip whole clusters and visual arrows follow reordered edges. Selection returns caller-owned lists of visual rectangles, while offsets remain logical UTF-8 bytes. The optional a11y_text module exposes the same mapping through a11y_shaped_text.h. Fields opt in through rmgui_field_t.text_options and borrow selection-rectangle storage; hint and IME composition use a separate auxiliary workspace. The 65,534-byte field ceiling remains. Check every layout result: a refused shaping call leaves the result struct unchanged but invalidates borrowed workspace content, including previously returned shaped results. The SHAPING showcase generates its RTL box font in caller storage and demonstrates fallback, mirroring and a host fi ligature adapter.

Use rmgui_layout_set_font(&kernel, &font) for the built-in font, or rmgui_layout_set_font_metrics(&kernel, &metrics) to share a caller-owned cache between measurement and painting. Custom providers install their measure callback, optional prefix callback, default userdata and optional paint cache together with rmgui_layout_set_text_binding. Paragraph painting shares the cache's 1024 exact pair advances and 256 codepoint-to-glyph tokens with measurement instead of repeating font-table walks; retained line breaks still avoid paint-time wrapping. rmgui_font_draw_with_metrics and its _to form opt standalone runs into the same cache. Pair lookups probe at most 16 slots before eviction; tokens are direct mapped. Eviction recomputes exact values, never changes output or allocates. The context is single-owner through measurement and painting, must outlive snapshots using it, and must be reinitialized after reinstalling a font. Font/size changes invalidate cached values automatically. Build consumers with matching headers.

Accessibility data

<rmgui/a11y.h> provides plain, deterministic accessibility data for a host bridge to AT-SPI, UIA, NSAccessibility or another platform. It makes no OS calls and allocates no memory. Metadata carries roles, borrowed UTF-8 names, descriptions/value text, integer numeric ranges, states, orientation, set position, live-region politeness and borrowed node-ID relations.

Opt a layout into semantic publication by supplying two disjoint a11y_records banks in rmgui_layout_storage_t, each with node_capacity records. Existing storage without these banks remains valid; attachment refuses until both are supplied. rmgui_layout_set_a11y attaches a borrowed source record or detaches with NULL. Arrange copies it transactionally into the snapshot; source records may be rewritten immediately before calling the setter, but strings and relation arrays must outlive snapshots using them. Metadata-only changes do not invalidate measurements or pixel damage. Arrange after layout focus changes before reading semantic focus.

rmgui_a11y_walk visits annotated visible nodes in paint/reading order, flattening unannotated containers; parent IDs and ordered visits define children and siblings. Hidden/unarranged nodes and semantic HIDDEN subtrees are excluded. Rectangles are clipped device coordinates; the host adds its screen-origin transform. Focus and hit queries use that same snapshot. Element builders derive supported states/values from public element state. rmgui_a11y_perform dispatches host actions through caller bindings and public element operations, or reports unsupported. Refresh element records and layout after mutation. Text-range/line helpers expose UTF-8 byte offsets, not UTF-16 indices, from a current field layout, including offscreen rows. The host owns platform registration, announcements and event delivery.

Docking

<rmgui/dock.h> arranges docked and floating panels. The host supplies storage, labels, content, eligibility, persistence and native windows.

Two split panels with the left client's 4:3 content centred in its allocation
uint64_t ids[6];
if (rmgui_dock_init(&dock, nodes, 3, ids, 6, aspects, 2) ||
rmgui_dock_add(&dock, 101, 0, RMGUI_DOCK_TAB, 0, (rmgui_rect_t){0}) ||
rmgui_dock_add(&dock, 102, 101, RMGUI_DOCK_RIGHT, 0, (rmgui_rect_t){0}) ||
rmgui_dock_aspect(&dock, 101, 4, 3) ||
rmgui_dock_arrange(&dock, viewport, 24, 28, 6, (rmgui_size_t){80, 60}))
return -1;
for (uint64_t id = 101; id <= 102; ++id) {
if (rmgui_dock_window(&dock, id, &panel) ||
rmgui_dock_node(&dock, panel.group, &group) ||
rmgui_dock_content_fit(&dock, id, panel.content, &fit))
return -1;
paint_panel(fb, group.strip, panel.content, fit, id); /* Host painter */
}
int rmgui_dock_window(const rmgui_dock_t *self, uint64_t id, rmgui_dock_window_t *out)
Resolve ID's membership/geometry; 0 on success, -1 for missing ID.
int rmgui_dock_add(rmgui_dock_t *self, uint64_t id, uint64_t target, rmgui_dock_placement_t placement, size_t index, rmgui_rect_t frame)
Add a nonzero unique ID.
@ RMGUI_DOCK_RIGHT
Definition dock.h:22
@ RMGUI_DOCK_TAB
Definition dock.h:23
int rmgui_dock_content_fit(const rmgui_dock_t *self, uint64_t id, rmgui_rect_t client, rmgui_rect_t *out)
Fit the window's locked viewport centrally inside its actual visible client box, after the caller app...
int rmgui_dock_init(rmgui_dock_t *self, rmgui_dock_node_t *nodes, size_t node_capacity, uint64_t *ids, size_t id_capacity, rmgui_dock_aspect_t *aspects, size_t window_capacity)
Reset an empty root using caller-owned nodes, aspects[window_capacity], and ids[id_capacity].
int rmgui_dock_node(const rmgui_dock_t *self, size_t slot, rmgui_dock_node_t *out)
Copy occupied node at slot; ids borrows model storage and is valid only until the next model mutation...
int rmgui_dock_aspect(rmgui_dock_t *self, uint64_t id, uint32_t width, uint32_t height)
Lock one ID's content viewport to width:height; 0:0 unlocks.
int rmgui_dock_arrange(rmgui_dock_t *self, rmgui_rect_t viewport, int title_height, int tab_height, int splitter_width, rmgui_size_t minimum)
Arrange docked tree inside viewport and each float intersected with it; nonpositive extents become ze...
Caller-owned per-window aspect-lock storage, initialized by dock_init.
Definition dock.h:106
A node's retained identity and latest arranged geometry.
Definition dock.h:64
rmgui_rect_t strip
Definition dock.h:72
Retained model and geometry; fields are read-only to callers.
Definition dock.h:115
One window's membership, allocated content before chrome, per-ID aspect lock, and latest arranged tab...
Definition dock.h:85
size_t group
Definition dock.h:86
rmgui_rect_t content
Definition dock.h:89
Half-open rectangle [x, x + w) by [y, y + h) in logical framebuffer pixels.
Definition geom.h:12
Width and height in logical framebuffer pixels.
Definition geom.h:20
Attribute Rule
Identity Nonzero stable ID; unique docked-tab or floating-group membership.
Header A single window gets a title_height strip and zero tab rect; a group gets a tab_height strip. Paint only the one strip.
Aspect 0:0 unlocks. Fit the largest whole multiple of the reduced ratio inside the available client, centred; return an empty fit if no step fits.
Float frame Use rmgui_window_frame_drag for movement and sizing; apply with rmgui_dock_float_frame.
Drag Hover previews a destination; commit refuses a stale model. Cancel leaves membership, order, ratio and frame unchanged.
Placement TAB merges, an edge splits a docked group, outside floats to a visible frame. An empty root offers TAB. A group cannot split against itself.
Refusal Invalid IDs, capacity, placement or geometry do not mutate the model. Removing the last tab collapses its group and parent split.

Try the DOCKING page in the showcase. For group dragging, placement, storage and edge cases, see the dock contract.

Capacity

Storage belongs to the host; painters and element kernels do not allocate it. Docking borrows nodes, per-node tab IDs and per-window aspect records. Tabs borrow identities, saved-focus entries and disabled bytes; choice groups borrow selection bytes. Window catalogs borrow declarations and output arrays for windows, taskbar cells/labels/separators and tray cells. Their capacities are explicit, and exhaustion refuses without changing published state. List rows and dropdowns retain only indexed state, not collection data; their counts, like tab and choice counts, fit the input result's int index. Flame charts walk the supplied frame array without a fixed depth bound; parents use int32_t. Axis ticks stream without a scratch array.

Backdrop palettes borrow stop arrays; particle emitters borrow color arrays and use caller-owned particle slots. Patterns render into caller surfaces. Layer surfaces use caller-chosen dimensions and an explicit device-pixel blur allowance; sampling coordinates must fit unsigned 32-bit Q16. Skin declarations borrow sheet names; asset decoding writes names and entries into caller arenas. Mesh models and poses use caller-owned, max_align_t-aligned contiguous arenas sized by the measure and instance-size queries; loading and initialization receive explicit byte capacities. Mesh input budgets are caller supplied; zero budgets select the corresponding integer representation ceilings. CPU mesh scratch is sized for the model and target dimensions.