Label Widget Documentation
Introduction
A Label Widget is a graphical user interface component used to display text on the screen.
It's a simple and efficient way to present non-interactive information to the user. The text within a label can be static or dynamic, and the widget supports various text rendering options, including different fonts, sizes, and colors. It's also possible to align the text within the label in different ways (left, right, center).
This Label Widget document covers the following topics:
- Creating and customizing Label Widgets using Microchip Graphic Suite (MGS) Harmony Composer.
- Label Widget properties.
- Handling Label Widget properties through application code.
- Label Widget example project.
- Application Program Interfaces (APIs) specific to Label Widgets.
Designing Label Widget Using MGS Harmony Composer
To add a Label Widget to your design, follow the steps given below:
Select and drag the Label from the Tool Box to your screen designer workspace as shown in the accompanying image.
To customize the label, select it on the screen designer or from the Screen Tree view and modify its properties using the Object Editor.
Set the label string by pressing the String button from Object Editor.
Managing Label Widget Schemes
Schemes control the look and feel of a widget.
To learn how to set the scheme for a label, click on the button next to the scheme property editor of the Object Editor:
This launches the Label Scheme Helper window containing tips on how different sections of the scheme color table manipulate various elements of the label.
The accompanying image is an example color scheme and the resulting appearance of the Label Widget.
Label Widget Properties
You can set the following properties of the Label Widget using the Object Editor.
String | Will add a String asset to the label. The effects of the settings are previewed within the MGS Harmony Composer. |
Managing Label Widget through Programming
Once the graphical design is completed using MGS Harmony Composer, MCC generates the required code for all the widgets based on the properties set in the Object Editor. To learn more about the process flow between designing a UI and developing application code, refer to the "Designing an Application with Microchip Graphics Suite (MGS)" page.
Let us suppose that a label widget is created with the following properties in MGS Harmony Composer.
For the label widget with the properties shown in the accompanying figure, MCC will automatically generate the following lines of code in src\config\default\gfx\legato\generated\screen\le_gen_screen_Screen0.c:
- A new label widget is created by the variable name Screen0_LabelWidget_0:
Screen0_LabelWidget_1 = leLabelWidget_New();
- Its position is set to pixel location 550x130:
Screen0_LabelWidget_1->fn->setPosition(Screen0_LabelWidget_0, 474, 200);
- Its size is set to 225x85:
Screen0_LabelWidget_1->fn->setSize(Screen0_LabelWidget_1, 225, 85);
- The alpha blending property is enabled:
Screen0_LabelWidget_1->fn->setAlphaEnabled(Screen0_LabelWidget_1, LE_TRUE);
- And the alpha amount will be set to 250:
Screen0_LabelWidget_1->fn->setAlphaAmount(Screen0_LabelWidget_1, 250);
- The label is set to have beveled border in this example.
Screen0_LabelWidget_1->fn->setBorderType(Screen0_LabelWidget_0, LE_WIDGET_BORDER_BEVEL);
- The height aligment is set to center:
Screen0_LabelWidget_1->fn->setHAlignment(Screen0_LabelWidget_1, LE_HALIGN_CENTER);
- If you set a string value to the label in the MGS Harmony Composer Object editor, then the code below is added, else, it is skipped:
Screen0_LabelWidget_1->fn->setString(Screen0_LabelWidget_1, (leString*)&string_AlphaBlending);
- Finally, the label is added to the screen:
root0->fn->addChild(root0, (leWidget*)Screen0_LabelWidget_1);
Label Widget Example Project
An example project for a Label Widget is provided.
In this example, we show:
- How to create a Label Widget.
- How to change its properties (scheme, string, and alpha amount) through programming.
MGS Harmony Web Simulator Output
In the example application, a system timer service callback will change a flag that will mark the Label Widget scheme and also a variable that will be later used to change Label Widget alpha blending.
As a best practice, changes to the widget are done in the main loop based on the variables that are changed in the timer callback, not in the callback directly.
The system timer callback and the code that changes the Label Widget can be found in the app.c file.
- System timer callback:
{
if (label_state == SET_WHITE_SCHEME)
label_state = SET_NO_SCHEME;
else
label_state = SET_WHITE_SCHEME;
alpha_value -= 20;
if (alpha_value < 30)
alpha_value = 255;
appData.state = APP_STATE_SERVICE_TASKS;
}
- Modifying the Label Widget scheme and text in the main loop.
{
case SET_WHITE_SCHEME:
{
Screen0_LabelWidget_0->fn->setString(Screen0_LabelWidget_0, (leString*)&string_White_scheme);
Screen0_LabelWidget_0->fn->setScheme(Screen0_LabelWidget_0, &WhiteScheme);
break;
}
case SET_NO_SCHEME:
{
Screen0_LabelWidget_0->fn->setString(Screen0_LabelWidget_0, (leString*)&string_No_scheme);
Screen0_LabelWidget_0->fn->setScheme(Screen0_LabelWidget_0, NULL);
break;
}
default:
break;
}
- Changing the alpha blending property.
Label Widget APIs Description
This section describes the APIs specific to the Label Widget. For a description of APIs common to all widgets, refer to the "Base Widget Documentation" page.
setString()
Sets the string associated with the label.
Parameters
leLabelWidget* | _this | Label widget pointer to operate on |
const leString* | str | Pointer to the string that should be shown on the label widget |
Returns LE_SUCCESS or LE_FAILURE.
getString()
Gets string assigned to the label widget.
Returns string pointer.
Learn More
For more advanced topics that are related to the Label Widget, refer to the following pages: