Note: The Agar manual pages follow certain conventions, notably concerning function return values. Please read AG_Intro(3) first.
SYNOPSIS
#include <agar/core.h> #include <agar/gui.h> |
DESCRIPTION
| The AG_Label widget displays single-line or multi-line text. In the case of polled labels, the text can contain elements which are going to be dereferenced on rendering. |
INHERITANCE HIERARCHY
| AG_Object(3)-> AG_Widget(3)-> AG_Label. |
INITIALIZATION
POLLED LABELS
AG_LabelNewPolled() and
AG_LabelNewPolledMT() may be used to display a label containing dynamically accessed elements.
The format string argument to
AG_LabelNewPolled() is similar to a printf-style format string but the subsequent arguments in
the variable-argument list are pointers.
The
AG_Label widget will display a continuously updated string, dereferencing the specified
variables at time of rendering.
Built-in format specifiers include:
The %[flags*] directives require that bit (or bitmask) descriptions be provided using the AG_LabelFlag*() functions (see FLAG DESCRIPTIONS section below). It is possible to register custom format specifiers (%[foo]) with the AG_RegisterLabelFormat() function. The callback function provided is expected to fill the contents of fixed-size buffer s with a string. The argument is retrieved using the AG_LABEL_ARG() macro. AG_UnregisterLabelFormat() removes the given format specifier. Note that the length of dynamic labels is difficult to determine automatically, so it is recommended to use either AG_LabelSizeHint() or AG_ExpandHoriz(3) with polled labels. |
FLAG DESCRIPTIONS
The AG_LabelFlag(), AG_LabelFlag8(), AG_LabelFlag16() and AG_LabelFlag32() functions register a new bit "flag" description for the variable at index. If the pointed value AND'ed with bitmask is true, the descr text will be displayed by the label. |
EVENTS
| The AG_Label widget neither reacts to nor generates any event. |
LABEL FLAGS
The following
AG_Label flags are defined:
|
EXAMPLES
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);
}
It is frequently useful to display bit values in textual format. The following example would display FOO_FLAG, BAR_FLAG. {
Uint MyFlags = FOO_FLAG|BAR_FLAG;
AG_Label *lbl;
lbl = AG_LabelNewPolled(win, 0, "MyFlags=%[flags]", &MyFlags);
AG_LabelFlag(lbl, 0, "FOO_FLAG", FOO_FLAG);
AG_LabelFlag(lbl, 0, "BAR_FLAG", BAR_FLAG);
}
The following code fragment defines a custom format specifier for use in polled labels: void
PrintMyVector(AG_Label *label, char *s, size_t len, int fPos)
{
struct my_vector *my = AG_LABEL_ARG(label, void *);
snprintf(s, len, "[%f,%f]", my->x, my->y);
}
{
struct my_vector v;
AG_RegisterLabelFormat("myVec", PrintMyVector);
AG_LabelNewPolled(parent, 0, "%[myVec]", &v);
}
|
SEE ALSO
| AG_Intro(3), AG_Pixmap(3), AG_Widget(3), AG_Window(3), M_Label(3), printf(3) |
HISTORY
| The AG_Label widget first appeared in Agar 1.0. |
