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

paint.h — element-agnostic painters: the face box model (inset and content box), the face box itself, clipped text and published paragraphs. More...

#include <stddef.h>
#include "fb.h"
#include "font.h"
#include "geom.h"
#include "layout.h"
#include "mask.h"
#include "style.h"
#include "draw_target.h"

Data Structures

struct  rmgui_paint_inset_t
 The box model every face obeys. More...

Macros

#define RMGUI_PAINT_STROKE_PX   1
 Width in pixels of the one-pixel face stroke BUTTON reserves outside its padding.

Functions

rmgui_paint_inset_t rmgui_paint_face_inset (rmgui_style_class_t class_id, const rmgui_style_resolved_t *style)
 The content inset of class_id's face for the resolved record style (resolved for that class).
rmgui_rect_t rmgui_paint_content_box (rmgui_rect_t r, rmgui_paint_inset_t inset)
 r inset by inset on both axes; negative inset components count as 0.
void rmgui_paint_box (rmgui_fb_t *fb, rmgui_rect_t r, const rmgui_style_resolved_t *style)
 Paints PANEL/FACE for style->states when bound.
void rmgui_paint_box_clipped (rmgui_fb_t *fb, rmgui_rect_t r, rmgui_rect_t clip, const rmgui_style_resolved_t *style)
 rmgui_paint_box's pixels for r, written only where they lie inside clip: the box keeps the place and size of r, so a box clip cuts loses the rings and fill outside it rather than drawing them at the clip's edge.
int rmgui_paint_box_ground (const rmgui_style_resolved_t *style, rmgui_mask_nine_t *ground)
 Replaces *ground (zero-initialized, or filled by an earlier call) with the background of the box rmgui_paint_box paints for style: the shape a backdrop laid over that box must keep to so that it reaches the border on every side, follows rounded corners and leaves the border its colours.
void rmgui_paint_text (rmgui_fb_t *fb, rmgui_font_t *font, rmgui_rect_t r, rmgui_rect_t clip, int x, int y, const char *text, size_t length, int font_px, rmgui_color_t color)
 Draws the UTF-8 text[0, length) with its line box's top-left at (x, y) in color at font_px through font, writing only pixels inside the intersection of r and clip.
void rmgui_paint_paragraph (rmgui_fb_t *fb, rmgui_font_t *font, const rmgui_layout_snapshot_node_t *node, const char *text, int font_px, rmgui_color_t color)
 Paints one TEXT node as the kernel published it through font, writing only pixels inside the intersection of node->rect and node->clip:
void rmgui_paint_box_to (rmgui_target_t *, rmgui_rect_t, const rmgui_style_resolved_t *)
 Explicit destination versions preserve the corresponding framebuffer painter's geometry and clipping.
void rmgui_paint_box_clipped_to (rmgui_target_t *, rmgui_rect_t, rmgui_rect_t, const rmgui_style_resolved_t *)
 Paint a box through clip, with the same target failure contract above.
void rmgui_paint_text_to (rmgui_target_t *, rmgui_font_t *, rmgui_rect_t, rmgui_rect_t, int, int, const char *, size_t, int, rmgui_color_t)
 Paint prepared text through rect intersect clip; no allocation in RECORD.
void rmgui_paint_paragraph_to (rmgui_target_t *, rmgui_font_t *, const rmgui_layout_snapshot_node_t *, const char *, int, rmgui_color_t)
 Paint the published paragraph; every emitted glyph must be prepared.

Detailed Description

paint.h — element-agnostic painters: the face box model (inset and content box), the face box itself, clipped text and published paragraphs.

Every coordinate is a logical framebuffer pixel. Painters that draw text take the font as the parameter after the framebuffer (see font.h).

Macro Definition Documentation

◆ RMGUI_PAINT_STROKE_PX

#define RMGUI_PAINT_STROKE_PX   1

Width in pixels of the one-pixel face stroke BUTTON reserves outside its padding.

Function Documentation

◆ rmgui_paint_face_inset()

rmgui_paint_inset_t rmgui_paint_face_inset ( rmgui_style_class_t class_id,
const rmgui_style_resolved_t * style )

The content inset of class_id's face for the resolved record style (resolved for that class).

Returns {0, 0} when style is NULL.

◆ rmgui_paint_content_box()

rmgui_rect_t rmgui_paint_content_box ( rmgui_rect_t r,
rmgui_paint_inset_t inset )

r inset by inset on both axes; negative inset components count as 0.

The result always lies inside r: an inset wider than the rect yields an empty box centred in it, never a negative extent.

◆ rmgui_paint_box()

void rmgui_paint_box ( rmgui_fb_t * fb,
rmgui_rect_t r,
const rmgui_style_resolved_t * style )

Paints PANEL/FACE for style->states when bound.

Otherwise fills r with style->background and strokes style->border_width nested one-pixel rings of style->border inside it. Writes only pixels of r that lie in the framebuffer. NULL fb or style paints nothing.

◆ rmgui_paint_box_clipped()

void rmgui_paint_box_clipped ( rmgui_fb_t * fb,
rmgui_rect_t r,
rmgui_rect_t clip,
const rmgui_style_resolved_t * style )

rmgui_paint_box's pixels for r, written only where they lie inside clip: the box keeps the place and size of r, so a box clip cuts loses the rings and fill outside it rather than drawing them at the clip's edge.

With clip covering r the result equals rmgui_paint_box(fb, r, style). NULL fb or style, or an empty overlap of r and clip, paints nothing.

◆ rmgui_paint_box_ground()

int rmgui_paint_box_ground ( const rmgui_style_resolved_t * style,
rmgui_mask_nine_t * ground )

Replaces *ground (zero-initialized, or filled by an earlier call) with the background of the box rmgui_paint_box paints for style: the shape a backdrop laid over that box must keep to so that it reaches the border on every side, follows rounded corners and leaves the border its colours.

  • No PANEL/FACE bound: every band is style->border_width wide and holds no background.
  • A bound nine-patch with an opaque centre: the bands are its insets at style's scale. A band pixel's coverage is 255 where the art, painted over black and over white alike, shows its centre colour, and falls linearly to 0 where the largest premultiplied channel difference from it reaches 32. A ring, a bevel, and whatever lies outside a rounded corner are therefore excluded; a pixel the border shares with the fill is covered in part. An edge is read once, across its band, and taken to hold along its length.
  • Any other bound art: no bands; the whole box is background. Allocates the masks and two renders the size of the bands. Returns 0, or -1 leaving *ground the whole rect when style or ground is NULL or an allocation fails.

◆ rmgui_paint_text()

void rmgui_paint_text ( rmgui_fb_t * fb,
rmgui_font_t * font,
rmgui_rect_t r,
rmgui_rect_t clip,
int x,
int y,
const char * text,
size_t length,
int font_px,
rmgui_color_t color )

Draws the UTF-8 text[0, length) with its line box's top-left at (x, y) in color at font_px through font, writing only pixels inside the intersection of r and clip.

NULL fb, font or text, or an empty intersection, paints nothing.

◆ rmgui_paint_paragraph()

void rmgui_paint_paragraph ( rmgui_fb_t * fb,
rmgui_font_t * font,
const rmgui_layout_snapshot_node_t * node,
const char * text,
int font_px,
rmgui_color_t color )

Paints one TEXT node as the kernel published it through font, writing only pixels inside the intersection of node->rect and node->clip:

  • text_truncated: the first text_bytes bytes of text as one line at (text_x, text_y), followed, when text_ellipsis, by U+2026 at the prefix's end (the two runs the kernel measured);
  • otherwise the retained text_lines, when supplied, or the lines rmgui_text_flow_line_prefix produces at the published flow_w (0: lines end only at newlines), one line height apart from text_y. Retained lines are never re-measured, including clipped-away rows. With the built-in font metrics measure provider, glyph placement shares node->text_metrics with measurement; cache collisions recompute exact advances. Painting owns that mutable context for the call. text must be the node's NUL-terminated text, and font and font_px the face and pixel size the kernel measured it with. There is no text length cap. NULL fb, font, node or text paints nothing.

◆ rmgui_paint_box_to()

void rmgui_paint_box_to ( rmgui_target_t * ,
rmgui_rect_t ,
const rmgui_style_resolved_t *  )

Explicit destination versions preserve the corresponding framebuffer painter's geometry and clipping.

RECORD text requires prepared glyphs; failures latch on the stream, without allocation or implicit preparation.

◆ rmgui_paint_box_clipped_to()

void rmgui_paint_box_clipped_to ( rmgui_target_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
const rmgui_style_resolved_t *  )

Paint a box through clip, with the same target failure contract above.

◆ rmgui_paint_text_to()

void rmgui_paint_text_to ( rmgui_target_t * ,
rmgui_font_t * ,
rmgui_rect_t ,
rmgui_rect_t ,
int ,
int ,
const char * ,
size_t ,
int ,
rmgui_color_t  )

Paint prepared text through rect intersect clip; no allocation in RECORD.

◆ rmgui_paint_paragraph_to()

void rmgui_paint_paragraph_to ( rmgui_target_t * ,
rmgui_font_t * ,
const rmgui_layout_snapshot_node_t * ,
const char * ,
int ,
rmgui_color_t  )

Paint the published paragraph; every emitted glyph must be prepared.