Cross-platform C SDK logo

Cross-platform C SDK

Label

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Functions

Label*label_create (void)
Label*label_multiline (void)
voidlabel_OnClick (...)
voidlabel_text (...)
voidlabel_size_text (...)
voidlabel_font (...)
voidlabel_style_over (...)
voidlabel_align (...)
voidlabel_color (...)
voidlabel_color_over (...)
voidlabel_bgcolor (...)
voidlabel_bgcolor_over (...)

Label controls are used to insert small blocks of text into windows and forms. They are of uniform format, that is, the font and color attributes will be applied to the entire text. In most cases the content will be limited to a single line, although it is possible to show blocks that extend in several lines. The control size will be adjusted to the text it contains (Figure 1). In Hello Label! you have an example of use.


1. Multiline label

In the case that the column of Layout has a width smaller than the text, some dots (ellipse) will be displayed at the clipping point (Figure 2), except in multi-line labels, which will expand vertically to accommodate all text (Figure 3).

Label controls with the width smaller than the text.
Figure 2: Text adjustment by reducing the width of the control.
Multiline label controls.
Figure 3: Multi-line labels will expand vertically to accommodate all text.

2. Label in forms

In (Figure 4) we have an example of the use of Label in forms. If necessary, we can make the texts sensitive to the mouse by varying their style and colors (Figure 5).


3. Dynamic labels

  • Use label_size_text to set the text to which the control will be sized.
  • Use label_align to set the internal alignment of the text.

The usual thing will be that the text of a Label control is constant, but sometimes we will need to change it to, for example, display status information. In the case of changing the text once the window has been sized, it is possible that the control does not have enough space to accommodate the new text, cutting off and introducing ellipses (Figure 6).

Window with a Label control wrapped to text. Window with a Label control that is too small to accommodate the new text.
Figure 6: Label control does not have enough space to accommodate the new text.

To avoid this, we can set an alt text large enough for all possible values. The label control will use this text to calculate its size (Figure 7).

 
label_size_text(label, "Hello, I'm a bigger label");
Window with a sufficiently wide Label control. Window with a sufficiently wide Label control.
Figure 7: Label control properly sized.

Another way to solve this problem is to expand the cell where the Label is housed, with the ekJUSTIFY option, occupying the entire width of the layout column (Figure 8).

 
// (0, 0) is the cell coords
layout_label(layout, label, 0, 0);
layout_halign(layout, 0, 0, ekJUSTIFY);
Window with a Label control expanded horizontally. Window with a Label control expanded horizontally.
Figure 8: Label control expanded to the full width of the column.
In the event that the control is wider than the text itself, we can control the internal alignment with label_align.
❮ Back
Next ❯

label_create ()

Create a text control.

Label*
label_create(void);

Return

The new label.


label_multiline ()

Create a multi-line text control.

Label*
label_multiline(void);

Return

The new label.


label_OnClick ()

Set the OnClick event handler.

void
label_OnClick(Label *label,
              Listener *listener);
1
2
3
4
5
6
7
static void i_OnClick(App *app, Event *e)
{
    const EvText *p = event_params(e, EvText);
    do_something_onclick(app, p->text);
}
...
label_OnClick(label, listener(app, i_OnClick, App));
label

The label.

listener

Event handler.

Remarks

See GUI Events.


label_text ()

Set the text that the label will display.

void
label_text(Label *label,
           const char_t *text);
label

The label.

text

UTF8 C-string terminated in null character '\0'.


label_size_text ()

Sets the text with which the control will be sized.

void
label_size_text(Label *label,
                const char_t *text);
label

The Label.

text

UTF8 C-string terminated in null character '\0'.

Remarks

By default, a Label control will be sized to the exact size of the text it contains. See Dynamic labels.


label_font ()

Set the text font.

void
label_font(Label *label,
           const Font *font);
label

The label.

font

Font.


label_style_over ()

Set the font modifiers, when the mouse is over the control.

void
label_style_over(Label *label,
                 const uint32_t style);
label

The label.

style

Combination of values fstyle_t.


label_align ()

Sets the horizontal alignment of the text with respect to the size of the control.

void
label_align(Label *label,
            const align_t align);
label

The label.

align

Alignment.

Remarks

See Dynamic labels.


label_color ()

Set the text color.

void
label_color(Label *label,
            const color_t color);
label

The label.

color

The color.

Remarks

RGB values may not be fully portable. See Colors.


label_color_over ()

Set the color of the text, when the mouse is over the control.

void
label_color_over(Label *label,
                 const color_t color);
label

The label.

color

The color.

Remarks

RGB values may not be fully portable. See Colors.


label_bgcolor ()

Set the background color of the text.

void
label_bgcolor(Label *label,
              const color_t color);
label

The label.

color

The color.

Remarks

RGB values may not be fully portable. See Colors.


label_bgcolor_over ()

Set the background color of the text, when the mouse is over the control.

void
label_bgcolor_over(Label *label,
                   const color_t color);
label

The label.

color

El color.

Remarks

RGB values may not be fully portable. See Colors.

❮ Back
Next ❯