Update examples

This commit is contained in:
Insality
2023-05-31 21:54:55 +03:00
parent a01eae3d89
commit b628212c58
21 changed files with 3306 additions and 164 deletions

View File

@@ -3,7 +3,7 @@
-- Modified by: Insality
local helper = require("druid.helper")
local parser = require("druid.custom.rich_text.rich_text.parse")
local parser = require("druid.custom.rich_text.module.rt_parse")
local utf8_lua = require("druid.system.utf8")
local utf8 = utf8 or utf8_lua
@@ -462,6 +462,7 @@ function M._update_nodes(lines, settings)
gui.set_shadow(node, word.shadow)
gui.set_text(node, word.text)
gui.set_color(node, word.color or word.text_color)
gui.set_font(node, word.font or settings.font)
end
word.node = node
gui.set_enabled(node, true)

View File

@@ -2,7 +2,7 @@
-- Author: Britzl
-- Modified by: Insality
local tags = require("druid.custom.rich_text.rich_text.tags")
local tags = require("druid.custom.rich_text.module.rt_tags")
local utf8_lua = require("druid.system.utf8")
local utf8 = utf8 or utf8_lua

View File

@@ -2,7 +2,7 @@
-- Author: Britzl
-- Modified by: Insality
local color = require("druid.custom.rich_text.rich_text.color")
local color = require("druid.custom.rich_text.module.rt_color")
local M = {}
@@ -41,6 +41,9 @@ local function split(s, token)
end
-- Format: <color=[#]{HEX_VALUE}>{Text}</color>
-- Format: <color={COLOR_NAME}>{Text}</color>
-- Example: <color=FF0000>Rich Text</color>
M.register("color", function(params, settings)
settings.color = color.parse(params)
end)
@@ -71,16 +74,22 @@ M.register("a", function(params, settings)
end)
-- Example: </br>
M.register("br", function(params, settings)
settings.br = true
end)
-- Example: <nobr></nobr>
M.register("nobr", function(params, settings)
settings.nobr = true
end)
-- Format: <img={animation_id},[width],[height]/>
-- Example: <img=logo/>
-- Example: <img=logo,48/>
-- Example: <img=logo,48,48/>
M.register("img", function(params, settings)
local texture_and_anim, params = split(params, ",")
local width, height

View File

@@ -1,5 +1,5 @@
local component = require("druid.component")
local rich_text = require("druid.custom.rich_text.rich_text.richtext")
local rich_text = require("druid.custom.rich_text.module.rt")
---@class druid.rich_text
local RichText = component.create("rich_text")
@@ -28,6 +28,7 @@ function RichText:init(template, nodes)
end
---@param text string
---@return rich_text.word[], rich_text.lines_metrics
function RichText:set_text(text)
self:clean()
@@ -64,6 +65,7 @@ end
function RichText:_get_settings()
return {
-- General settings
adjust_scale = 1,
parent = self.root,
width = self.root_size.x,
@@ -71,6 +73,7 @@ function RichText:_get_settings()
text_prefab = self.text_prefab,
node_prefab = self.icon_prefab,
-- Text Settings
size = gui.get_scale(self.text_prefab).x,
shadow = gui.get_shadow(self.text_prefab),
outline = gui.get_outline(self.text_prefab),
@@ -78,6 +81,7 @@ function RichText:_get_settings()
text_leading = gui.get_leading(self.text_prefab),
is_multiline = gui.get_line_break(self.text_prefab),
-- Image settings
combine_words = false,
image_pixel_grid_snap = false,
node_scale = gui.get_scale(self.icon_prefab),
@@ -88,12 +92,10 @@ end
function RichText:clean()
if not self._words then
return
if self._words then
rich_text.remove(self._words)
self._words = nil
end
rich_text.remove(self._words)
self._words = nil
end