# 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.

All parameters for the Rich Text component are adjusted in the GUI scene.

This component uses GUI component template. (/druid/custom/rich_text/rich_text.gui).

You able to customize it or make your own with the next node scructure:

root

- text_prefab

- icon_prefab

# Rich Text Setup #

• Root node size: Set the maximum width and height of the text.

• Root anchor: Define the alignment of the Rich Text inside the root node size area.

• Text prefab: Configure all default text parameters for the text node.

• Text prefab anchor: Set the anchor for each text node (adjust this only if animating text).

• Icon prefab: Configure all default node parameters for the icon node.

• Icon prefab anchor: Set the anchor for each icon node (adjust this only if animating the icon).

# Notes #

• Nested tags are supported

Example Link

### 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,
        default_animation: string,
        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

clear() | Clear all created words.
get_line_metric() | Get current line metrics
get_words() | Get all current words.
init(self, template, nodes) | The RichText constructor
set_text(self, text) | Set text for Rich Text
tagged(tag) | Get all words, which has a passed tag.

## Tables

style | Component style params.

## Fields

druid | The component druid instance

## Functions

clear()
  Clear all created words.
get_line_metric()
  Get current line metrics

  ### Returns:

  druid.rich_text.lines_metrics
get_words()
  Get all current words.

  ### Returns:

  table druid.rich_text.word[]
init(self, template, nodes)
  The RichText constructor

  ### Parameters:

  - self RichText RichText
  - template string The Rich Text template name
  - nodes table The node table, if prefab was copied by gui.clone_tree()
set_text(self, text)
  Set text for Rich Text

  ### Parameters:

  - self RichText RichText
  - text string The text to set

  ### Returns:

  1. druid.rich_text.word[] words
  2. 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(tag)
  Get all words, which has a passed tag.

  ### Parameters:

  - tag string

  ### 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 Rich Text color aliases (default {})
  - ADJUST_STEPS number Amount steps of attemps text adjust by height (default 20)
  - ADJUST_SCALE_DELTA number Scale step on each height adjust step (default 0.02)

## Fields

druid
  The component druid instance
  - druid DruidInstance DruidInstance

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