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

A label widget. More...

#include <stdlib.h>
#include <core/gp_compiler.h>

Go to the source code of this file.

Functions

void gp_widget_label_set (gp_widget *self, const char *text)
 Sets the label text.
 
void gp_widget_labe_fmt_set (gp_widget *self, const char *text_fmt)
 Sets the label text format.
 
void gp_widget_label_fmt_var_set (gp_widget *self, const char *fmt,...)
 Sets label accordingly to text format string.
 
void gp_widget_label_append (gp_widget *self, const char *text)
 Appends text to the label.
 
int gp_widget_label_printf (gp_widget *self, const char *fmt,...) __attribute__((format(printf
 Printf-like function to set label text.
 
int void gp_widget_label_vprintf (gp_widget *self, const char *fmt, va_list ap)
 VPrintf-like function to set label text.
 
static void gp_widget_label_tattr_set (gp_widget *self, gp_widget_tattr tattr)
 Changes text attributes.
 
static void gp_widget_label_width_set (gp_widget *self, unsigned int width)
 Changes widget minimal width.
 
gp_widget * gp_widget_label_new (const char *text, gp_widget_tattr tattr, unsigned int width)
 Allocates a label widget.
 
gp_widget * gp_widget_label_printf_new (gp_widget_tattr tattr, const char *fmt,...) __attribute__((format(printf
 Printf-like function to create a label widget.
 

Detailed Description

A label widget.

Definition in file gp_widget_label.h.

Function Documentation

◆ gp_widget_labe_fmt_set()

void gp_widget_labe_fmt_set ( gp_widget *  self,
const char *  text_fmt 
)

Sets the label text format.

The text format may include a variable that can be then set.

Parameters
selfA label widget.
text_fmtA text format.

◆ gp_widget_label_append()

void gp_widget_label_append ( gp_widget *  self,
const char *  text 
)

Appends text to the label.

Parameters
selfA label widget.
textText to be appended.

◆ gp_widget_label_fmt_var_set()

void gp_widget_label_fmt_var_set ( gp_widget *  self,
const char *  fmt,
  ... 
)

Sets label accordingly to text format string.

Parameters
selfA label widget.
fmtPrintf-like format
...Printf-like parameters.

◆ gp_widget_label_new()

gp_widget * gp_widget_label_new ( const char *  text,
gp_widget_tattr  tattr,
unsigned int  width 
)

Allocates a label widget.

Label minimal width is a bit more complicated topic since labels can change content and hence size dynamically. There are two different modes of operation.

  • If width is set, the size is set to stone so that the label can hold width characters. The main problem is that for proprotional fonts the allocated space is huge because we account for maximal character width. To accomodate for that you can also pass a string with subset of characters that are expected to appear in the label to make that computation more precise.
  • If width is not set, i.e. set to zero, the size is computed accordintly to the current label text, however by default the widget does not shrink, e.g. if the new string width is shorter than the last one we do not trigger resize, which avoids for the layout to size to jump on label text changes. You can manually trigger shrinking by calling gp_widget_resize().
Parameters
textA label text.
tattrText attributes, e.g. bold.
widthMaximal expected text width, if set to non-zero it's used to callculate the label size.
Returns
Newly allocated label widget.

◆ gp_widget_label_printf()

int gp_widget_label_printf ( gp_widget *  self,
const char *  fmt,
  ... 
)

Printf-like function to set label text.

Parameters
selfA label widget.
fmtPrintf formatting string.
...Printf parameters.
Returns
Number of characters printed.

◆ gp_widget_label_printf_new()

gp_widget * gp_widget_label_printf_new ( gp_widget_tattr  tattr,
const char *  fmt,
  ... 
)

Printf-like function to create a label widget.

Parameters
tattrText attributes, e.g. bold.
fmtPrintf formatting string.
...Printf parameters.
Returns
Newly allocated label widget.

◆ gp_widget_label_set()

void gp_widget_label_set ( gp_widget *  self,
const char *  text 
)

Sets the label text.

Parameters
selfA label widget.
textNew widget label text.

◆ gp_widget_label_tattr_set()

static void gp_widget_label_tattr_set ( gp_widget *  self,
gp_widget_tattr  tattr 
)
inlinestatic

Changes text attributes.

Parameters
selfA label widget.
tattrNew text attributes.

Definition at line 101 of file gp_widget_label.h.

◆ gp_widget_label_vprintf()

int void gp_widget_label_vprintf ( gp_widget *  self,
const char *  fmt,
va_list  ap 
)

VPrintf-like function to set label text.

Parameters
selfA label widget.
fmtPrintf formatting string.
apPrintf parameters.

◆ gp_widget_label_width_set()

static void gp_widget_label_width_set ( gp_widget *  self,
unsigned int  width 
)
inlinestatic

Changes widget minimal width.

Parameters
selfPointer to a label widget.
widthNew label width, the unit for the width is font characters.

Definition at line 116 of file gp_widget_label.h.