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_size(self[, text]) Calculate text width with font with respect to trailing space
init(self, node[, value[, adjust_type=downscale]]) 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_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
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_size(self[, text])
Calculate text width with font with respect to trailing space

Parameters:

Returns:

  1. number Width
  2. number Height
init(self, node[, value[, adjust_type=downscale]])
Text constructor

Parameters:

  • self Text Text
  • node string or node Node name or GUI Text Node itself
  • value string Initial text. Default value is node text from GUI scene. (optional)
  • adjust_type string 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:

Returns:

    bool 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 gui.pivot 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_text_adjust(self[, adjust_type[, minimal_scale]])
Set text adjust, refresh the current text visuals, if needed

Parameters:

  • self Text Text
  • adjust_type number See const.TEXT_ADJUST. If pass nil - use current adjust type (optional)
  • minimal_scale number If pass nil - not use minimal scale (optional)

Returns:

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

Parameters:

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 The postfix for TRIM adjust type (default ...)
  • DEFAULT_ADJUST string The default adjust type for any text component (default DOWNSCALE)

Fields

adjust_type
Current text size adjust settings
  • adjust_type number
color
Current text color
  • color vector3
node
Text node
node_id
The node id of text node
  • node_id hash
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
  • 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