mirror of
https://github.com/Insality/druid
synced 2025-06-27 10:27:48 +02:00
Update annotations, fix rare errors
This commit is contained in:
parent
b9b74736a7
commit
d39f4715f3
@ -1846,19 +1846,24 @@ function helper.table_to_string(t) end
|
||||
---@class druid.rich_text.word
|
||||
---@field node node
|
||||
---@field relative_scale number
|
||||
---@field adjust_scale number
|
||||
---@field color vector4
|
||||
---@field position vector3
|
||||
---@field offset vector3
|
||||
---@field scale vector3
|
||||
---@field size vector3
|
||||
---@field metrics druid.rich_text.metrics
|
||||
---@field pivot number @ The gui.PIVOT_* constant
|
||||
---@field pivot userdata @ The gui.PIVOT_* constant
|
||||
---@field text string
|
||||
---@field source_text string
|
||||
---@field text_color vector4
|
||||
---@field shadow vector4
|
||||
---@field outline vector4
|
||||
---@field font string
|
||||
---@field image druid.rich_text.image
|
||||
---@field image_color vector4
|
||||
---@field default_animation string
|
||||
---@field default_texture string
|
||||
---@field anchor number
|
||||
---@field br boolean
|
||||
---@field nobr boolean
|
||||
@ -1880,8 +1885,10 @@ function helper.table_to_string(t) end
|
||||
---@field image_pixel_grid_snap boolean
|
||||
---@field combine_words boolean
|
||||
---@field default_animation string
|
||||
---@field default_texture string
|
||||
---@field node_prefab node
|
||||
---@field text_prefab node
|
||||
---@field is_multiline boolean
|
||||
|
||||
---@class GUITextMetrics
|
||||
---@field width number
|
||||
|
@ -351,7 +351,7 @@ function Scroll.set_size(self, size, offset)
|
||||
end
|
||||
|
||||
|
||||
--- Set scroll view size.
|
||||
--- Set new scroll view size in case the node size was changed.
|
||||
-- @tparam Scroll self @{Scroll}
|
||||
-- @tparam vector3 size The new size for view node
|
||||
-- @treturn druid.scroll Current scroll instance
|
||||
|
@ -71,10 +71,10 @@ function M.length(text)
|
||||
end
|
||||
|
||||
|
||||
---@param word rich_text.word
|
||||
---@param previous_word rich_text.word|nil
|
||||
---@param settings rich_text.settings
|
||||
---@return rich_text.metrics
|
||||
---@param word druid.rich_text.word
|
||||
---@param previous_word druid.rich_text.word|nil
|
||||
---@param settings druid.rich_text.settings
|
||||
---@return druid.rich_text.metrics
|
||||
local function get_text_metrics(word, previous_word, settings)
|
||||
local text = word.text
|
||||
local font_resource = gui.get_font_resource(word.font)
|
||||
@ -117,7 +117,8 @@ end
|
||||
---@return druid.rich_text.metrics
|
||||
local function get_image_metrics(word, settings)
|
||||
local node_prefab = settings.node_prefab
|
||||
gui.play_flipbook(node_prefab, word.image.anim)
|
||||
gui.set_texture(node_prefab, word.image.texture or settings.default_texture)
|
||||
gui.play_flipbook(node_prefab, word.image.anim or settings.default_animation)
|
||||
local node_size = gui.get_size(node_prefab)
|
||||
local aspect = node_size.x / node_size.y
|
||||
node_size.x = word.image.width or node_size.x
|
||||
@ -145,8 +146,9 @@ end
|
||||
--- @param text string The text to create rich text nodes from
|
||||
--- @param settings table Optional settings table (refer to documentation for details)
|
||||
--- @param style druid.rich_text.style
|
||||
--- @return words
|
||||
--- @return metrics
|
||||
--- @return druid.rich_text.word[]
|
||||
--- @return druid.rich_text.settings
|
||||
--- @return druid.rich_text.lines_metrics
|
||||
function M.create(text, settings, style)
|
||||
assert(text, "You must provide a text")
|
||||
|
||||
@ -171,10 +173,9 @@ function M.create(text, settings, style)
|
||||
outline = settings.outline,
|
||||
font = font,
|
||||
-- Image params
|
||||
---@type rich_text.word.image
|
||||
---@type druid.rich_text.image
|
||||
image = nil,
|
||||
image_color = gui.get_color(settings.node_prefab),
|
||||
default_animation = nil,
|
||||
-- Tags
|
||||
br = nil,
|
||||
nobr = nil,
|
||||
@ -237,9 +238,6 @@ function M._split_on_lines(words, settings)
|
||||
if word == nil then
|
||||
break
|
||||
end
|
||||
if word.image then
|
||||
word.default_animation = settings.default_animation
|
||||
end
|
||||
|
||||
-- Reset texts to start measure again
|
||||
word.text = word.source_text
|
||||
@ -308,9 +306,9 @@ function M._split_on_lines(words, settings)
|
||||
end
|
||||
|
||||
|
||||
---@param lines rich_text.word[][]
|
||||
---@param settings rich_text.settings
|
||||
---@return rich_text.lines_metrics
|
||||
---@param lines druid.rich_text.word[][]
|
||||
---@param settings druid.rich_text.settings
|
||||
---@return druid.rich_text.lines_metrics
|
||||
function M._position_lines(lines, settings)
|
||||
local lines_metrics = M._get_lines_metrics(lines, settings)
|
||||
-- current x-y is left top point of text spawn
|
||||
@ -355,9 +353,9 @@ function M._position_lines(lines, settings)
|
||||
end
|
||||
|
||||
|
||||
---@param lines rich_text.word[][]
|
||||
---@param settings rich_text.settings
|
||||
---@return rich_text.lines_metrics
|
||||
---@param lines druid.rich_text.word[][]
|
||||
---@param settings druid.rich_text.settings
|
||||
---@return druid.rich_text.lines_metrics
|
||||
function M._get_lines_metrics(lines, settings)
|
||||
local metrics = {}
|
||||
local text_width = 0
|
||||
@ -389,7 +387,7 @@ function M._get_lines_metrics(lines, settings)
|
||||
}
|
||||
end
|
||||
|
||||
---@type rich_text.lines_metrics
|
||||
---@type druid.rich_text.lines_metrics
|
||||
local lines_metrics = {
|
||||
text_width = text_width,
|
||||
text_height = text_height,
|
||||
@ -400,8 +398,8 @@ function M._get_lines_metrics(lines, settings)
|
||||
end
|
||||
|
||||
|
||||
---@param lines rich_text.word[][]
|
||||
---@param settings rich_text.settings
|
||||
---@param lines druid.rich_text.word[][]
|
||||
---@param settings druid.rich_text.settings
|
||||
function M._update_nodes(lines, settings)
|
||||
for line_index = 1, #lines do
|
||||
local line = lines[line_index]
|
||||
@ -411,7 +409,8 @@ function M._update_nodes(lines, settings)
|
||||
if word.image then
|
||||
node = word.node or gui.clone(settings.node_prefab)
|
||||
gui.set_size_mode(node, gui.SIZE_MODE_MANUAL)
|
||||
gui.play_flipbook(node, hash(word.image.anim or word.default_animation))
|
||||
gui.set_texture(node, word.image.texture or settings.default_texture)
|
||||
gui.play_flipbook(node, hash(word.image.anim or settings.default_animation))
|
||||
gui.set_color(node, word.color or word.image_color)
|
||||
else
|
||||
node = word.node or gui.clone(settings.text_prefab)
|
||||
@ -432,10 +431,10 @@ function M._update_nodes(lines, settings)
|
||||
end
|
||||
|
||||
|
||||
---@param words rich_text.word[]
|
||||
---@param settings rich_text.settings
|
||||
---@param words druid.rich_text.word[]
|
||||
---@param settings druid.rich_text.settings
|
||||
---@param scale number
|
||||
---@return rich_text.lines_metrics
|
||||
---@return druid.rich_text.lines_metrics
|
||||
function M.set_text_scale(words, settings, scale)
|
||||
settings.adjust_scale = scale
|
||||
|
||||
@ -499,15 +498,15 @@ function M.adjust_to_area(words, settings, lines_metrics, style)
|
||||
end
|
||||
|
||||
|
||||
---@return boolean @If we fit into area size
|
||||
---@return druid.rich_text.word[][] lines
|
||||
function M.apply_scale_without_update(words, settings, scale)
|
||||
settings.adjust_scale = scale
|
||||
return M._split_on_lines(words, settings)
|
||||
end
|
||||
|
||||
|
||||
---@param lines rich_text.word[][]
|
||||
---@param settings rich_text.settings
|
||||
---@param lines druid.rich_text.word[][]
|
||||
---@param settings druid.rich_text.settings
|
||||
function M.is_fit_info_area(lines, settings)
|
||||
local lines_metrics = M._get_lines_metrics(lines, settings)
|
||||
local area_size = gui.get_size(settings.parent)
|
||||
|
@ -149,7 +149,7 @@ function M.parse(text, default_settings, style)
|
||||
end
|
||||
|
||||
-- parse the tag, split into name and optional parameters
|
||||
local endtag, name, params, empty = tag:match("<(/?)(%a+)=?(%S-)(/?)>")
|
||||
local endtag, name, params, empty = tag:match("<(/?)([%a_]+)=?(%S-)(/?)>")
|
||||
|
||||
local is_endtag = endtag == "/"
|
||||
local is_empty = empty == "/"
|
||||
|
@ -210,7 +210,15 @@ function RichText.set_text(self, text)
|
||||
end
|
||||
|
||||
|
||||
function RichText.get_text(self)
|
||||
return self._last_value
|
||||
end
|
||||
|
||||
|
||||
function RichText:on_remove()
|
||||
pcall(gui.set_texture, self.icon_prefab, self._settings.default_texture)
|
||||
pcall(gui.play_flipbook, self.icon_prefab, self._settings.default_animation)
|
||||
|
||||
self:clear()
|
||||
end
|
||||
|
||||
@ -238,6 +246,15 @@ function RichText.tagged(self, tag)
|
||||
end
|
||||
|
||||
|
||||
---Split a word into it's characters
|
||||
-- @tparam RichText self @{RichText}
|
||||
-- @tparam druid.rich_text.word word
|
||||
-- @treturn druid.rich_text.word[] characters
|
||||
function RichText.characters(self, word)
|
||||
return rich_text.characters(word)
|
||||
end
|
||||
|
||||
|
||||
--- Get all current words.
|
||||
-- @treturn table druid.rich_text.word[]
|
||||
function RichText:get_words()
|
||||
@ -277,6 +294,7 @@ function RichText:_create_settings()
|
||||
node_scale = gui.get_scale(self.icon_prefab),
|
||||
image_scale = gui.get_scale(self.icon_prefab),
|
||||
default_animation = gui.get_flipbook(self.icon_prefab),
|
||||
default_texture = gui.get_texture(self.icon_prefab),
|
||||
}
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user