mirror of
https://github.com/Insality/druid
synced 2025-09-28 02:22:19 +02:00
Update annotations P.1
This commit is contained in:
@@ -18,10 +18,10 @@
|
||||
-- @alias druid.lang_text
|
||||
|
||||
--- On change text callback
|
||||
-- @tfield DruidEvent on_change @{DruidEvent}
|
||||
-- @tfield DruidEvent on_change DruidEvent
|
||||
|
||||
--- The text component
|
||||
-- @tfield Text text @{Text}
|
||||
-- @tfield Text text Text
|
||||
|
||||
--- Text node
|
||||
-- @tfield node node
|
||||
@@ -32,15 +32,21 @@ local Event = require("druid.event")
|
||||
local settings = require("druid.system.settings")
|
||||
local component = require("druid.component")
|
||||
|
||||
local LangText = component.create("lang_text")
|
||||
---@class druid.lang_text: druid.base_component
|
||||
---@field text druid.text
|
||||
---@field node node
|
||||
---@field on_change druid.event
|
||||
---@field private last_locale_args table
|
||||
---@field private last_locale string
|
||||
local M = component.create("lang_text")
|
||||
|
||||
|
||||
--- The @{LangText} constructor
|
||||
-- @tparam LangText self @{LangText}
|
||||
--- The LangText constructor
|
||||
-- @tparam LangText self LangText
|
||||
-- @tparam string|node node The node_id or gui.get_node(node_id)
|
||||
-- @tparam string|nil locale_id Default locale id or text from node as default
|
||||
-- @tparam string|nil adjust_type Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
|
||||
function LangText.init(self, node, locale_id, adjust_type)
|
||||
function M:init(node, locale_id, adjust_type)
|
||||
self.druid = self:get_druid()
|
||||
self.text = self.druid:new_text(node, locale_id, adjust_type)
|
||||
self.node = self.text.node
|
||||
@@ -55,7 +61,7 @@ function LangText.init(self, node, locale_id, adjust_type)
|
||||
end
|
||||
|
||||
|
||||
function LangText.on_language_change(self)
|
||||
function M:on_language_change()
|
||||
if self.last_locale then
|
||||
self:translate(self.last_locale, unpack(self.last_locale_args))
|
||||
end
|
||||
@@ -63,10 +69,10 @@ end
|
||||
|
||||
|
||||
--- Setup raw text to lang_text component
|
||||
-- @tparam LangText self @{LangText}
|
||||
-- @tparam LangText self LangText
|
||||
-- @tparam string text Text for text node
|
||||
-- @treturn LangText Current instance
|
||||
function LangText.set_to(self, text)
|
||||
function M:set_to(text)
|
||||
self.last_locale = false
|
||||
self.text:set_to(text)
|
||||
self.on_change:trigger()
|
||||
@@ -76,7 +82,7 @@ end
|
||||
|
||||
|
||||
--- Translate the text by locale_id
|
||||
-- @tparam LangText self @{LangText}
|
||||
-- @tparam LangText self LangText
|
||||
-- @tparam string locale_id Locale id
|
||||
-- @tparam string|nil a Optional param to string.format
|
||||
-- @tparam string|nil b Optional param to string.format
|
||||
@@ -86,7 +92,7 @@ end
|
||||
-- @tparam string|nil f Optional param to string.format
|
||||
-- @tparam string|nil g Optional param to string.format
|
||||
-- @treturn LangText Current instance
|
||||
function LangText.translate(self, locale_id, a, b, c, d, e, f, g)
|
||||
function M:translate(locale_id, a, b, c, d, e, f, g)
|
||||
self.last_locale_args = { a, b, c, d, e, f, g }
|
||||
self.last_locale = locale_id or self.last_locale
|
||||
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
||||
@@ -96,7 +102,7 @@ end
|
||||
|
||||
|
||||
--- Format string with new text params on localized text
|
||||
-- @tparam LangText self @{LangText}
|
||||
-- @tparam LangText self LangText
|
||||
-- @tparam string|nil a Optional param to string.format
|
||||
-- @tparam string|nil b Optional param to string.format
|
||||
-- @tparam string|nil c Optional param to string.format
|
||||
@@ -105,11 +111,11 @@ end
|
||||
-- @tparam string|nil f Optional param to string.format
|
||||
-- @tparam string|nil g Optional param to string.format
|
||||
-- @treturn LangText Current instance
|
||||
function LangText.format(self, a, b, c, d, e, f, g)
|
||||
function M:format(a, b, c, d, e, f, g)
|
||||
self.last_locale_args = { a, b, c, d, e, f, g }
|
||||
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
return LangText
|
||||
return M
|
||||
|
Reference in New Issue
Block a user