5.4 KiB
druid.text API
at /druid/base/text.lua
The component to handle text behaviour over a GUI Text node, mainly used to automatically adjust text size to fit the text area
Functions
- init
- get_text_size
- get_text_index_by_width
- set_to
- set_text
- get_text
- set_size
- set_color
- set_alpha
- set_scale
- set_pivot
- is_multiline
- set_text_adjust
- set_minimal_scale
- get_text_adjust
Fields
- node
- on_set_text
- on_update_text_scale
- on_set_pivot
- style
- pos
- node_id
- start_size
- text_area
- adjust_type
- color
- last_value
- last_scale
init
text:init(node, [value], [adjust_type])
The Text constructor
- Parameters:
node
(string|node): Node name or GUI Text Node itself[value]
(string|nil): Initial text. Default value is node text from GUI scene. Default: nil[adjust_type]
(string|nil): Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference. Default: DOWNSCALE
get_text_size
text:get_text_size([text])
Calculate text width with font with respect to trailing space
-
Parameters:
[text]
(string|nil): The text to calculate the size of, if nil - use current text
-
Returns:
width
(number): The text widthheight
(number): The text height
get_text_index_by_width
text:get_text_index_by_width(width)
Get chars count by width
-
Parameters:
width
(number): The width to get the chars count of
-
Returns:
index
(number): The chars count
set_to
text:set_to(set_to)
Set text to text field
-
Parameters:
set_to
(string): Text for node
-
Returns:
self
(druid.text): Current text instance
set_text
text:set_text([new_text])
-
Parameters:
[new_text]
(any):
-
Returns:
- `` (druid.text):
get_text
text:get_text()
- Returns:
- `` (unknown):
set_size
text:set_size(size)
Set text area size
-
Parameters:
size
(vector3): The new text area size
-
Returns:
self
(druid.text): Current text instance
set_color
text:set_color(color)
Set color
-
Parameters:
color
(vector4): Color for node
-
Returns:
self
(druid.text): Current text instance
set_alpha
text:set_alpha(alpha)
Set alpha
-
Parameters:
alpha
(number): Alpha for node
-
Returns:
self
(druid.text): Current text instance
set_scale
text:set_scale(scale)
Set scale
-
Parameters:
scale
(vector3): Scale for node
-
Returns:
self
(druid.text): Current text instance
set_pivot
text:set_pivot(pivot)
Set text pivot. Text will re-anchor inside text area
-
Parameters:
pivot
(userdata): The gui.PIVOT_* constant
-
Returns:
self
(druid.text): Current text instance
is_multiline
text:is_multiline()
Return true, if text with line break
- Returns:
Is
(boolean): text node with line break
set_text_adjust
text:set_text_adjust([adjust_type], [minimal_scale])
Set text adjust, refresh the current text visuals, if needed Values are: "downscale", "trim", "no_adjust", "downscale_limited", "scroll", "scale_then_scroll", "trim_left", "scale_then_trim", "scale_then_trim_left"
-
Parameters:
[adjust_type]
(string|nil): See const.TEXT_ADJUST. If pass nil - use current adjust type[minimal_scale]
(number|nil): To remove minimal scale, usetext:set_minimal_scale(nil)
, if pass nil - not change minimal scale
-
Returns:
self
(druid.text): Current text instance
set_minimal_scale
text:set_minimal_scale(minimal_scale)
Set minimal scale for DOWNSCALE_LIMITED or SCALE_THEN_SCROLL adjust types
-
Parameters:
minimal_scale
(number): If pass nil - not use minimal scale
-
Returns:
self
(druid.text): Current text instance
get_text_adjust
text:get_text_adjust()
Return current text adjust type
- Returns:
adjust_type
(string): The current text adjust type
Fields
- node (node): The text node
- on_set_text (event): The event triggered when the text is set, fun(self, text)
- on_update_text_scale (event): The event triggered when the text scale is updated, fun(self, scale, metrics)
- on_set_pivot (event): The event triggered when the text pivot is set, fun(self, pivot)
- style (druid.text.style): The style of the text
- pos (unknown)
- node_id (unknown)
- start_size (unknown)
- text_area (unknown)
- adjust_type (string|nil)
- color (unknown)
- last_value (unknown)
- last_scale (vector3)