Skip to content

Label

The label is an output element and displays a formatted text. It is a function and only manages display.

It is very similar to the label provided by the GUI library.

Configure

Warning

Ensure the graphics library is included and initialised according to the configuration procedure.

As a function, the label element requires no configuration.

Use

1
2
3
4
5
6
myGraphics.dLabel(10, 10, 80, 50
    "Label",
    myColours.black, myColours.white,
    horizontalCentre, verticalMiddle,
    fontSizeAutomatic,
    true);

dLabel() displays the label.

The required parameters are

  • The first line specifies the vector coordinates: top-left coordinates x-y then width and height in pixels;

  • The second line contains the text to be displayed;

  • The third line sets the text colour and the background colour.

The optional parameters are

  • The fourth line is optional and specifies the horizontal and vertical formatting:
Constant Horizontal Constant Vertical Value
horizontalLeft Left verticalBottom Bottom -1
horizontalCentre Centre verticalMiddle Middle 0
horizontalRight Right verticalTop Top 1

Default is horizontalCentre, verticalMiddle for centre-middle.

  • The fifth line is optional and selects the size of the font, by default fontSizeAutomatic for automatic.

If fontSizeAutomatic is set, smaller fonts are checked to display the whole text. Otherwise, the text is truncated.

  • The sixth line is for compatibility only.

Example

This is the core of the code from example Graphics_Label.ino.

void displayLabel()
{
    myScreen.setOrientation(myOrientation);
    uint16_t x, y, dx, dy;

    x = myScreen.screenSizeX();
    y = myScreen.screenSizeY();
    dx = x / 3;
    dy = y / 4;

    myGraphics.dLabel(0, 0, x, dy, "Label", myColours.black, myColours.white, -1, 1, fontLarge);

    char * stringH[] = {"Left", "Centre", "Right"};
    char * stringV[] = {"Bottom", "Middle", "Top"};

    for (int8_t i = -1; i < 2; i++)
    {
        for (int8_t j = -1; j < 2; j++)
        {
            myGraphics.dLabel(dx + i * dx, dy + j * dy + dy, dx, dy, formatString(" %s %s ", stringH[i + 1], stringV[j + 1]), myColours.black, myColours.white, i, j, fontSmall, true);
        }
    }

    for (uint8_t k = 0; k < 3; k++)
    {
        myScreen.dLine(0, dy + k * dy, x, 1, myColours.grey);
        myScreen.dLine(dx * k, dy, 1, dy * 3, myColours.grey);
    }

    // Grid
    myScreen.dLine(0, y - 1, x, 1, myColours.grey);
    myScreen.dLine(x - 1, dy, 1, dy * 3, myColours.grey);

    myScreen.flushFast();
}