Pebble Foundation Classes  0.2.0
C++ for Pebble
Drawing Text

Functions to draw text into a graphics context. More...

Collaboration diagram for Drawing Text:

Classes

class  Pebble::GTextAttributes
 

Typedefs

typedef struct GTextAttributes GTextAttributes
 

Enumerations

enum  GTextOverflowMode { GTextOverflowModeWordWrap, GTextOverflowModeTrailingEllipsis, GTextOverflowModeFill }
 
enum  GTextAlignment { GTextAlignmentLeft, GTextAlignmentCenter, GTextAlignmentRight }
 

Functions

GTextAttributes * graphics_text_attributes_create (void)
 
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)
 
void graphics_text_attributes_enable_screen_text_flow (GTextAttributes *text_attributes, uint8_t inset)
 
void graphics_text_attributes_restore_default_paging (GTextAttributes *text_attributes)
 
void graphics_text_attributes_enable_paging (GTextAttributes *text_attributes, GPoint content_origin_on_screen, GRect paging_on_screen)
 
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)
 
GSize graphics_text_layout_get_content_size (const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment)
 
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)
 

Detailed Description

Functions to draw text into a graphics context.

See Graphics Context for more information about the graphics context.

Other drawing functions and related documentation:

Enumeration Type Documentation

◆ GTextAlignment

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

See also
graphics_draw_text
text_layer_set_text_alignment
Enumerator
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.

◆ GTextOverflowMode

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

See also
graphics_draw_text
text_layer_set_overflow_mode
Enumerator
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.

Function Documentation

◆ graphics_draw_text()

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
ctxThe destination graphics context in which to draw
textThe zero terminated UTF-8 string to draw
fontThe font in which the text should be set
boxThe bounding box in which to draw the text. The first line of text will be drawn against the top of the box.
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional text attributes to describe the characteristics of the text

◆ graphics_text_attributes_create()

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

◆ 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_attributesAttributes for which to enable paging and locked content origin
content_origin_on_screenAbsolute 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_screenRectangle 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
graphics_text_attributes_enable_screen_text_flow
text_layer_enable_screen_text_flow_and_paging
layer_convert_point_to_screen

◆ 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_attributesThe attributes for which text flow should be enabled
insetAdditional 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
text_layer_enable_screen_text_flow_and_paging

◆ graphics_text_attributes_restore_default_paging()

void graphics_text_attributes_restore_default_paging ( GTextAttributes *  text_attributes)

Restores paging and locked content origin to the defaults.

Parameters
text_attributesThe attributes for which to restore paging and locked content origin
See also
graphics_text_attributes_enable_paging
text_layer_restore_default_text_flow_and_paging

◆ graphics_text_attributes_restore_default_text_flow()

void graphics_text_attributes_restore_default_text_flow ( GTextAttributes *  text_attributes)

Restores text flow to the rectangular default.

Parameters
text_attributesThe attributes for which to disable text flow
See also
graphics_text_attributes_enable_screen_text_flow
text_layer_restore_default_text_flow_and_paging

◆ graphics_text_layout_get_content_size()

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
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
Returns
The maximum size occupied by the text
See also
app_graphics_text_layout_get_content_size_with_attributes

◆ 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
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional 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