mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Start update docs
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
-- Author: Britzl
|
||||
-- Modified by: Insality
|
||||
|
||||
--- RT
|
||||
-- @module rich_text.rt
|
||||
-- @local
|
||||
|
||||
local helper = require("druid.helper")
|
||||
local parser = require("druid.custom.rich_text.module.rt_parse")
|
||||
local utf8_lua = require("druid.system.utf8")
|
||||
@@ -203,6 +207,7 @@ function M._fill_properties(word, metrics, settings)
|
||||
word.position = vmath.vector3(0)
|
||||
|
||||
if word.image then
|
||||
-- Image properties
|
||||
word.scale = gui.get_scale(settings.node_prefab) * word.relative_scale * settings.adjust_scale
|
||||
word.pivot = gui.get_pivot(settings.node_prefab)
|
||||
word.size = metrics.node_size
|
||||
@@ -212,6 +217,7 @@ function M._fill_properties(word, metrics, settings)
|
||||
word.size.x = word.image.width
|
||||
end
|
||||
else
|
||||
-- Text properties
|
||||
word.scale = gui.get_scale(settings.text_prefab) * word.relative_scale * settings.adjust_scale
|
||||
word.pivot = gui.get_pivot(settings.text_prefab)
|
||||
word.size = vmath.vector3(metrics.width, metrics.height, 0)
|
||||
@@ -510,32 +516,6 @@ function M.is_fit_info_area(lines, settings)
|
||||
end
|
||||
|
||||
|
||||
--- Detected click/touch events on words with an anchor tag
|
||||
-- These words act as "hyperlinks" and will generate a message when clicked
|
||||
-- @param words Words to search for anchor tags
|
||||
-- @param action The action table from on_input
|
||||
-- @return true if a word was clicked, otherwise false
|
||||
function M.on_click(words, action)
|
||||
for i = 1, #words do
|
||||
local word = words[i]
|
||||
if word.anchor and gui.pick_node(word.node, action.x, action.y) then
|
||||
if word.tags and word.tags.a then
|
||||
local message = {
|
||||
node_id = gui.get_id(word.node),
|
||||
text = word.text,
|
||||
x = action.x, y = action.y,
|
||||
screen_x = action.screen_x, screen_y = action.screen_y
|
||||
}
|
||||
msg.post("#", word.tags.a, message)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
--- Get all words with a specific tag
|
||||
-- @param words The words to search (as received from richtext.create)
|
||||
-- @param tag The tag to search for. Nil to search for words without a tag
|
||||
|
@@ -1,7 +1,18 @@
|
||||
-- Copyright (c) 2022 Maksim Tuprikov <insality@gmail.com>. This code is licensed under MIT license
|
||||
|
||||
--- Druid Rich Text custom component.
|
||||
-- It's wrapper on Input component with cursor and placeholder text
|
||||
-- @module RichText
|
||||
-- @within BaseComponent
|
||||
-- @alias druid.rich_text
|
||||
|
||||
--- The component druid instance
|
||||
-- @tfield DruidInstance druid @{DruidInstance}
|
||||
|
||||
|
||||
local component = require("druid.component")
|
||||
local rich_text = require("druid.custom.rich_text.module.rt")
|
||||
|
||||
---@class druid.rich_text
|
||||
local RichText = component.create("rich_text")
|
||||
|
||||
local SCHEME = {
|
||||
@@ -14,9 +25,9 @@ local SCHEME = {
|
||||
function RichText:init(template, nodes)
|
||||
self:set_template(template)
|
||||
self:set_nodes(nodes)
|
||||
|
||||
self.root = self:get_node(SCHEME.ROOT)
|
||||
self.druid = self:get_druid()
|
||||
self.root_size = gui.get_size(self.root)
|
||||
|
||||
self.text_prefab = self:get_node(SCHEME.TEXT_PREFAB)
|
||||
self.icon_prefab = self:get_node(SCHEME.ICON_PREFAB)
|
||||
@@ -24,12 +35,10 @@ function RichText:init(template, nodes)
|
||||
gui.set_enabled(self.text_prefab, false)
|
||||
gui.set_enabled(self.icon_prefab, false)
|
||||
|
||||
self._settings = self:_get_settings()
|
||||
self._settings = self:_create_settings()
|
||||
end
|
||||
|
||||
|
||||
---@param text string
|
||||
---@return rich_text.word[], rich_text.lines_metrics
|
||||
function RichText:set_text(text)
|
||||
self:clean()
|
||||
|
||||
@@ -57,24 +66,25 @@ function RichText:tagged(tag)
|
||||
end
|
||||
|
||||
|
||||
---@return druid.rich_text_word[]
|
||||
function RichText:get_words()
|
||||
return self._words
|
||||
end
|
||||
|
||||
|
||||
function RichText:_get_settings()
|
||||
function RichText:_create_settings()
|
||||
local root_size = gui.get_size(self.root)
|
||||
return {
|
||||
-- General settings
|
||||
-- Adjust scale using to fit the text to the root node area
|
||||
adjust_scale = 1,
|
||||
parent = self.root,
|
||||
width = self.root_size.x,
|
||||
height = self.root_size.y,
|
||||
width = root_size.x,
|
||||
height = root_size.y,
|
||||
combine_words = false,
|
||||
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),
|
||||
text_scale = gui.get_scale(self.text_prefab),
|
||||
@@ -82,7 +92,6 @@ function RichText:_get_settings()
|
||||
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),
|
||||
image_scale = gui.get_scale(self.icon_prefab),
|
||||
|
Reference in New Issue
Block a user