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
17, 100, &style) != 0)
return -1;
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};
17, 100, &style) != 0)
return -1;
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
const int32_t samples[] = {12, 32, 24, 61, 53, 78, 68};
for (uint32_t i = 0; i < 7; ++i) {
return -1;
}
}
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) {
return -1;
box.w, layout))
return -1;
return -1;
}
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