Difference between revisions of "Label"
(→API reference) |
(Small label improvements) |
||
Line 1: | Line 1: | ||
− | A label is a simple rectangular widget which takes no input. The label | + | A label is a simple rectangular widget which takes no input. The label will automatically redraw it the text changed. If the label is smaller than the text it displays, the text gets clipped. |
− | The text of the label can be set using the gwinSetText() routine. | + | The text of the label can be set using the ''gwinSetText()'' routine. |
== Border == | == Border == |
Revision as of 23:07, 17 June 2015
A label is a simple rectangular widget which takes no input. The label will automatically redraw it the text changed. If the label is smaller than the text it displays, the text gets clipped. The text of the label can be set using the gwinSetText() routine.
Border
The default drawing routine of the labels allows to enable or disable a border. This can be done using gwinLabelSetBorder().
Auto scale
If you apply a size of 0 to the width or the height of the label, the corresponding dimension will be scaled automatically. This also happens when you change the text or the font of the label. However, if you're using a border, this will certainly change the look of your application.
Justification
The text of a label is currently always justified to the left side. We'll update dynamic justification soon.
Attribute
Often you want to display multiple text elements below each other where an element consists of a static text which will always be the same and some variable one. The static text is called the attribute and can be optionally set through gwinLabelSetAttribute() once you enabled this feature in your gfxconf.h. The function does also take a tab parameter which allows to align multiple labels vertically as the following example shows:
Current IP: 192.168.1.42 Netmask: 255.255.255.0 DHCP: On
API reference
The API reference of the label widget can be found here.
Example
The following example shows how to create a label.
#include "gfx.h" static GHandle ghLabel1; static void createWidgets(void) { GWidgetInit wi; // Apply some default values for GWIN wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; wi.g.show = TRUE; // Apply the label parameters wi.g.y = 10; wi.g.x = 10; wi.g.width = 100; wi.g.height = 20; wi.text = "Label 1"; // Create the actual label ghLabel1 = gwinLabelCreate(NULL, &wi); } int main(void) { // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // create the widget createWidgets(); while(1) { gwinSetText(ghLabel1, "This is some text", TRUE); gfxSleepMilliseconds(1000); gwinSetText(ghLabel1, "Aaaand some other text", TRUE); gfxSleepMilliseconds(1000); } return 0; }