RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
skin.h File Reference
#include "style.h"
#include "style_palette.h"
#include "style_ext.h"
#include "fb.h"
#include "geom.h"
#include "draw_target.h"

Data Structures

struct  rmgui_skin_t
 Immutable declaration. More...
struct  rmgui_skin_set_t
 Borrowed declarations sorted uniquely by target,part,states,tier_percent. More...
struct  rmgui_skin_image_t
 Named borrowed tight RGBA sheet; neither header nor pixels are modified. More...
struct  rmgui_skin_bound_t
 Parallel bound entry borrowing declaration and read-only sheet. More...
struct  rmgui_skin_binding_t
 Borrowed immutable bound table; keep entries, declarations and sheets alive until every resolved style using this binding is retired. More...
struct  rmgui_style_kdl_skin_storage_t

Typedefs

typedef struct rmgui_skin_cache rmgui_skin_cache_t

Enumerations

enum  rmgui_skin_target_t {
  RMGUI_SKIN_TARGET_BUTTON , RMGUI_SKIN_TARGET_DROPDOWN , RMGUI_SKIN_TARGET_SLIDER , RMGUI_SKIN_TARGET_CHOICE ,
  RMGUI_SKIN_TARGET_LIST_ROW , RMGUI_SKIN_TARGET_TEXT_FIELD , RMGUI_SKIN_TARGET_TAB , RMGUI_SKIN_TARGET_WINDOW ,
  RMGUI_SKIN_TARGET_CONTEXT_MENU , RMGUI_SKIN_TARGET_PROGRESS , RMGUI_SKIN_TARGET_SCROLLBAR , RMGUI_SKIN_TARGET_PANEL ,
  RMGUI_SKIN_TARGET_BACKDROP , RMGUI_SKIN_TARGET_COUNT
}
 Independent skin targets; values do not index style classes. More...
enum  rmgui_skin_part_t {
  RMGUI_SKIN_PART_FACE , RMGUI_SKIN_PART_BODY , RMGUI_SKIN_PART_CARD , RMGUI_SKIN_PART_TITLE ,
  RMGUI_SKIN_PART_TRACK , RMGUI_SKIN_PART_FILL , RMGUI_SKIN_PART_THUMB , RMGUI_SKIN_PART_INDICATOR ,
  RMGUI_SKIN_PART_DECREMENT , RMGUI_SKIN_PART_INCREMENT , RMGUI_SKIN_PART_CLOSE , RMGUI_SKIN_PART_MINIMIZE ,
  RMGUI_SKIN_PART_MAXIMIZE , RMGUI_SKIN_PART_RESTORE , RMGUI_SKIN_PART_CLOSE_GLYPH , RMGUI_SKIN_PART_MINIMIZE_GLYPH ,
  RMGUI_SKIN_PART_MAXIMIZE_GLYPH , RMGUI_SKIN_PART_RESTORE_GLYPH , RMGUI_SKIN_PART_STRIPES , RMGUI_SKIN_PART_SHADOW ,
  RMGUI_SKIN_PART_RADIO_INDICATOR , RMGUI_SKIN_PART_ARROW_UP , RMGUI_SKIN_PART_ARROW_DOWN , RMGUI_SKIN_PART_ARROW_LEFT ,
  RMGUI_SKIN_PART_ARROW_RIGHT , RMGUI_SKIN_PART_TOOLBAR = 25 , RMGUI_SKIN_PART_STATUS = 26 , RMGUI_SKIN_PART_TAB_SEGMENT_FIRST = 27 ,
  RMGUI_SKIN_PART_TAB_SEGMENT_LAST = 28 , RMGUI_SKIN_PART_THUMB_HORIZONTAL = 29 , RMGUI_SKIN_PART_TRACK_HORIZONTAL = 30 , RMGUI_SKIN_PART_CHECK_MARK = 31 ,
  RMGUI_SKIN_PART_RADIO_MARK = 32 , RMGUI_SKIN_PART_COUNT = 33
}
 Replaceable visual parts; text/selection marks remain element-owned. More...
enum  rmgui_skin_mode_t { RMGUI_SKIN_NINE_PATCH , RMGUI_SKIN_TILE }
 Nine-patch uses physical source insets; tile repeats the full source. More...
enum  rmgui_skin_tint_kind_t {
  RMGUI_SKIN_TINT_NONE , RMGUI_SKIN_TINT_LITERAL , RMGUI_SKIN_TINT_ROLE , RMGUI_SKIN_TINT_ROLE_RAMP ,
  RMGUI_SKIN_TINT_ROLE_BEVEL
}
 None uses opaque white; literal and role multiply straight RGBA channels. More...

Functions

rmgui_skin_cache_t * rmgui_skin_cache_create (size_t byte_capacity)
void rmgui_skin_cache_destroy (rmgui_skin_cache_t *cache)
void rmgui_skin_cache_clear (rmgui_skin_cache_t *cache)
rmgui_skin_cache_t * rmgui_skin_cache_scope (rmgui_skin_cache_t *cache)
int rmgui_skin_bind (const rmgui_skin_set_t *set, const rmgui_skin_image_t *images, size_t image_count, rmgui_skin_bound_t *scratch, size_t capacity, rmgui_skin_binding_t *out, char *error, size_t error_cap)
 Validate sorted declarations, unique image names and source bounds, then bind without allocation.
int rmgui_style_resolve_with_skins (const rmgui_style_snapshot_t *snapshot, const rmgui_skin_binding_t *skins, rmgui_style_class_t class_id, rmgui_style_states_t states, int font_px, int scale_percent, rmgui_style_resolved_t *out)
 Ordinary resolution plus borrowed skin binding/colour roles.
int rmgui_skin_is_opaque (const rmgui_style_resolved_t *rs, rmgui_skin_target_t target, rmgui_skin_part_t part, rmgui_style_states_t states)
int rmgui_skin_paint (rmgui_fb_t *fb, const rmgui_style_resolved_t *rs, rmgui_skin_target_t target, rmgui_skin_part_t part, rmgui_style_states_t states, rmgui_rect_t dst, rmgui_rect_t clip, int origin_x, int origin_y)
 Paint the normalized target/part/state with nearest permitted tier.
int rmgui_skin_paint_to (rmgui_target_t *, const rmgui_style_resolved_t *, rmgui_skin_target_t, rmgui_skin_part_t, rmgui_style_states_t, rmgui_rect_t, rmgui_rect_t, int, int)
 Explicit destination skin painter.
int rmgui_skin_recipe (const rmgui_style_resolved_t *, rmgui_skin_target_t, rmgui_skin_part_t, rmgui_style_states_t, int origin_x, int origin_y, struct rmgui_recipe_step *out)
 Lower the selected sheet part to one caller-owned image recipe layer.
int rmgui_style_decode_with_assets_kdl (const char *text, size_t length, size_t max_bytes, const rmgui_style_palette_t *palette, rmgui_style_snapshot_t *out, rmgui_style_palette_refs_t *refs_out, rmgui_skin_t *skin_scratch, size_t skin_capacity, char *skin_names, size_t skin_names_capacity, rmgui_skin_set_t *skins_out, char *error, size_t error_cap)
 Unified schema-2/3 decode.
int rmgui_style_decode_with_assets_and_ext_kdl (const char *text, size_t length, size_t max_bytes, const rmgui_style_palette_t *palette, rmgui_style_snapshot_t *out, rmgui_style_palette_refs_t *refs_out, const rmgui_style_kdl_skin_storage_t *skin_storage, const rmgui_style_kdl_skin_storage_t *skin_work, rmgui_skin_set_t *skins_out, rmgui_style_ext_t *ext, rmgui_style_ext_t *ext_work, char *error, size_t error_cap)
size_t rmgui_style_encode_with_assets_kdl (const rmgui_style_snapshot_t *snapshot, const rmgui_style_palette_refs_t *refs, const rmgui_skin_set_t *skins, char *out, size_t capacity)
 Canonical schema-3 export preserving role identities and sorted declarations.

Typedef Documentation

◆ rmgui_skin_cache_t

typedef struct rmgui_skin_cache rmgui_skin_cache_t
  • Owned bounded sprite/label-ink cache. Sources remain borrowed and immutable until clear/destroy; clear before changing or releasing any source pixels. Creation allocates byte_capacity plus at most 64 KiB fixed metadata for 416 sprites and 96 label inks, and returns NULL on allocation failure. Painting, clear and scope allocate nothing. Each cache and its borrowed sources belong to one calling thread.

Enumeration Type Documentation

◆ rmgui_skin_target_t

Independent skin targets; values do not index style classes.

Enumerator
RMGUI_SKIN_TARGET_BUTTON 
RMGUI_SKIN_TARGET_DROPDOWN 
RMGUI_SKIN_TARGET_SLIDER 
RMGUI_SKIN_TARGET_CHOICE 
RMGUI_SKIN_TARGET_LIST_ROW 
RMGUI_SKIN_TARGET_TEXT_FIELD 
RMGUI_SKIN_TARGET_TAB 
RMGUI_SKIN_TARGET_WINDOW 
RMGUI_SKIN_TARGET_CONTEXT_MENU 
RMGUI_SKIN_TARGET_PROGRESS 
RMGUI_SKIN_TARGET_SCROLLBAR 
RMGUI_SKIN_TARGET_PANEL 
RMGUI_SKIN_TARGET_BACKDROP 
RMGUI_SKIN_TARGET_COUNT 

◆ rmgui_skin_part_t

Replaceable visual parts; text/selection marks remain element-owned.

Enumerator
RMGUI_SKIN_PART_FACE 
RMGUI_SKIN_PART_BODY 
RMGUI_SKIN_PART_CARD 
RMGUI_SKIN_PART_TITLE 
RMGUI_SKIN_PART_TRACK 
RMGUI_SKIN_PART_FILL 
RMGUI_SKIN_PART_THUMB 
RMGUI_SKIN_PART_INDICATOR 
RMGUI_SKIN_PART_DECREMENT 
RMGUI_SKIN_PART_INCREMENT 
RMGUI_SKIN_PART_CLOSE 
RMGUI_SKIN_PART_MINIMIZE 
RMGUI_SKIN_PART_MAXIMIZE 
RMGUI_SKIN_PART_RESTORE 
RMGUI_SKIN_PART_CLOSE_GLYPH 
RMGUI_SKIN_PART_MINIMIZE_GLYPH 
RMGUI_SKIN_PART_MAXIMIZE_GLYPH 
RMGUI_SKIN_PART_RESTORE_GLYPH 
RMGUI_SKIN_PART_STRIPES 
RMGUI_SKIN_PART_SHADOW 
RMGUI_SKIN_PART_RADIO_INDICATOR 
RMGUI_SKIN_PART_ARROW_UP 
RMGUI_SKIN_PART_ARROW_DOWN 
RMGUI_SKIN_PART_ARROW_LEFT 
RMGUI_SKIN_PART_ARROW_RIGHT 
RMGUI_SKIN_PART_TOOLBAR 
  • WINDOW-only host-owned chrome bands; BODY remains client content.
RMGUI_SKIN_PART_STATUS 
RMGUI_SKIN_PART_TAB_SEGMENT_FIRST 
  • TAB-only outer segments. TAB/FILL is the square middle segment, TAB/TRACK the whole strip, and TAB/FACE a rounded single tab.
RMGUI_SKIN_PART_TAB_SEGMENT_LAST 
RMGUI_SKIN_PART_THUMB_HORIZONTAL 
  • SCROLLBAR-only axis-specific art; absent entries use THUMB/TRACK.
RMGUI_SKIN_PART_TRACK_HORIZONTAL 
RMGUI_SKIN_PART_CHECK_MARK 
RMGUI_SKIN_PART_RADIO_MARK 
RMGUI_SKIN_PART_COUNT 

◆ rmgui_skin_mode_t

Nine-patch uses physical source insets; tile repeats the full source.

Enumerator
RMGUI_SKIN_NINE_PATCH 
RMGUI_SKIN_TILE 

◆ rmgui_skin_tint_kind_t

None uses opaque white; literal and role multiply straight RGBA channels.

ROLE_RAMP maps source luminance floor((54R+183G+19B)/256) from the role in tint.r (black endpoint) to tint_role (white endpoint), interpolating straight RGBA with halves-up /255 rounding, then multiplying source alpha. tint.g/b must be zero and tint.a must be 255. KDL: tint ramp LOW HIGH. ROLE_BEVEL uses tint.r/tint.g as an unordered pair of edge roles, ordered dark/light by (54R²+183G²+19B²)/256 in the active scheme; tint_role is the face role. Luminance 0/128/255 selects shade/face/highlight, with linear halves-up RGBA interpolation between stops; source alpha still multiplies. tint.b must be zero and tint.a must be 255. KDL: tint bevel EDGE FACE EDGE.

Enumerator
RMGUI_SKIN_TINT_NONE 
RMGUI_SKIN_TINT_LITERAL 
RMGUI_SKIN_TINT_ROLE 
RMGUI_SKIN_TINT_ROLE_RAMP 
RMGUI_SKIN_TINT_ROLE_BEVEL 

Function Documentation

◆ rmgui_skin_cache_create()

rmgui_skin_cache_t * rmgui_skin_cache_create ( size_t byte_capacity)
  • Create an empty cache under the ownership and allocation contract above.

◆ rmgui_skin_cache_destroy()

void rmgui_skin_cache_destroy ( rmgui_skin_cache_t * cache)
  • Release an inactive cache; NULL is permitted.

◆ rmgui_skin_cache_clear()

void rmgui_skin_cache_clear ( rmgui_skin_cache_t * cache)
  • Forget all cached sprites and label inks; NULL is permitted.

◆ rmgui_skin_cache_scope()

rmgui_skin_cache_t * rmgui_skin_cache_scope ( rmgui_skin_cache_t * cache)
  • Set the current thread's optional skin-paint cache, returning the previous scope. Restore that pointer after painting. NULL selects uncached painting; oversize sprites retain uncached semantics. Scopes may nest.

◆ rmgui_skin_bind()

int rmgui_skin_bind ( const rmgui_skin_set_t * set,
const rmgui_skin_image_t * images,
size_t image_count,
rmgui_skin_bound_t * scratch,
size_t capacity,
rmgui_skin_binding_t * out,
char * error,
size_t error_cap )

Validate sorted declarations, unique image names and source bounds, then bind without allocation.

Only caller capacity limits the entry count. Returns 0/-1; out is unchanged on error, scratch unspecified. NULL storage is permitted only for empty tables. Scratch must not alias a published binding. Names, declarations and sheets are borrowed read-only and must remain alive; sheets must not alias painting destination storage.

◆ rmgui_style_resolve_with_skins()

int rmgui_style_resolve_with_skins ( const rmgui_style_snapshot_t * snapshot,
const rmgui_skin_binding_t * skins,
rmgui_style_class_t class_id,
rmgui_style_states_t states,
int font_px,
int scale_percent,
rmgui_style_resolved_t * out )

Ordinary resolution plus borrowed skin binding/colour roles.

NULL skins is semantically plain resolution. Returns 0/-1 with out unchanged on error.

◆ rmgui_skin_is_opaque()

int rmgui_skin_is_opaque ( const rmgui_style_resolved_t * rs,
rmgui_skin_target_t target,
rmgui_skin_part_t part,
rmgui_style_states_t states )
  • Return 1 only when the selected source and tint cover every destination pixel opaquely, or 0 for missing/invalid input or conservative refusal. Sources are inspected read-only; this call allocates nothing.

◆ rmgui_skin_paint()

int rmgui_skin_paint ( rmgui_fb_t * fb,
const rmgui_style_resolved_t * rs,
rmgui_skin_target_t target,
rmgui_skin_part_t part,
rmgui_style_states_t states,
rmgui_rect_t dst,
rmgui_rect_t clip,
int origin_x,
int origin_y )

Paint the normalized target/part/state with nearest permitted tier.

State priority is DISABLED, PRESSED, HOVER, SELECTED, FOCUSED, DEFAULT; INACTIVE is independent. Never inherit another state/part. SELECTED overrides HOVER/PRESSED only when its matching entry is a nine-patch with non-zero insets. Missing, tile and zero-inset selected art retain interaction art. For enabled SELECTED controls, compose at most one matching nine-patch perimeter: PRESSED, otherwise FOCUSED, otherwise HOVER. The selected interior is untouched by perimeter composition. Each disjoint outer destination band's width is its scaled source inset capped at two logical pixels (rounded to device pixels, minimum cap one); opposing bands shrink proportionally when the destination is smaller. Physical corner-preserving caps are not perimeter widths. Tiles, zero-width bands and absent entries contribute nothing. Return 1 for present base skin (even transparent), 0 for no match, NULL inputs or empty dst/clip. Origin is absolute device px; no allocation or procedural fallback is performed. WINDOW/TOOLBAR and WINDOW/STATUS use shared chrome dst/origin and individual band clips to keep material phase continuous; painting a band changes neither geometry nor client BODY.

◆ rmgui_skin_paint_to()

Explicit destination skin painter.

Sheets remain immutable through RECORD submit/discard. Return matches rmgui_skin_paint; stream errors latch.

◆ rmgui_skin_recipe()

int rmgui_skin_recipe ( const rmgui_style_resolved_t * ,
rmgui_skin_target_t ,
rmgui_skin_part_t ,
rmgui_style_states_t ,
int origin_x,
int origin_y,
struct rmgui_recipe_step * out )

Lower the selected sheet part to one caller-owned image recipe layer.

This exposes builtin skins through the same recipe evaluator as host classes. Source sheet storage remains borrowed. Return 0, or -1 without changing out for missing/invalid input. origin is in device pixels.

◆ rmgui_style_decode_with_assets_kdl()

int rmgui_style_decode_with_assets_kdl ( const char * text,
size_t length,
size_t max_bytes,
const rmgui_style_palette_t * palette,
rmgui_style_snapshot_t * out,
rmgui_style_palette_refs_t * refs_out,
rmgui_skin_t * skin_scratch,
size_t skin_capacity,
char * skin_names,
size_t skin_names_capacity,
rmgui_skin_set_t * skins_out,
char * error,
size_t error_cap )

Unified schema-2/3 decode.

Palette requires refs_out. Skin declarations and NUL-terminated sheet names are copied into caller scratch and name storage; keep both alive until the returned set and its bindings are retired. Empty skins permits NULL storage and zero capacities. Returns 0/-1 on invalid input or exhausted caller capacity; snapshot/refs/set unchanged on failure, both scratch areas unspecified. Neither may alias an active set. No sheets are loaded. max_bytes=0 selects RMGUI_STYLE_DEFAULT_MAX_BYTES.

◆ rmgui_style_decode_with_assets_and_ext_kdl()

int rmgui_style_decode_with_assets_and_ext_kdl ( const char * text,
size_t length,
size_t max_bytes,
const rmgui_style_palette_t * palette,
rmgui_style_snapshot_t * out,
rmgui_style_palette_refs_t * refs_out,
const rmgui_style_kdl_skin_storage_t * skin_storage,
const rmgui_style_kdl_skin_storage_t * skin_work,
rmgui_skin_set_t * skins_out,
rmgui_style_ext_t * ext,
rmgui_style_ext_t * ext_work,
char * error,
size_t error_cap )

◆ rmgui_style_encode_with_assets_kdl()

size_t rmgui_style_encode_with_assets_kdl ( const rmgui_style_snapshot_t * snapshot,
const rmgui_style_palette_refs_t * refs,
const rmgui_skin_set_t * skins,
char * out,
size_t capacity )

Canonical schema-3 export preserving role identities and sorted declarations.

NULL refs/skins mean none. Skin exports omit scheme-default scalar values and optional skin defaults. Return required bytes excluding NUL, or 0 for invalid input or a complete document exceeding decoder byte/node limits. A supplied buffer receives a NUL-terminated prefix, empty on refusal.