Update Rich text style params

This commit is contained in:
Insality
2023-08-05 19:01:06 +03:00
parent 5a0cf42e3d
commit 628723386e
8 changed files with 123 additions and 83 deletions

View File

@@ -59,7 +59,6 @@
-- font: string,
-- image: druid.rich_text.image,
-- default_animation: string,
-- anchor: number,
-- br: boolean,
-- nobr: boolean,
-- }
@@ -125,6 +124,21 @@ function RichText.init(self, template, nodes)
end
--- Component style params.
-- You can override this component styles params in Druid styles table
-- or create your own style
-- @table style
-- @tfield[opt={}] table COLORS Rich Text color aliases
-- @tfield[opt=20] number ADJUST_STEPS Amount steps of attemps text adjust by height
-- @tfield[opt=0.02] number ADJUST_SCALE_DELTA Scale step on each height adjust step
function RichText.on_style_change(self, style)
self.style = {}
self.style.COLORS = style.COLORS or {}
self.style.ADJUST_STEPS = style.ADJUST_STEPS or 20
self.style.ADJUST_SCALE_DELTA = style.ADJUST_SCALE_DELTA or 0.02
end
--- Set text for Rich Text
-- @tparam RichText self @{RichText}
-- @tparam string text The text to set
@@ -174,10 +188,10 @@ end
-- <img=texture:image,size/>
-- <img=texture:image,width,height/>
function RichText.set_text(self, text)
self:clean()
self:clear()
local words, settings, line_metrics = rich_text.create(text, self._settings)
line_metrics = rich_text.adjust_to_area(words, settings, line_metrics)
local words, settings, line_metrics = rich_text.create(text, self._settings, self.style)
line_metrics = rich_text.adjust_to_area(words, settings, line_metrics, self.style)
self._words = words
self._line_metrics = line_metrics
@@ -187,13 +201,22 @@ end
function RichText:on_remove()
self:clean()
self:clear()
end
--- Get all words, which has a passed tag
--- Clear all created words.
function RichText:clear()
if self._words then
rich_text.remove(self._words)
self._words = nil
end
end
--- Get all words, which has a passed tag.
-- @tparam string tag
-- @treturn table Words
-- @treturn druid.rich_text.word[] words
function RichText:tagged(tag)
if not self._words then
return
@@ -204,12 +227,19 @@ end
--- Get all current words.
-- @treturn table Words
-- @treturn table druid.rich_text.word[]
function RichText:get_words()
return self._words
end
--- Get current line metrics
--- @treturn druid.rich_text.lines_metrics
function RichText:get_line_metric()
return self._line_metrics
end
function RichText:_create_settings()
local root_size = gui.get_size(self.root)
return {
@@ -219,7 +249,7 @@ function RichText:_create_settings()
parent = self.root,
width = root_size.x,
height = root_size.y,
combine_words = false,
combine_words = false, -- disabled now
text_prefab = self.text_prefab,
node_prefab = self.icon_prefab,
@@ -231,7 +261,7 @@ function RichText:_create_settings()
is_multiline = gui.get_line_break(self.text_prefab),
-- Image settings
image_pixel_grid_snap = false,
image_pixel_grid_snap = false, -- disabled now
node_scale = gui.get_scale(self.icon_prefab),
image_scale = gui.get_scale(self.icon_prefab),
default_animation = gui.get_flipbook(self.icon_prefab),
@@ -239,13 +269,4 @@ function RichText:_create_settings()
end
--- Clear all created words.
function RichText:clean()
if self._words then
rich_text.remove(self._words)
self._words = nil
end
end
return RichText