All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TextLayer

Detailed Description

Layer that displays and formats a text string.

text_layer.png

The geometric information (bounds, frame) of the Layer is used as the "box" in which the text is drawn. The TextLayer also has a number of other properties that influence how the text is drawn. Most important of these properties are: a pointer to the string to draw itself, the font, the text color, the background color of the layer, the overflow mode and alignment of the text inside the layer.

See Also
Layers
Drawing Text
Fonts

Function Documentation

TextLayer* text_layer_create ( GRect  frame)

Creates a new TextLayer on the heap and initializes it with the default values.

The text layer is automatically marked dirty after this operation.

Parameters
frameThe frame with which to initialze the TextLayer
Returns
A pointer to the TextLayer. NULL if the TextLayer could not be created
void text_layer_destroy ( TextLayer *  text_layer)

Destroys a TextLayer previously created by text_layer_create.

GSize text_layer_get_content_size ( TextLayer *  text_layer)

Calculates the size occupied by the current text of the TextLayer.

Parameters
text_layerthe TextLayer for which to calculate the text's size
Returns
The size occupied by the current text of the TextLayer
Layer* text_layer_get_layer ( TextLayer *  text_layer)

Gets the "root" Layer of the text layer, which is the parent for the sub- layers used for its implementation.

Parameters
text_layerPointer to the TextLayer for which to get the "root" Layer
Returns
The "root" Layer of the text layer.
const char* text_layer_get_text ( TextLayer *  text_layer)

Gets the pointer to the string that the TextLayer is using.

Parameters
text_layerThe TextLayer for which to get the text
See Also
text_layer_set_text
void text_layer_set_background_color ( TextLayer *  text_layer,
GColor  color 
)

Sets the background color of bounding box that will be drawn behind the text.

Parameters
text_layerThe TextLayer of which to set the background color
colorThe new GColor to set the background to
See Also
text_layer_set_text_color
void text_layer_set_font ( TextLayer *  text_layer,
GFont  font 
)

Sets the font of the TextLayer.

Parameters
text_layerThe TextLayer of which to set the font
fontThe new GFont for the TextLayer
See Also
fonts_get_system_font
fonts_load_custom_font
void text_layer_set_overflow_mode ( TextLayer *  text_layer,
GTextOverflowMode  line_mode 
)

Sets the line break mode of the TextLayer.

Parameters
text_layerThe TextLayer of which to set the overflow mode
line_modeThe new GTextOverflowMode to set
void text_layer_set_size ( TextLayer *  text_layer,
const GSize  max_size 
)

Update the size of the text layer This is a convenience function to update the frame of the TextLayer.

Parameters
text_layerThe TextLayer of which to set the size
max_sizeThe new size for the TextLayer
void text_layer_set_text ( TextLayer *  text_layer,
const char *  text 
)

Sets the pointer to the string where the TextLayer is supposed to find the text at a later point in time, when it needs to draw itself.

Parameters
text_layerThe TextLayer of which to set the text
textThe new text to set onto the TextLayer. This must be a null-terminated and valid UTF-8 string!
Note
The string is not copied, so its buffer most likely cannot be stack allocated, but is recommended to be a buffer that is long-lived, at least as long as the TextLayer is part of a visible Layer hierarchy.
See Also
text_layer_get_text
void text_layer_set_text_alignment ( TextLayer *  text_layer,
GTextAlignment  text_alignment 
)

Sets the alignment of the TextLayer.

Parameters
text_layerThe TextLayer of which to set the alignment
text_alignmentThe new text alignment for the TextLayer
See Also
GTextAlignment
void text_layer_set_text_color ( TextLayer *  text_layer,
GColor  color 
)

Sets the color of text that will be drawn.

Parameters
text_layerThe TextLayer of which to set the text color
colorThe new GColor to set the text color to
See Also
text_layer_set_background_color