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

Drawing Text

Functions to draw text into a graphics context.

See Graphics Context for more information about the graphics context.

Other drawing functions and related documentation:

  • Drawing Primitives

  • Drawing Paths

  • Graphics Types

Function Documentation

GTextAttributes * graphics_text_attributes_create(void)

Creates an instance of GTextAttributes for advanced control when rendering text.

Returns

New instance of GTextAttributes

See Also

graphics_draw_text
void graphics_text_attributes_destroy(GTextAttributes * text_attributes)

Destroys a previously created instance of GTextAttributes.

void graphics_text_attributes_restore_default_text_flow(GTextAttributes * text_attributes)

Restores text flow to the rectangular default.

Parameters

text_attributes

The attributes for which to disable text flow

See Also

graphics_text_attributes_enable_screen_text_flow
void graphics_text_attributes_enable_screen_text_flow(GTextAttributes * text_attributes, uint8_t inset)

Enables text flow that follows the boundaries of the screen.

Parameters

text_attributes

The attributes for which text flow should be enabled

inset

Additional amount of pixels to inset to the inside of the screen for text flow calculation. Can be zero.

See Also

graphics_text_attributes_restore_default_text_flow
void graphics_text_attributes_restore_default_paging(GTextAttributes * text_attributes)

Restores paging and locked content origin to the defaults.

Parameters

text_attributes

The attributes for which to restore paging and locked content origin

See Also

graphics_text_attributes_enable_paging
void graphics_text_attributes_enable_paging(GTextAttributes * text_attributes, GPoint content_origin_on_screen, GRect paging_on_screen)

Enables paging and locks the text flow calculation to a fixed point on the screen.

Parameters

text_attributes

Attributes for which to enable paging and locked content origin

content_origin_on_screen

Absolute coordinate on the screen where the text content starts before an animation or scrolling takes place. Usually the frame's origin of a layer in screen coordinates.

paging_on_screen

Rectangle in absolute coordinates on the screen that describes where text content pages. Usually the container's absolute frame in screen coordinates.

See Also

graphics_text_attributes_restore_default_paging
void graphics_draw_text(GContext * ctx, const char * text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, GTextAttributes * text_attributes)

Draw text into the current graphics context, using the context's current text color. The text will be drawn inside a box with the specified dimensions and configuration, with clipping occuring automatically.

Parameters

ctx

The destination graphics context in which to draw

text

The zero terminated UTF-8 string to draw

font

The font in which the text should be set

box

The bounding box in which to draw the text. The first line of text will be drawn against the top of the box.

overflow_mode

The overflow behavior, in case the text is larger than what fits inside the box.

alignment

The horizontal alignment of the text

text_attributes

Optional text attributes to describe the characteristics of the text

GSize graphics_text_layout_get_content_size(const char * text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment)

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters

text

The zero terminated UTF-8 string for which to calculate the size

font

The font in which the text should be set while calculating the size

box

The bounding box in which the text should be constrained

overflow_mode

The overflow behavior, in case the text is larger than what fits inside the box.

alignment

The horizontal alignment of the text

Returns

The maximum size occupied by the text

See Also

app_graphics_text_layout_get_content_size_with_attributes

GSize graphics_text_layout_get_content_size_with_attributes(const char * text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, GTextAttributes * text_attributes)

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters

text

The zero terminated UTF-8 string for which to calculate the size

font

The font in which the text should be set while calculating the size

box

The bounding box in which the text should be constrained

overflow_mode

The overflow behavior, in case the text is larger than what fits inside the box.

alignment

The horizontal alignment of the text

text_attributes

Optional text attributes to describe the characteristics of the text

Returns

The maximum size occupied by the text

See Also

app_graphics_text_layout_get_content_size

Enum Documentation

enum GTextOverflowMode

Text overflow mode controls the way text overflows when the string that is drawn does not fit inside the area constraint.

graphics_draw_text text_layer_set_overflow_mode

Enumerators

GTextOverflowModeWordWrap

On overflow, wrap words to a new line below the current one. Once vertical space is consumed, the last line may be clipped.

GTextOverflowModeTrailingEllipsis

On overflow, wrap words to a new line below the current one. Once vertical space is consumed, truncate as needed to fit a trailing ellipsis (...). Clipping may occur if the vertical space cannot accomodate the first line of text.

GTextOverflowModeFill

Acts like GTextOverflowModeTrailingEllipsis, plus trims leading and trailing newlines, while treating all other newlines as spaces.

enum GTextAlignment

Text aligment controls the way the text is aligned inside the box the text is drawn into.

graphics_draw_text text_layer_set_text_alignment

Enumerators

GTextAlignmentLeft

Aligns the text to the left of the drawing box.

GTextAlignmentCenter

Aligns the text centered inside the drawing box.

GTextAlignmentRight

Aligns the text to the right of the drawing box.

Typedef Documentation

typedef struct GTextAttributes GTextAttributes

Need some help?

Functions

  • graphics_text_attributes_create
  • graphics_text_attributes_destroy
  • graphics_text_attributes_restore_default_text_flow
  • graphics_text_attributes_enable_screen_text_flow
  • graphics_text_attributes_restore_default_paging
  • graphics_text_attributes_enable_paging
  • graphics_draw_text
  • graphics_text_layout_get_content_size
  • graphics_text_layout_get_content_size_with_attributes

Enums

  • GTextOverflowMode
  • GTextAlignment

Typedefs

  • GTextAttributes

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!