pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

TextLayer

Layer that displays and formats a text string.

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.

Function Documentation

TextLayer * text_layer_create(GRect frame)

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

  • Font: Raster Gothic 14-point Boldface (system font)

  • Text Alignment: GTextAlignmentLeft

  • Text color: GColorBlack

  • Background color: GColorWhite

  • Clips: true

  • Hidden: false

  • Caching: false

The text layer is automatically marked dirty after this operation.

Parameters

frame

The 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.

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_layer

Pointer to the TextLayer for which to get the "root" Layer

Returns

The "root" Layer of the text layer.

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.

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.

Parameters

text_layer

The TextLayer of which to set the text

text

The new text to set onto the TextLayer. This must be a null-terminated and valid UTF-8 string!

See Also

text_layer_get_text
const char * text_layer_get_text(TextLayer * text_layer)

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

Parameters

text_layer

The 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 the bounding box that will be drawn behind the text.

Parameters

text_layer

The TextLayer of which to set the background color

color

The new GColor to set the background to

See Also

text_layer_set_text_color
void text_layer_set_text_color(TextLayer * text_layer, GColor color)

Sets the color of text that will be drawn.

Parameters

text_layer

The TextLayer of which to set the text color

color

The new GColor to set the text color to

See Also

text_layer_set_background_color
void text_layer_set_overflow_mode(TextLayer * text_layer, GTextOverflowMode line_mode)

Sets the line break mode of the TextLayer.

Parameters

text_layer

The TextLayer of which to set the overflow mode

line_mode

The new GTextOverflowMode to set

void text_layer_set_font(TextLayer * text_layer, GFont font)

Sets the font of the TextLayer.

Parameters

text_layer

The TextLayer of which to set the font

font

The new GFont for the TextLayer

See Also

fonts_get_system_font
void text_layer_set_text_alignment(TextLayer * text_layer, GTextAlignment text_alignment)

Sets the alignment of the TextLayer.

Parameters

text_layer

The TextLayer of which to set the alignment

text_alignment

The new text alignment for the TextLayer

See Also

GTextAlignment
void text_layer_enable_screen_text_flow_and_paging(TextLayer * text_layer, uint8_t inset)

Enables text flow following the boundaries of the screen and pagination that introduces extra line spacing at page breaks to avoid partially clipped lines for the TextLayer. If the TextLayer is part of a ScrollLayer the ScrollLayer's frame will be used to configure paging.

Note

Make sure the TextLayer is part of the view hierarchy before calling this function. Otherwise it has no effect.

Parameters

text_layer

The TextLayer for which to enable text flow and paging

inset

Additional amount of pixels to inset to the inside of the screen for text flow

See Also

text_layer_restore_default_text_flow_and_paging
void text_layer_restore_default_text_flow_and_paging(TextLayer * text_layer)

Restores text flow and paging for the TextLayer to the rectangular defaults.

Parameters

text_layer

The TextLayer for which to restore text flow and paging

See Also

text_layer_enable_screen_text_flow_and_paging
GSize text_layer_get_content_size(TextLayer * text_layer)

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

Parameters

text_layer

the TextLayer for which to calculate the text's size

Returns

The size occupied by the current text of the TextLayer

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_layer

The TextLayer of which to set the size

max_size

The new size for the TextLayer

Typedef Documentation

typedef struct TextLayer TextLayer

Need some help?

Functions

  • text_layer_create
  • text_layer_destroy
  • text_layer_get_layer
  • text_layer_set_text
  • text_layer_get_text
  • text_layer_set_background_color
  • text_layer_set_text_color
  • text_layer_set_overflow_mode
  • text_layer_set_font
  • text_layer_set_text_alignment
  • text_layer_enable_screen_text_flow_and_paging
  • text_layer_restore_default_text_flow_and_paging
  • text_layer_get_content_size
  • text_layer_set_size

Typedefs

  • TextLayer

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!