GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Enumerations | Functions
gp_widget_tattr.h File Reference

A text attrbutes. More...

#include <text/gp_text.h>
#include <widgets/gp_widget_types.h>
#include <widgets/gp_widget_render.h>

Go to the source code of this file.

Enumerations

enum  gp_widget_tattr {
  GP_TATTR_BOLD = 0x10 , GP_TATTR_LARGE = 0x20 , GP_TATTR_MONO = 0x40 , GP_TATTR_FONT = 0x70 ,
  GP_TATTR_LEFT = 0x01 , GP_TATTR_CENTER = 0x02 , GP_TATTR_RIGHT = 0x03 , GP_TATTR_HALIGN = 0x03
}
 Text attribute flags. More...
 

Functions

static const gp_text_stylegp_widget_tattr_font (gp_widget_tattr attr, const gp_widget_render_ctx *ctx)
 Returns text font based on text attributes and render context.
 
static int gp_widget_tattr_halign (gp_widget_tattr attr)
 Returns the alignment part of the text attributes.
 
int gp_widget_tattr_parse (const char *attrs, gp_widget_tattr *tattr, int flags)
 Parses text attributes encoded in a string into attribute bitflags.
 

Detailed Description

A text attrbutes.

Text attributes describe text font, size, and horizontal alignment. Attributes can be either passed down as a C constants, e.g. GP_TATTR_BOLD | GP_TATTR_LARGE or parsed from a string from JSON e.g. "bold|large".

Definition in file gp_widget_tattr.h.

Enumeration Type Documentation

◆ gp_widget_tattr

Text attribute flags.

Enumerator
GP_TATTR_BOLD 

Bold font.

GP_TATTR_LARGE 

Large font.

GP_TATTR_MONO 

Monospace font, can't be combined with large.

GP_TATTR_FONT 

Font attribute mask.

GP_TATTR_LEFT 

Left horizontal alignment.

GP_TATTR_CENTER 

Center horizontal alignment.

GP_TATTR_RIGHT 

Right horizontal alignment.

GP_TATTR_HALIGN 

Alignment attribute mask.

Definition at line 27 of file gp_widget_tattr.h.

Function Documentation

◆ gp_widget_tattr_font()

static const gp_text_style * gp_widget_tattr_font ( gp_widget_tattr  attr,
const gp_widget_render_ctx ctx 
)
inlinestatic

Returns text font based on text attributes and render context.

Parameters
attrText attribute bitflags.
ctxA widget rendering context.
Returns
A text style to use for text rendering.

Definition at line 54 of file gp_widget_tattr.h.

References gp_widget_render_ctx::font, gp_widget_render_ctx::font_big, gp_widget_render_ctx::font_big_bold, gp_widget_render_ctx::font_bold, gp_widget_render_ctx::font_mono, gp_widget_render_ctx::font_mono_bold, GP_TATTR_BOLD, GP_TATTR_LARGE, and GP_TATTR_MONO.

◆ gp_widget_tattr_halign()

static int gp_widget_tattr_halign ( gp_widget_tattr  attr)
inlinestatic

Returns the alignment part of the text attributes.

Parameters
attrA text attribute bitflags.
Returns
Horizontal aliment part of the flags.

Definition at line 82 of file gp_widget_tattr.h.

References GP_TATTR_HALIGN.

◆ gp_widget_tattr_parse()

int gp_widget_tattr_parse ( const char *  attrs,
gp_widget_tattr tattr,
int  flags 
)

Parses text attributes encoded in a string into attribute bitflags.

The attributes are separated by | e.g. valid attributes string is "bold|large".

Parameters
attrsText attributes description string.
tattrA pointer to tattr to be filled in.
flagsA bitwise or of GP_TATTR_FONT and GP_TATTR_HALIGN that enables parsing font and/or alignment.
Returns
Zero on success, non-zero on parsing failure.