AG_Label *
AG_LabelNew
(AG_Widget
*parent, Uint
flags, const char
*fmt, ...);
AG_Label *
AG_LabelNewS
(AG_Widget
*parent, Uint
flags, const char
*text);
AG_Label *
AG_LabelNewPolled
(AG_Widget
*parent, Uint
flags, const char
*fmt, ...);
AG_Label *
AG_LabelNewPolledMT
(AG_Widget
*parent, Uint
flags, AG_Mutex
*mutex, const char
*fmt, ...);
void
AG_LabelText
(AG_Label
*label, const char
*format, ...);
void
AG_LabelTextS
(AG_Label
*label, const char
*s);
void
AG_LabelAppend
(AG_Label
*label, const char
*format, ...);
void
AG_LabelAppendS
(AG_Label
*label, const char
*s);
void
AG_LabelSetFont
(AG_Label
*label, AG_Font
*font);
void
AG_LabelSetColor
(AG_Label
*label, AG_Color
C);
void
AG_LabelSetColorBG
(AG_Label
*label, AG_Color
C);
void
AG_LabelSetPadding
(AG_Label
*label, int left,
int right,
int top,
int bottom);
void
AG_LabelJustify
(AG_Label
*label, enum
ag_text_justify justify);
void
AG_LabelValign
(AG_Label
*label, enum
ag_text_valign valign);
void
AG_LabelSizeHint
(AG_Label
*label, Uint
nlines, const char
*text);
The
AG_LabelNew
()
function allocates, initializes and attaches a
AG_Label
widget initially displaying the given
text.
The
AG_LabelNewPolled
()
function creates a new AG_Label
widget displaying a
string of text which contains references to variables. The
AG_LabelNewPolledMT
() variant accepts a pointer to a
mutex that will be automatically acquired and release as the widget accesses
the referenced data. See the POLLED
LABELS section for more details.
See LABEL
FLAGS section for a the accepted flags values for
AG_LabelNew
()
and AG_LabelNewPolled
().
AG_LabelText
()
changes the text contents of the label to the given string.
AG_LabelAppend
() appends the given string to the
existing text.
The
AG_LabelSetFont
()
function configures an alternate font which will be used to display the
label. The font argument is not duplicated (i.e., the
referenced font should remain valid as long as the widget exists). To set
the font of a label back to the default Agar font, NULL can be passed. See
AG_FetchFont(3)
for details on Agar fonts.
AG_LabelSetColor
()
and AG_LabelSetColorBG
() configure an alternate text
and background color for the label (see
AG_Color(3)).
AG_LabelSetPadding
()
sets the label padding parameters in pixels. If a parameter is -1, its
current value is preserved.
The
AG_LabelJustify
()
function sets the text justification:
enum ag_text_justify {
AG_TEXT_LEFT,
AG_TEXT_CENTER,
AG_TEXT_RIGHT
};
AG_LabelValign
()
sets the vertical text alignment:
enum ag_text_valign {
AG_TEXT_TOP,
AG_TEXT_MIDDLE,
AG_TEXT_BOTTOM
};
The
AG_LabelSizeHint
()
function arranges for the minimum scaling of the label to accomodate at
least nlines lines of the given text string. If
nlines is 0, the number of lines will be based on the
contents of the text string.
The following code snippet creates a window containing both a
static label and a polled label:
AG_Window *win;
int myInt = 1234;
AG_Label *myLbl;
win = AG_WindowNew(0);
AG_LabelNew(win, 0, "Foo");
myLbl = AG_LabelNewPolled(win, 0, "myInt=%i", &myInt);
AG_LabelSizeHint(myLbl, 1, "myInt=0000");
Thread-safe code can associate polled labels with mutexes
protecting the data to access:
int myInt = 1234;
AG_Mutex myMutex = AG_MUTEX_INITIALIZER;
AG_LabelNewPolledMT(win, 0, &myMutex, "myInt=%i", &myInt);
The following code fragment defines a custom format specifier,
which can be used in polled labels (and is also recognized by
AG_Printf
()). For more details on custom format
specifiers, refer to
AG_String(3).
AG_Size
PrintMyVector(AG_FmtString *fs, char *dst, AG_Size dstSize)
{
struct my_vector *my = AG_LABEL_ARG(fs);
return AG_Snprintf(dst, dstSize, "[%f,%f]", my->x, my->y);
}
...
struct my_vector v;
AG_RegisterFmtStringExt("myVec", PrintMyVector);
AG_LabelNewS(parent, 0, "Static label: %[myVec]", &v);
AG_LabelNewPolled(parent, 0, "Polled label: %[myVec]", &v);