|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
choice.h — the choice element: a group of checkbox or radio options, each an indicator plus its label. More...
#include <stddef.h>#include <stdint.h>#include "fb.h"#include "font.h"#include "geom.h"#include "input.h"#include "style.h"#include "draw_target.h"Data Structures | |
| struct | rmgui_choice_t |
| Retained group state, built by rmgui_choice_init. More... | |
Macros | |
| #define | RMGUI_CHOICE_NONE UINT32_MAX |
| The hover/pressed value meaning "no option". | |
Enumerations | |
| enum | rmgui_choice_kind_t { RMGUI_CHOICE_KIND_CHECK , RMGUI_CHOICE_KIND_RADIO } |
| How options select: CHECK toggles each option independently, RADIO keeps exactly one option selected. More... | |
Functions | |
| int | rmgui_choice_init (rmgui_choice_t *self, rmgui_choice_kind_t kind, size_t count, uint8_t *selected, size_t capacity) |
| Borrows selected[0..count), with capacity bytes, each 0 or 1, until the group is retired. | |
| rmgui_size_t | rmgui_choice_measure (const rmgui_font_t *font, const rmgui_style_resolved_t *rs, int scale_percent, const char *label) |
| Minimum outer size of ONE option showing label (NULL = empty) in font. | |
| void | rmgui_choice_paint (rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_style_resolved_t *rs, int scale_percent, rmgui_rect_t rect, rmgui_rect_t clip, rmgui_choice_kind_t kind, const char *label) |
| Paints one option in rect: a checkbox or radio indicator with its resolved background, border, and selected mark, followed by label in resolved text (including disabled text). | |
| rmgui_rect_t | rmgui_choice_indicator_rect (const rmgui_style_resolved_t *rs, int scale_percent, rmgui_rect_t rect) |
| The indicator box rmgui_choice_paint draws for one option arranged at rect: at the scaled 2-pixel inset from rect's left edge, centred vertically, rs->indicator_size square, shrunk to fit rect.h less the scaled 4-pixel vertical floor (never below 0). | |
| rmgui_style_states_t | rmgui_choice_states (const rmgui_choice_t *self, size_t option) |
| The state set to paint option option with: SELECTED from selected, HOVER when hovered, PRESSED when pressed and hovered (never while DISABLED), FOCUSED when the group is FOCUSED and option is the focus option, DISABLED from the group. | |
| rmgui_input_result_t | rmgui_choice_input (rmgui_choice_t *self, const rmgui_rect_t *options, const rmgui_input_t *in) |
| Applies one event to the group whose options are arranged at options[0..count). | |
| void | rmgui_choice_paint_to (rmgui_target_t *, rmgui_font_t *, const rmgui_style_resolved_t *, int, rmgui_rect_t, rmgui_rect_t, rmgui_choice_kind_t, const char *) |
| Explicit choice destination with identical indicator and skin behavior. | |
choice.h — the choice element: a group of checkbox or radio options, each an indicator plus its label.
Style class RADIO.
Typed choice groups
From the current checkout, ui.h groups the same selection state with its labels. Use rmgui_choice_view_init with caller-owned selection bytes and an optional array of labels in option order. Route one event to the group with rmgui_choice_event; it uses the arranged option rectangles and updates those selection bytes in place. Draw each visible option with rmgui_choice_draw. For recording, call rmgui_choice_prepare for each option you will draw before recording any commands. The lower-level APIs below remain available for custom painting.
| #define RMGUI_CHOICE_NONE UINT32_MAX |
The hover/pressed value meaning "no option".
| enum rmgui_choice_kind_t |
| int rmgui_choice_init | ( | rmgui_choice_t * | self, |
| rmgui_choice_kind_t | kind, | ||
| size_t | count, | ||
| uint8_t * | selected, | ||
| size_t | capacity ) |
Borrows selected[0..count), with capacity bytes, each 0 or 1, until the group is retired.
Focus starts at the lowest selected option, or zero. Returns 0, or -1 leaving self and storage unchanged for NULL, invalid kind, count outside 1..INT_MAX or above capacity, invalid selection bytes, or a RADIO selection without exactly one selected option. The array must not alias self. Input mutates only the selected bytes that change.
| rmgui_size_t rmgui_choice_measure | ( | const rmgui_font_t * | font, |
| const rmgui_style_resolved_t * | rs, | ||
| int | scale_percent, | ||
| const char * | label ) |
Minimum outer size of ONE option showing label (NULL = empty) in font.
The indicator's scaled inset, label gap, right margin and vertical floor are added to the already resolved device-pixel indicator/font metrics. scale_percent is 1..400; NULL rs or invalid scale yields {0, 0}.
| void rmgui_choice_paint | ( | rmgui_fb_t * | fb, |
| rmgui_font_t * | font, | ||
| const rmgui_style_resolved_t * | rs, | ||
| int | scale_percent, | ||
| rmgui_rect_t | rect, | ||
| rmgui_rect_t | clip, | ||
| rmgui_choice_kind_t | kind, | ||
| const char * | label ) |
Paints one option in rect: a checkbox or radio indicator with its resolved background, border, and selected mark, followed by label in resolved text (including disabled text).
Inset, gap, vertical floor and indicator strokes round at scale_percent (1..400); the resolved metrics are not scaled again. Writes only inside rect ∩ clip. CHOICE/INDICATOR replaces checkbox chrome; radios first consult CHOICE/RADIO_INDICATOR, then the shared CHOICE/INDICATOR when absent. On a selected option, CHOICE/CHECK_MARK and CHOICE/RADIO_MARK may independently replace the procedural mark in the same indicator box. If the mark part for the current state is absent, the procedural mark remains, even when the indicator itself is skinned. Labels remain element-owned. Marks do not change layout, hit areas, or input behavior. NULL fb/rs or invalid scale paints nothing; NULL label/font omits text.
| rmgui_rect_t rmgui_choice_indicator_rect | ( | const rmgui_style_resolved_t * | rs, |
| int | scale_percent, | ||
| rmgui_rect_t | rect ) |
The indicator box rmgui_choice_paint draws for one option arranged at rect: at the scaled 2-pixel inset from rect's left edge, centred vertically, rs->indicator_size square, shrunk to fit rect.h less the scaled 4-pixel vertical floor (never below 0).
The label's line box starts the scaled 6-pixel gap right of it. NULL rs or a scale_percent outside 1..400 yields a zero rect.
| rmgui_style_states_t rmgui_choice_states | ( | const rmgui_choice_t * | self, |
| size_t | option ) |
The state set to paint option option with: SELECTED from selected, HOVER when hovered, PRESSED when pressed and hovered (never while DISABLED), FOCUSED when the group is FOCUSED and option is the focus option, DISABLED from the group.
0 for a NULL self or option >= count.
| rmgui_input_result_t rmgui_choice_input | ( | rmgui_choice_t * | self, |
| const rmgui_rect_t * | options, | ||
| const rmgui_input_t * | in ) |
Applies one event to the group whose options are arranged at options[0..count).
Pointer: the first option rect containing the pointer is hovered; PRESS on an option holds it (captured); RELEASE on the held option completes a click. KEY: SPACE acts on the focus option; LEFT/UP and RIGHT/DOWN move the focus option (wrapping) and, for RADIO, select it. Acting on option i reports CHANGE value i: CHECK toggles i; RADIO selects i and reports only when i was not already selected. A completed click also moves the focus option to i. LEAVE clears hover and the held press; FOCUS_IN/FOCUS_OUT set/clear group FOCUSED. While DISABLED, an inside PRESS reports REFUSED (value 0, consumed 1, captured 0); other events report NONE, selection and focus do not move, and hover/FOCUSED remain tracked. NULL self, options or in returns an all-zero result.
| void rmgui_choice_paint_to | ( | rmgui_target_t * | , |
| rmgui_font_t * | , | ||
| const rmgui_style_resolved_t * | , | ||
| int | , | ||
| rmgui_rect_t | , | ||
| rmgui_rect_t | , | ||
| rmgui_choice_kind_t | , | ||
| const char * | ) |
Explicit choice destination with identical indicator and skin behavior.
RECORD needs prepared label glyphs and immutable sheets; failures latch.