Module RichText
Druid Rich Text Custom Component.
# Overview #
This custom component is inspired by defold-richtext by britzl. It uses a similar syntax for tags but currently supports fewer tags.
Create Rich Text on your GUI Text Node. All properties of the text node will be used as default for the text.
# Notes #
• Nested tags are supported
Usage:
local RichText = require("druid.custom.rich_text.rich_text") ... self.rich_text = self.druid:new(RichText, "rich_text") self.rich_text:set_text("Hello, Druid Rich Text!")
type druid.rich_text.word = { node: Node, relative_scale: number, color: vector4, position: vector3, offset: vector3, scale: vector3, size: vector3, metrics: druid.rich_text.metrics, pivot: Pivot, text: string, shadow: vector4, outline: vector4, font: string, image: druid.rich_text.image, br: boolean, nobr: boolean, } type druid.rich_text.word.image = { texture: string, anim: string, width: number, height: number, } type druid.rich_text.lines_metrics = { text_width: number, text_height: number, lines: table<number, druid.rich_text.metrics>, } type druid.rich_text.metrics = { width: number, height: number, offset_x: number|nil, offset_y: number|nil, node_size: vector3|nil @For images only, }
Functions
characters(self, word) | Split a word into it's characters |
clear() | Clear all created words. |
get_line_metric() | Get current line metrics |
get_text(self) | Get current text |
get_words() | Get all current words. |
init(self, text_node, value) | The RichText constructor |
set_text(self, text) | Set text for Rich Text |
tagged(self, tag) | Get all words, which has a passed tag. |
Tables
style | Component style params. |
Fields
druid | The component druid instance |
root | The root node of the Rich Text |
text_prefab | The text prefab node |
Functions
- characters(self, word)
-
Split a word into it's characters
Parameters:
- self RichText RichText
- word druid.rich_text.word
Returns:
-
druid.rich_text.word[]
characters
- clear()
- Clear all created words.
- get_line_metric()
-
Get current line metrics
Returns:
-
druid.rich_text.lines_metrics
- get_text(self)
-
Get current text
Parameters:
- self RichText RichText
Returns:
-
string
text
- get_words()
-
Get all current words.
Returns:
-
table
druid.rich_text.word[]
- init(self, text_node, value)
-
The RichText constructor
Parameters:
- set_text(self, text)
-
Set text for Rich Text
Parameters:
Returns:
- druid.rich_text.word[] words
- druid.rich_text.lines_metrics line_metrics
Usage:
• color: Change text color <color=red>Foobar</color> <color=1.0,0,0,1.0>Foobar</color> <color=#ff0000>Foobar</color> <color=#ff0000ff>Foobar</color> • shadow: Change text shadow <shadow=red>Foobar</shadow> <shadow=1.0,0,0,1.0>Foobar</shadow> <shadow=#ff0000>Foobar</shadow> <shadow=#ff0000ff>Foobar</shadow> • outline: Change text shadow <outline=red>Foobar</outline> <outline=1.0,0,0,1.0>Foobar</outline> <outline=#ff0000>Foobar</outline> <outline=#ff0000ff>Foobar</outline> • font: Change font <font=MyCoolFont>Foobar</font> • size: Change text size, relative to default size <size=2>Twice as large</size> • br: Insert a line break <br/> • nobr: Prevent the text from breaking Words <nobr>inside tag</nobr> won't break • img: Display image <img=texture:image/> <img=texture:image,size/> <img=texture:image,width,height/>
- tagged(self, tag)
-
Get all words, which has a passed tag.
Parameters:
Returns:
-
druid.rich_text.word[]
words
Tables
- style
-
Component style params.
You can override this component styles params in Druid styles table
or create your own style
Fields:
- COLORS table or nil Rich Text color aliases. Default: {}
- ADJUST_STEPS number or nil Amount steps of attemps text adjust by height. Default: 20
- ADJUST_SCALE_DELTA number or nil Scale step on each height adjust step. Default: 0.02
Fields
- druid
-
The component druid instance
- druid DruidInstance DruidInstance
- root
-
The root node of the Rich Text
- root node
- text_prefab
-
The text prefab node
- text_prefab node