# Module `Text`

Component for Wrapping GUI Text Nodes: Druid Text

## Overview ##

Druid Text is a component that provides various adjustment modes for text nodes.

It allows text to be scaled down to fit within the size of the text node.

## Notes ##

• The text pivot can be changed using the text:set_pivot method. The anchoring will be inside the text node's area size.

• There are several text adjustment types available. The default is DOWNSCALE. You can change the default adjustment type in the Text style. Refer to the example below to see all available adjustment types:

- const.TEXT_ADJUST.DOWNSCALE: Changes the text's scale to fit within the text node's size.

- const.TEXT_ADJUST.TRIM: Trims the text with a postfix (default: "...", can be overridden in styles) to fit within the text node's size.

- const.TEXT_ADJUST.NO_ADJUST: No adjustment is applied, similar to the default Defold Text Node behavior.

- const.TEXT_ADJUST.DOWNSCALE_LIMITED: Changes the text's scale with a limited downscale. You can set the minimum scale using the text:set_minimal_scale() function.

- const.TEXT_ADJUST.SCROLL: Changes the text's pivot to imitate scrolling within the text box. For better effect, use with a stencil node.

- const.TEXT_ADJUST.SCALE_THEN_SCROLL: Combines two modes: limited downscale first, then scroll.

Example Link

## Functions

get_text_adjust(self, adjust_type) | Return current text adjust type
get_text_index_by_width(self, width) | Get chars count by width
get_text_size(self, text) | Calculate text width with font with respect to trailing space
init(self, node, value, adjust_type) | The Text constructor
is_multiline(self) | Return true, if text with line break
set_alpha(self, alpha) | Set alpha
set_color(self, color) | Set color
set_minimal_scale(self, minimal_scale) | Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
set_pivot(self, pivot) | Set text pivot.
set_scale(self, scale) | Set scale
set_size(self, size) | Set text area size
set_text_adjust(self, adjust_type, minimal_scale) | Set text adjust, refresh the current text visuals, if needed
set_to(self, set_to) | Set text to text field

## Tables

style | Component style params.

## Fields

adjust_type | Current text size adjust settings
color | Current text color
last_value | The last text value
node | Text node
node_id | The node id of text node
on_set_pivot | On change pivot callback(self, pivot)
on_set_text | On set text callback(self, text)
on_update_text_scale | On adjust text size callback(self, new_scale, text_metrics)
pos | Current text position
scale | Current text node scale
start_scale | Initial text node scale
start_size | Initial text node size
text_area | Current text node available are

## Functions

get_text_adjust(self, adjust_type)
  Return current text adjust type

  ### Parameters:

  - self
  - adjust_type

  ### Returns:

  number The current text adjust type
get_text_index_by_width(self, width)
  Get chars count by width

  ### Parameters:

  - self Text Text
  - width number

  ### Returns:

  number Chars count
get_text_size(self, text)
  Calculate text width with font with respect to trailing space

  ### Parameters:

  - self Text Text
  - text string |nil

  ### Returns:

  1. number Width
  2. number Height
init(self, node, value, adjust_type)
  The Text constructor

  ### Parameters:

  - self Text Text
  - node string or node Node name or GUI Text Node itself
  - value string or nil Initial text. Default value is node text from GUI scene. Default: nil
  - adjust_type string or nil Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
is_multiline(self)
  Return true, if text with line break

  ### Parameters:

  - self Text Text

  ### Returns:

  boolean Is text node with line break
set_alpha(self, alpha)
  Set alpha

  ### Parameters:

  - self Text Text
  - alpha number Alpha for node

  ### Returns:

  Text Current text instance
set_color(self, color)
  Set color

  ### Parameters:

  - self Text Text
  - color vector4 Color for node

  ### Returns:

  Text Current text instance
set_minimal_scale(self, minimal_scale)
  Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types

  ### Parameters:

  - self Text Text
  - minimal_scale number If pass nil - not use minimal scale

  ### Returns:

  Text Current text instance
set_pivot(self, pivot)
  Set text pivot. Text will re-anchor inside text area

  ### Parameters:

  - self Text Text
  - pivot number The gui.PIVOT_* constant

  ### Returns:

  Text Current text instance
set_scale(self, scale)
  Set scale

  ### Parameters:

  - self Text Text
  - scale vector3 Scale for node

  ### Returns:

  Text Current text instance
set_size(self, size)
  Set text area size

  ### Parameters:

  - self Text Text
  - size vector3 The new text area size

  ### Returns:

  Text Current text instance
set_text_adjust(self, adjust_type, minimal_scale)
  Set text adjust, refresh the current text visuals, if needed

  ### Parameters:

  - self Text Text
  - adjust_type string or nil See const.TEXT_ADJUST. If pass nil - use current adjust type
  - minimal_scale number or nil If pass nil - not use minimal scale

  ### Returns:

  Text Current text instance
set_to(self, set_to)
  Set text to text field

  ### Parameters:

  - self Text Text
  - set_to string Text for node

  ### Returns:

  Text Current text instance

## Tables

style
  Component style params. You can override this component styles params in druid styles table or create your own style

  ### Fields:

  - TRIM_POSTFIX string or nil The postfix for TRIM adjust type. Default: ...
  - DEFAULT_ADJUST string or nil The default adjust type for any text component. Default: DOWNSCALE
  - ADJUST_STEPS string or nil Amount of iterations for text adjust by height. Default: 20
  - ADJUST_SCALE_DELTA string or nil Scale step on each height adjust step. Default: 0.02

## Fields

adjust_type
  Current text size adjust settings
  - adjust_type number
color
  Current text color
  - color vector3
last_value
  The last text value
  - last_value string
node
  Text node
  - node node
node_id
  The node id of text node
  - node_id hash
on_set_pivot
  On change pivot callback(self, pivot)
  - on_set_pivot DruidEvent DruidEvent
on_set_text
  On set text callback(self, text)
  - on_set_text DruidEvent DruidEvent
on_update_text_scale
  On adjust text size callback(self, new_scale, text_metrics)
  - on_update_text_scale DruidEvent DruidEvent
pos
  Current text position
  - pos vector3
scale
  Current text node scale
  - scale vector3
start_scale
  Initial text node scale
  - start_scale vector3
start_size
  Initial text node size
  - start_size vector3
text_area
  Current text node available are
  - text_area vector3

generated by LDoc TESTING Last updated 2015-01-01 12:00:00