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

image_button.h — sprite-sheet faces using the button input state. More...

#include "button.h"
#include "mask.h"
#include "ui_context.h"

Data Structures

struct  rmgui_image_button_view_t
 A button state and borrowed vertical sheet of one to four equal frames. More...

Functions

int rmgui_image_button_draw (const rmgui_ui_t *ui, const rmgui_image_button_view_t *button, rmgui_rect_t box)
 Draw the current frame.
unsigned rmgui_image_button_frame (rmgui_style_states_t states, unsigned frame_count)
 Frame index for states, in priority DISABLED > PRESSED > HOVER/FOCUSED > REST.
rmgui_size_t rmgui_image_button_measure (const rmgui_fb_t *sheet, unsigned frame_count)
 Natural size of one frame: {sheet.width, sheet.height / frame_count}.
void rmgui_image_button_paint (rmgui_fb_t *fb, const rmgui_fb_t *sheet, unsigned frame_count, const rmgui_style_resolved_t *rs, rmgui_rect_t rect, rmgui_rect_t clip, rmgui_style_states_t states)
 Composite the selected frame over fb, scaled to rect with the sampling of rmgui_fb_blit_filtered and draw.h's straight-over blend, clipped to rect, clip and fb.
int rmgui_image_button_shape (rmgui_mask_t *mask, const rmgui_fb_t *sheet, unsigned frame_count)
 Replace an allocated mask's coverage with the REST frame's alpha using rmgui_mask_from_alpha's nearest-pixel stretching.
void rmgui_image_button_paint_to (rmgui_target_t *, const rmgui_fb_t *, unsigned, const rmgui_style_resolved_t *, rmgui_rect_t, rmgui_rect_t, rmgui_style_states_t)
 Explicit sprite destination; RECORD pins the complete sheet until submit.

Detailed Description

image_button.h — sprite-sheet faces using the button input state.

A sheet is a straight-alpha RGBA8 framebuffer with 1..4 equal frames stacked top to bottom: REST, HOVER, PRESSED, DISABLED. Its positive height must divide evenly by frame_count, with at least one row per frame. The host retains rmgui_button_t and calls rmgui_button_input, first passing each event through rmgui_input_shape for a shaped node.

Function Documentation

◆ rmgui_image_button_draw()

int rmgui_image_button_draw ( const rmgui_ui_t * ui,
const rmgui_image_button_view_t * button,
rmgui_rect_t box )

Draw the current frame.

A disabled button without a disabled frame uses the theme's button overlay; keep asset registration and hit routing explicit. Returns 0 or -1 for invalid arguments or an unresolved fallback style. Paint errors latch on the target.

◆ rmgui_image_button_frame()

unsigned rmgui_image_button_frame ( rmgui_style_states_t states,
unsigned frame_count )

Frame index for states, in priority DISABLED > PRESSED > HOVER/FOCUSED > REST.

A missing selected frame falls back to REST, not to a lower state. Returns 0 for frame_count outside 1..4. Other state bits are ignored.

◆ rmgui_image_button_measure()

rmgui_size_t rmgui_image_button_measure ( const rmgui_fb_t * sheet,
unsigned frame_count )

Natural size of one frame: {sheet.width, sheet.height / frame_count}.

NULL/empty sheet or an invalid frame_count/height yields {0, 0}.

◆ rmgui_image_button_paint()

void rmgui_image_button_paint ( rmgui_fb_t * fb,
const rmgui_fb_t * sheet,
unsigned frame_count,
const rmgui_style_resolved_t * rs,
rmgui_rect_t rect,
rmgui_rect_t clip,
rmgui_style_states_t states )

Composite the selected frame over fb, scaled to rect with the sampling of rmgui_fb_blit_filtered and draw.h's straight-over blend, clipped to rect, clip and fb.

No label, border or style background is painted. When DISABLED has no frame (frame_count < 4), composite rs's overlay_disabled over rect after the image, just as rmgui_button_paint does; NULL rs omits that overlay. states selects the frame independently of rs->states. NULL/empty fb or sheet, invalid frame_count/height, fb == sheet, or identical fb/sheet pixel pointers paints nothing. Other overlapping storage is not supported. No heap allocation; sheet is borrowed for the call and is never modified.

◆ rmgui_image_button_shape()

int rmgui_image_button_shape ( rmgui_mask_t * mask,
const rmgui_fb_t * sheet,
unsigned frame_count )

Replace an allocated mask's coverage with the REST frame's alpha using rmgui_mask_from_alpha's nearest-pixel stretching.

Returns 0, or -1 with mask unchanged for NULL/empty mask or sheet or invalid frame_count/height. Never reallocates the mask. The caller owns the mask, assigns its address to the layout node's shape, and keeps it allocated and unmodified until every snapshot using that node's shape is no longer queried.

◆ rmgui_image_button_paint_to()

void rmgui_image_button_paint_to ( rmgui_target_t * ,
const rmgui_fb_t * ,
unsigned ,
const rmgui_style_resolved_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
rmgui_style_states_t  )

Explicit sprite destination; RECORD pins the complete sheet until submit.

Frame sampling and disabled overlay match CPU; bounded failures latch.