Chapter 3. Text labels

#include <x/w/label.H>

x::w::label s=factory->create_label("Hello world");

create_label() creates a simple display element, a x::w::label, that displays text. The first parameter to create_label() is actually a x::w::text_param object. An explicitly-constructed x::w::text_param gives the ability of using custom fonts and colors for the new label. Labels use a default font and color, if not specified in the x::w::text_param.

\n characters in the text string create labels with multiple lines. create_label() takes an optional second parameter which is a x::w::label_config that configures the label element's appearance. x::w::label_config's alignment value specifies the formatting of labels that have multiple lines of text:

x::w::halign::left (default)

Display all lines in the label normally, left-aligned.


Center all the lines.


Align all lines against their right margin.

Sometimes it's desirable to explicitly set the alignment even for labels with just a single line of text. Normally display elements get automatically sized for their content. It's possible that a container adjusts the label to a wider size that it needs, due to other elements in the container, and the alignment setting will then govern how the text gets padded.