RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
toggle.h File Reference

Integer-only switch, optional mixed state, caller-resolved styling. More...

#include <stdint.h>
#include "input.h"
#include "style_ext.h"
#include "font.h"
#include "draw_target.h"
#include "motion.h"
#include "ui_context.h"

Data Structures

struct  rmgui_toggle_t
 Public value/states are readable. More...
struct  rmgui_toggle_view_t
 A toggle with a borrowed resolved extension style and an optional borrowed NUL-terminated label. More...

Enumerations

enum  rmgui_toggle_value_t { RMGUI_TOGGLE_OFF , RMGUI_TOGGLE_ON , RMGUI_TOGGLE_MIXED }
enum  rmgui_toggle_label_t { RMGUI_TOGGLE_LABEL_RIGHT , RMGUI_TOGGLE_LABEL_LEFT }

Functions

int rmgui_toggle_init (rmgui_toggle_t *self, rmgui_toggle_value_t value, int allow_mixed, rmgui_toggle_label_t label_side)
 Status functions return 0, or -1 with self unchanged for NULL/invalid enum, invalid invariant or MIXED when allow_mixed=0.
int rmgui_toggle_set (rmgui_toggle_t *self, rmgui_toggle_value_t value, uint32_t duration_ms, int reduced_motion)
int rmgui_toggle_tick (rmgui_toggle_t *self, uint32_t elapsed_ms, int reduced_motion)
 Advance by host delta, never wall clock.
rmgui_size_t rmgui_toggle_measure (const rmgui_font_t *font, const rmgui_style_ext_resolved_t *style, const char *label)
 Resolved extension properties, all caller-owned: LENGTH track-width, track-height, knob-inset, label-gap; INT font-px, transition-ms; COLOR off, on, mixed, knob, border, text.
rmgui_rect_t rmgui_toggle_track_rect (const rmgui_toggle_t *self, const rmgui_style_ext_resolved_t *style, rmgui_rect_t rect)
rmgui_rect_t rmgui_toggle_knob_rect (const rmgui_toggle_t *self, const rmgui_style_ext_resolved_t *style, rmgui_rect_t rect)
rmgui_input_result_t rmgui_toggle_input (rmgui_toggle_t *self, const rmgui_style_ext_resolved_t *style, rmgui_rect_t rect, const rmgui_input_t *in, int reduced_motion)
 SPACE/ENTER and a primary click toggle OFF<->ON (MIXED->ON).
void rmgui_toggle_paint_to (rmgui_target_t *target, rmgui_font_t *font, const rmgui_style_ext_resolved_t *style, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_toggle_t *self, const char *label)
 Pure CPU/RECORD painters share clipping and geometry.
void rmgui_toggle_paint (rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_style_ext_resolved_t *style, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_toggle_t *self, const char *label)
rmgui_input_result_t rmgui_toggle_event (rmgui_toggle_view_t *toggle, rmgui_rect_t box, const rmgui_input_t *event, int reduced_motion)
 Route one event at box using the toggle's current resolved style.
int rmgui_toggle_prepare (const rmgui_ui_t *ui, const rmgui_toggle_view_t *toggle)
 Stage the label at the extension's device font size before recording.
int rmgui_toggle_draw (const rmgui_ui_t *ui, const rmgui_toggle_view_t *toggle, rmgui_rect_t box)
 Draw at box with the borrowed style.

Detailed Description

Integer-only switch, optional mixed state, caller-resolved styling.

Enumeration Type Documentation

◆ rmgui_toggle_value_t

Enumerator
RMGUI_TOGGLE_OFF 
RMGUI_TOGGLE_ON 
RMGUI_TOGGLE_MIXED 

◆ rmgui_toggle_label_t

Enumerator
RMGUI_TOGGLE_LABEL_RIGHT 
RMGUI_TOGGLE_LABEL_LEFT 

Function Documentation

◆ rmgui_toggle_init()

int rmgui_toggle_init ( rmgui_toggle_t * self,
rmgui_toggle_value_t value,
int allow_mixed,
rmgui_toggle_label_t label_side )

Status functions return 0, or -1 with self unchanged for NULL/invalid enum, invalid invariant or MIXED when allow_mixed=0.

allow_mixed must be 0 or 1. Init is instantaneous. Set restarts a damped motion.h spring from the displayed position; duration_ms maps its 500 ms canonical spring trajectory onto caller time. duration_ms=0 or reduced_motion is instant. Set cancels capture. Repeated set does not restart its transition.

◆ rmgui_toggle_set()

int rmgui_toggle_set ( rmgui_toggle_t * self,
rmgui_toggle_value_t value,
uint32_t duration_ms,
int reduced_motion )

◆ rmgui_toggle_tick()

int rmgui_toggle_tick ( rmgui_toggle_t * self,
uint32_t elapsed_ms,
int reduced_motion )

Advance by host delta, never wall clock.

Canonical spring time is floor(500*elapsed/duration), advanced by integer 1 ms motion substeps. Clamps to the knob track and reaches the exact endpoint at duration. Returns 1 iff position changed, 0 otherwise (including invalid self).

◆ rmgui_toggle_measure()

rmgui_size_t rmgui_toggle_measure ( const rmgui_font_t * font,
const rmgui_style_ext_resolved_t * style,
const char * label )

Resolved extension properties, all caller-owned: LENGTH track-width, track-height, knob-inset, label-gap; INT font-px, transition-ms; COLOR off, on, mixed, knob, border, text.

Width > height >= 2, inset >=0 with 2*inset < height, gap >=0, font-px >=1, transition-ms >=0. Optional COLOR focus outlines the whole element when focused. Property IDs/class name are unrestricted; matching uses names. Missing/wrong/invalid required geometry returns empty geometry/measure, zero input, or paints nothing. Missing required colors only affects painters. Label NULL means empty. Label is single-line UTF-8, not retained. Label side changes track placement, never input semantics; the entire rect is clickable. Size/geometry arithmetic saturates measure at INT_MAX; overflowing rect endpoints are refused.

◆ rmgui_toggle_track_rect()

rmgui_rect_t rmgui_toggle_track_rect ( const rmgui_toggle_t * self,
const rmgui_style_ext_resolved_t * style,
rmgui_rect_t rect )

◆ rmgui_toggle_knob_rect()

rmgui_rect_t rmgui_toggle_knob_rect ( const rmgui_toggle_t * self,
const rmgui_style_ext_resolved_t * style,
rmgui_rect_t rect )

◆ rmgui_toggle_input()

rmgui_input_result_t rmgui_toggle_input ( rmgui_toggle_t * self,
const rmgui_style_ext_resolved_t * style,
rmgui_rect_t rect,
const rmgui_input_t * in,
int reduced_motion )

SPACE/ENTER and a primary click toggle OFF<->ON (MIXED->ON).

Press captures; release outside cancels a click. Horizontal drag >=3 pixels selects OFF/ON by the dragged knob midpoint, including release outside. Preview position follows the drag; value commits only on release. Touch uses the same path with one owning ID, ignoring other touches. LEAVE/CANCEL/FOCUS_OUT cancel preview and restore the committed value via transition. Disabled primary press reports REFUSED, and disabled state cancels capture. CHANGE.value is the new enum. Caller routes keys only when focused. reduced_motion is used for every transition. Input uses no clock; host calls tick independently.

◆ rmgui_toggle_paint_to()

void rmgui_toggle_paint_to ( rmgui_target_t * target,
rmgui_font_t * font,
const rmgui_style_ext_resolved_t * style,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_toggle_t * self,
const char * label )

Pure CPU/RECORD painters share clipping and geometry.

Track uses committed value's off/on/mixed color; knob uses animated position. RECORD labels need prepared glyphs, as rmgui_paint_text_to; no implicit preparation/allocation. CPU labels follow font.h's existing cache contract: warm glyphs before painting when allocation-free CPU painting is required. NULL font omits label only. Invalid self/style/geometry paints nothing.

◆ rmgui_toggle_paint()

void rmgui_toggle_paint ( rmgui_fb_t * fb,
rmgui_font_t * font,
const rmgui_style_ext_resolved_t * style,
rmgui_rect_t rect,
rmgui_rect_t clip,
const rmgui_toggle_t * self,
const char * label )

◆ rmgui_toggle_event()

rmgui_input_result_t rmgui_toggle_event ( rmgui_toggle_view_t * toggle,
rmgui_rect_t box,
const rmgui_input_t * event,
int reduced_motion )

Route one event at box using the toggle's current resolved style.

Invalid input is not consumed; the host owns routing and reduced motion.

◆ rmgui_toggle_prepare()

int rmgui_toggle_prepare ( const rmgui_ui_t * ui,
const rmgui_toggle_view_t * toggle )

Stage the label at the extension's device font size before recording.

Returns 0 on success or when no glyphs are needed, -1 on error.

◆ rmgui_toggle_draw()

int rmgui_toggle_draw ( const rmgui_ui_t * ui,
const rmgui_toggle_view_t * toggle,
rmgui_rect_t box )

Draw at box with the borrowed style.

A NULL font omits the label. Returns -1 for invalid arguments or style, otherwise 0; paint errors latch on the target.