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

The host supplies an RGBA8 fb, device-pixel box and clip, and the inputs listed below. The snippets target v0.14.4. The rich-text image was captured with v0.13.0; the other images were captured with v0.11.2. Set up the library.

Button

A Save changes button in its hover state
rmgui_input_result_t result = rmgui_button_input(button, box, event);
if (rmgui_style_resolve(theme, RMGUI_STYLE_CLASS_BUTTON, button->states,
17, 100, &style) != 0)
return -1;
rmgui_button_paint(fb, font, &style, box, clip, "Save changes");
rmgui_input_result_t rmgui_button_input(rmgui_button_t *self, rmgui_rect_t rect, const rmgui_input_t *in)
Applies one event to the button whose arranged rect is rect.
void rmgui_button_paint(rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_style_resolved_t *rs, rmgui_rect_t rect, rmgui_rect_t clip, const char *label)
Paints the button face (rs->background, with rs->overlay_disabled composited over it under DISABLED,...
@ RMGUI_INPUT_RESULT_ACTIVATE
the element was activated (value: element-defined, 0 if none)
Definition input.h:182
An element input function's report: what happened, and how the host routes the next events.
Definition input.h:229
rmgui_input_result_kind_t kind
Definition input.h:230
One class at a state, font size and UI scale; unused roles are zero.
Definition style.h:304
@ RMGUI_STYLE_CLASS_BUTTON
Definition style.h:27
int rmgui_style_resolve(const rmgui_style_snapshot_t *snapshot, rmgui_style_class_t class_id, rmgui_style_states_t states, int font_px, int scale_percent, rmgui_style_resolved_t *out)
Resolve a validated snapshot at positive font_px and scale_percent 1..400; invalid inputs return -1 w...
Host supplies How to use it
button Zero-initialize once; retain it across events.
event Route pointer or focused keyboard input. Use NULL to repaint only.
theme, font A validated style snapshot and an initialized font.
Result 1: run the save action. 0: no activation. -1: style refused.

Button contract

Slider

A horizontal slider at 65 with three marked positions
const int64_t detents[] = {25, 50, 75};
if (rmgui_style_resolve(theme, RMGUI_STYLE_CLASS_SLIDER, slider->states,
17, 100, &style) != 0)
return -1;
rmgui_slider_paint(fb, &style, box, clip, slider, detents, 3);
void rmgui_slider_paint(rmgui_fb_t *fb, const rmgui_style_resolved_t *rs, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_slider_t *self, const int64_t *detents, size_t detent_count)
Paints the slider arranged at rect: the track (rs->background, track_w wide, rs->track_height tall,...
@ RMGUI_STYLE_CLASS_SLIDER
Definition style.h:28
Attribute Value
Range / initial value 0–100 / 65
Detents Draw marks; they do not snap input.
Input Initialize once with rmgui_slider_init(slider, 0, 100, 65); retain the slider and route events through rmgui_slider_input.

Slider contract

Chart

A filled time-series chart rising over six seconds
if (!rmgui_chart_series_count(series)) {
const int32_t samples[] = {12, 32, 24, 61, 53, 78, 68};
rmgui_chart_series_init(series, slots, 7);
for (uint32_t i = 0; i < 7; ++i) {
if (rmgui_chart_series_push(series, i * 1000, samples[i]) != 0)
return -1;
}
}
rmgui_chart_plot_samples(fb, box, clip, view, chart_style, series, 0,
rmgui_chart_axis_paint(fb, box, clip, view, chart_style, font, 13);
void rmgui_chart_axis_paint(rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, rmgui_font_t *font, int font_px)
Paints the grid of view inside rect, with L = rmgui_font_line_height(font_px):
@ RMGUI_CHART_PLOT_AREA
Definition chart_plot.h:42
void rmgui_chart_plot_samples(rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_chart_view_t *view, const rmgui_style_resolved_t *rs, const rmgui_chart_series_t *series, int series_index, unsigned flags)
Paints series (every sample, oldest first) into the window view with the roles of rs->series[series_i...
size_t rmgui_chart_series_count(const rmgui_chart_series_t *s)
Return the sample count, at most capacity, or zero if s is null.
int rmgui_chart_series_push(rmgui_chart_series_t *s, uint32_t t_ms, int32_t value)
Append a sample, overwriting the oldest if the ring is full.
void rmgui_chart_series_init(rmgui_chart_series_t *s, rmgui_chart_sample_t *slots, size_t capacity)
Bind an empty series to capacity caller-owned slots.
Attribute Value
X / Y Milliseconds / caller-defined value units
series, slots Zero-initialized series and caller-owned 7-slot ring.
view Set v0 = 0, v1 = 100, and t1 = 6000 (milliseconds).
chart_style Resolve RMGUI_STYLE_CLASS_CHART; index 0 selects its first series color.
RMGUI_CHART_PLOT_AREA Fill down to the baseline, then draw the line.

Series contract · Plot contract

Rich text

Hamlet’s opening lines in a scrollable text view

The host supplies markdown and markdown_len, the bytes and length of a loaded UTF-8 document. The demo reads hamlet.md (the “To be, or not to be” soliloquy from Hamlet, Act III, Scene I) as a separate asset.

if (!rich->layout) {
if (rmgui_richtext_markdown(markdown, markdown_len, style->font_px, parsed))
return -1;
if (rmgui_richtext_layout(NULL, &parsed->document, fonts, style,
box.w, layout))
return -1;
if (rmgui_richtext_init(rich, layout) != 0)
return -1;
}
rmgui_richtext_paint(fb, rich, box, clip, NULL, NULL);
int rmgui_richtext_init(rmgui_richtext_t *, const rmgui_richtext_layout_t *)
Bind resets selection/capture/scroll; no cache/text copies.
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.
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_richtext_markdown(const char *source, size_t length, int base_px, rmgui_richtext_markdown_t *out)
int font_px
Definition style.h:306
Host supplies What it stores
markdown, markdown_len Loaded UTF-8 bytes and their count, excluding any trailing NUL.
rich Zero-initialize once; retain it across paints and input.
parsed Separate output text, span, and paragraph buffers. Link targets borrow markdown.
fonts, style Real font variants and paint metrics. Missing variants use regular.
layout Caller-owned line array sized for the whole document. Pass NULL as the first argument to use the default text options.
Lifetimes Keep source, parsed buffers, fonts, and line storage alive and unchanged through paint and input.

For bounded views, use rmgui_scroll_t for the scrollbar and keep its vertical offset in sync with rich->scroll_y. Route scrollbar gestures before text selection. Pass the actual viewport width (excluding the scrollbar) to layout.

Rich-text and Markdown contracts