mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 10:02:18 +02:00
Rich Text example progress
This commit is contained in:
@@ -72,7 +72,7 @@ nodes {
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
x: -200.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
@@ -108,7 +108,7 @@ nodes {
|
||||
id: "text_prefab"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
pivot: PIVOT_W
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
@@ -138,7 +138,7 @@ nodes {
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 110.0
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
|
@@ -73,6 +73,7 @@ function RichText:_get_settings()
|
||||
size = gui.get_scale(self.text_prefab).x,
|
||||
image_scale = gui.get_scale(self.icon_prefab),
|
||||
default_animation = gui.get_flipbook(self.icon_prefab),
|
||||
--combine_words = true,
|
||||
}
|
||||
end
|
||||
|
||||
|
@@ -62,21 +62,6 @@ local V3_ZERO = vmath.vector3(0)
|
||||
---@field text_prefab Node
|
||||
|
||||
|
||||
local function deepcopy(orig)
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||
end
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
|
||||
-- Trim spaces on string start
|
||||
local function ltrim(text)
|
||||
return text:match('^%s*(.*)')
|
||||
@@ -161,11 +146,15 @@ local function get_text_metrics(word, previous_word, settings)
|
||||
local previous_word_metrics = resource.get_text_metrics(font_resource, previous_word.text)
|
||||
local union_metrics = resource.get_text_metrics(font_resource, previous_word.text .. text)
|
||||
|
||||
print("prev word metrics", previous_word_metrics.width, previous_word.text)
|
||||
print("union", union_metrics.width, previous_word.text .. text)
|
||||
print("current width", metrics.width, text)
|
||||
local without_previous_width = metrics.width
|
||||
metrics.width = (union_metrics.width - previous_word_metrics.width) * word_scale_x
|
||||
-- Since the several characters can be ajusted to fit the space between the previous word and this word
|
||||
-- For example: chars: [.,?!]
|
||||
metrics.offset_x = metrics.width - without_previous_width
|
||||
print("with prev word offset", metrics.offset_x, previous_word.text, text)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -650,7 +639,7 @@ function M.characters(word)
|
||||
|
||||
-- exit early if word is a single character or empty
|
||||
if word_length <= 1 then
|
||||
local char = deepcopy(word)
|
||||
local char = helper.deepcopy(word)
|
||||
char.node, char.metrics = create_node(char, parent, font)
|
||||
gui.set_pivot(char.node, pivot)
|
||||
gui.set_position(char.node, gui.get_position(word.node))
|
||||
@@ -664,7 +653,7 @@ function M.characters(word)
|
||||
local position_x = position.x
|
||||
|
||||
for i = 1, word_length do
|
||||
local char = deepcopy(word)
|
||||
local char = helper.deepcopy(word)
|
||||
chars[#chars + 1] = char
|
||||
char.text = utf8.sub(word.text, i, i)
|
||||
char.node, char.metrics = create_node(char, parent, font)
|
||||
|
@@ -173,6 +173,21 @@ function M.contains(t, value)
|
||||
end
|
||||
|
||||
|
||||
function M.deepcopy(orig_table)
|
||||
local orig_type = type(orig_table)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig_table, nil do
|
||||
copy[M.deepcopy(orig_key)] = M.deepcopy(orig_value)
|
||||
end
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig_table
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
|
||||
--- Get text metric from gui node. Replacement of previous gui.get_text_metrics_from_node function
|
||||
-- @tparam Node text_node
|
||||
-- @treturn table {width, height, max_ascent, max_descent}
|
||||
|
Reference in New Issue
Block a user