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

Module map

Directory Public surface
rmgui/core Geometry, framebuffer, drawing, masks, images, text, style codecs/palettes, skins, layout, scroll, focus, input and paint
rmgui/elements Widgets, chart painters and dock tree
rmgui/effects Motion, layers, particles, backdrops, patterns and emboss
rmgui/gpu CPU/record targets and native rendering; gpu_sokol.h integrates a host-owned sokol_gfx pass
rmgui/mesh Bounded GLB scenes, animation, UV instances and CPU cel painting
rmgui/rmgui.h Umbrella header, except gpu_sokol.h

Modules

The library is a set of modules, listed with their sources, headers and declared dependencies in modules.d/<name>.mk: base (geometry, input events, the framebuffer, blended primitives, masks, gradients), motion, text (the bytes-in font, measuring, line breaking), render (the paint-target IR and what it replays), path (caller-owned Q16 curves and stroked geometry; depends on base render), style, style_kdl, style_json, recipe (caller-owned paint data; depends on base render style), skin, ui (face and scroll painters), layout, one module per element (button, field, dock, charts, ...), a11y (semantic snapshots, element adapters and host actions), the GPU modules (gpu_sokol, gpu_mesh, gpu_cloud_orb, gpu_native) and mesh. Optional tracks provides style-independent property animation; tracks_style adds schema/extension projections and depends only on tracks style. Directories group files for reading; modules are what depend on each other (render replays glyphs, so the font cache lives in text and its drawing in render; the directories do not show that). make check-modules fails when an object calls into a module its entry does not declare, when the declared graph has a cycle or an unknown name, or when ckdl is reached from a module that does not list it.

Using less costs nothing to configure:

  • A program links only what it calls. librmgui.a holds one object per source and the library is built with -ffunction-sections -fdata-sections, so a linker takes only the members a program refers to, and with -Wl,--gc-sections (-Wl,-dead_strip on macOS) only the functions. A program that draws a rounded rect links no layout, style, KDL or mesh code (make check-modules links one against the full archive and asserts it). The windows-x86_64 profile omits -fdata-sections: GCC for mingw-w64 would otherwise store every zero-initialised static as zeros in the PE image.
  • make native-core builds build/native-core/ with geometry, paths, drawing, text, style, skin, scrolling, layout and focus, without stock widgets. A host can supply any repeating tile to rmgui_backdrop_tile. Use premultiplied RGBA for translucent pixels. Zellige and hatch are presets in the optional pattern module.
  • Add a stock widget to the foundation by selecting its module and dependencies: make native N=build/with-button RMGUI_SELECT='$(RMGUI_CORE) button'. For less than the foundation, select individual modules, e.g. make native N=build/text-only RMGUI_SELECT='base text'. Give each selection its own output directory. Plain make native still builds the full package.
  • No module changes the layout of a type another module declares, and no macro selects a struct member: every selection is the same ABI, so a program built against the full package links against any archive holding the modules it uses. Capacity belongs to the caller, as storage the caller sizes (see the layout kernel), not to a build option.

New modules add modules.d/<name>.mk (appending to RMGUI_MODULES and defining RMGUI_MOD_<name>_SRCS, _HEADERS, _PRIVATE, _DEPS and, for tests, modules.d/tests/<name>.mk).

Typed elements

Use a shared rmgui_ui_t for one batch of draws. It borrows the destination, damage clip, theme, font, scale and optional skins. The element header declares its typed draw API; include ui.h for the optional button, choice and slider views, or rmgui.h for all installed modules.

/* Keep this with the rest of the application's UI state, across frames. */
rmgui_button_view_t apply = {.label = "Apply"};
/* Route an event to the arranged button, then draw its current state. */
rmgui_input_result_t result = rmgui_button_event(&apply, box, &event);
rmgui_ui_t ui = {.target = &target, .font = &font, .clip = damage};
if (rmgui_button_draw(&ui, &apply, box) != 0) {
/* Invalid arguments or style. */
}
A zero-initialized button with an optional borrowed, NUL-terminated label.
Definition ui.h:11
An element input function's report: what happened, and how the host routes the next events.
Definition input.h:229
Borrowed settings for a batch of typed controls.
Definition ui_context.h:16
int rmgui_button_draw(const rmgui_ui_t *ui, const rmgui_button_view_t *button, rmgui_rect_t box)
Draw the button with its current style.
rmgui_input_result_t rmgui_button_event(rmgui_button_view_t *button, rmgui_rect_t box, const rmgui_input_t *event)
Route one event to the button at box; the host owns focus and capture routing.
  • Use the existing state type directly when it already carries the element's configuration. When a view groups a label, data or style with state, it borrows that data; keep it alive as long as it is used.
  • The host still owns arranged rectangles, text and selection storage, event routing and elapsed time. Indexed widgets and charts borrow data rather than copying it. Docking is an arrangement API; draw the controls it places.
  • Built-in controls take their theme from the context. Widgets with application-registered extension classes still take the relevant resolved styles explicitly. Use the same metrics for layout, input and drawing.
  • Font preparation is separate from painting. For a recorded target, call the relevant *_prepare operations before recording commands. Plain CPU text needs no prepare pass; shaped text can require it on either target. Check the target itself for paint errors.
  • The lower-level *_paint_to APIs remain available for custom styling and composition.

Composed widgets

combo.h, datepicker.h, colorpicker.h, toast.h and richtext.h are independent element modules. Their painters accept caller-resolved extension classes; they add no built-in style classes. The Widgets showcase composes them with a 5,000-entry quest selector and an editable Markdown help pane.

  • A combo borrows an existing single-line field, immutable entry strings, match indices and a separate committed-text buffer. Matching is bytewise, locale-free prefix/substring matching unless the caller supplies a matcher.
  • Calendar years are Gregorian 1–9999. Serial days are relative to 1970-01-01; localization, week start and today belong to the caller. A completed range refuses if any date inside it is disabled.
  • Colour conversion uses encoded RGBA, without gamma correction. HSV units are tenths of a degree and tenths of a percent; RGB–HSV–RGB differs by at most one byte per channel. The host handles eyedropper requests.
  • Toasts borrow FIFO slots and message strings. Only visible, unhovered notifications age; queued items wait. Stack extents fit signed Q16 pixels (32767 pixels). Reduced motion snaps the caller-owned reflow springs.
  • Rich text borrows UTF-8, styled spans, paragraphs, fonts and a complete caller-owned line cache. Selection/copy offsets are UTF-8 bytes. Its small Markdown helper is intentionally not CommonMark; source and output buffers must remain disjoint.

Capacity failures refuse instead of allocating or truncating output. Counts returned in input events fit int; field byte ceilings remain those of field.h. See the public header contracts for the operation's transactional boundaries.

Dashboard controls

splitter, tooltip, toggle, spinbox, toolbar and menubar are separate modules. The Controls dashboard composes nested panes, a field-backed integer and fixed-point editor, an overflowing toolbar and a forty-tab strip.

  • Splitters borrow pane constraints, sizes and scratch. Resizing preserves collapsed panes and distributes flexible space proportionally; integer remainders go to earlier eligible panes. Hosts supply independent state for nested splitters and translate resize-cursor requests through host services.
  • Tooltip groups arbitrate one visible tooltip and advance only with supplied millisecond deltas. Keep group/state addresses stable while associated. Placement flips/shifts inside host bounds; rich hooks share the paint target.
  • Toggles animate through integer motion springs; reduced motion is immediate. Spin boxes retain committed integer units of 10^-decimals while the real field holds an editable draft. Re-layout after input/value changes. Enter commits valid text; Escape and invalid commits restore the committed value.
  • Toolbar items, geometry and overflow models are caller storage. Adjacent equal nonzero groups move together. Menubars borrow top-level and popup arrays; Alt mnemonics and arrow traversal share generic context-menu input. Context menus require explicit item models: labels, command values, disabled bytes and separator placement belong to the caller.
  • rmgui_tab_strip_t extends the base tab model with caller-owned label, close-geometry and menu arrays. Close/reorder events request host model changes; they never mutate identities. Rebind after applying those changes. Result indices fit int; geometry extents fit int. Storage exhaustion refuses instead of allocating. Painter styles are caller-resolved extension classes, without adding built-in classes.

Indexed models

model.h borrows indexed access, stable-ID lookup and optional prefix-height callbacks; fixed heights need no prefix array. Call the field-level row mark functions after editing data, then synchronize retained selection by identity. list_row.h retains the independently usable row element and its painters; its virtual list view paints visible model rows through those same painters, with selection/focus in caller-owned view state. tree.h and table.h share that visible window and row implementation. Selection uses caller-owned hash slots (two slots per selected identity, or one slot for a single identity); exhaustion refuses the entire selection change. Tree callbacks own the visible preorder projection and atomically load or refuse children. Supply sibling positions/counts for tree accessibility. Bulk expansion returns 0 when complete, +1 with an explicit committed callback count if work stops at its budget or a later callback refuses, and -1 only before any mutation (outputs unchanged). A +1 result is not completion. Table column arrays own widths, constraints and optional visual order; sort and reorder results ask the caller to update its data, not a reconciler. Models use size_t row indices, uint64 identities except UINT64_MAX, and signed 64-bit cumulative pixel heights. Accessibility metadata fits uint32. Resolve user-registered tree/table/header extension classes, then convert their eight named properties with rmgui_model_style; no builtin class is added. The Models showcase exposes lazy loading, live insertion/removal, selection, keyboard/type-ahead input, header resizing/sorting and accessibility actions.