mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
Update rich text example
This commit is contained in:
parent
5e92cf5ffc
commit
a1d138522e
@ -64,16 +64,25 @@ end
|
|||||||
|
|
||||||
function RichText:_get_settings()
|
function RichText:_get_settings()
|
||||||
return {
|
return {
|
||||||
width = self.root_size.x,
|
adjust_scale = 1,
|
||||||
parent = self.root,
|
parent = self.root,
|
||||||
|
width = self.root_size.x,
|
||||||
|
height = self.root_size.y,
|
||||||
text_prefab = self.text_prefab,
|
text_prefab = self.text_prefab,
|
||||||
node_prefab = self.icon_prefab,
|
node_prefab = self.icon_prefab,
|
||||||
|
|
||||||
|
size = gui.get_scale(self.text_prefab).x,
|
||||||
shadow = gui.get_shadow(self.text_prefab),
|
shadow = gui.get_shadow(self.text_prefab),
|
||||||
outline = gui.get_outline(self.text_prefab),
|
outline = gui.get_outline(self.text_prefab),
|
||||||
size = gui.get_scale(self.text_prefab).x,
|
text_scale = gui.get_scale(self.text_prefab),
|
||||||
|
text_leading = gui.get_leading(self.text_prefab),
|
||||||
|
is_multiline = gui.get_line_break(self.text_prefab),
|
||||||
|
|
||||||
|
combine_words = false,
|
||||||
|
image_pixel_grid_snap = false,
|
||||||
|
node_scale = gui.get_scale(self.icon_prefab),
|
||||||
image_scale = gui.get_scale(self.icon_prefab),
|
image_scale = gui.get_scale(self.icon_prefab),
|
||||||
default_animation = gui.get_flipbook(self.icon_prefab),
|
default_animation = gui.get_flipbook(self.icon_prefab),
|
||||||
--combine_words = true,
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ local V3_ZERO = vmath.vector3(0)
|
|||||||
---@field shadow vector4
|
---@field shadow vector4
|
||||||
---@field outline vector4
|
---@field outline vector4
|
||||||
---@field position vector3
|
---@field position vector3
|
||||||
---@field line_spacing number
|
|
||||||
---@field image_pixel_grid_snap boolean
|
---@field image_pixel_grid_snap boolean
|
||||||
---@field combine_words boolean
|
---@field combine_words boolean
|
||||||
---@field default_animation string
|
---@field default_animation string
|
||||||
@ -146,15 +145,11 @@ local function get_text_metrics(word, previous_word, settings)
|
|||||||
local previous_word_metrics = resource.get_text_metrics(font_resource, previous_word.text)
|
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)
|
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
|
local without_previous_width = metrics.width
|
||||||
metrics.width = (union_metrics.width - previous_word_metrics.width) * word_scale_x
|
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
|
-- Since the several characters can be ajusted to fit the space between the previous word and this word
|
||||||
-- For example: chars: [.,?!]
|
-- For example: chars: [.,?!]
|
||||||
metrics.offset_x = metrics.width - without_previous_width
|
metrics.offset_x = metrics.width - without_previous_width
|
||||||
print("with prev word offset", metrics.offset_x, previous_word.text, text)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -202,22 +197,6 @@ end
|
|||||||
function M.create(text, settings)
|
function M.create(text, settings)
|
||||||
assert(text, "You must provide a text")
|
assert(text, "You must provide a text")
|
||||||
|
|
||||||
---@class rich_text.settings
|
|
||||||
settings = settings or {}
|
|
||||||
settings.adjust_scale = 1
|
|
||||||
settings.position = settings.position or V3_ZERO
|
|
||||||
settings.line_spacing = settings.line_spacing or 1
|
|
||||||
settings.image_pixel_grid_snap = settings.image_pixel_grid_snap or false
|
|
||||||
settings.combine_words = settings.combine_words or false
|
|
||||||
settings.default_animation = settings.default_animation or nil
|
|
||||||
settings.node_prefab = settings.node_prefab
|
|
||||||
settings.text_prefab = settings.text_prefab
|
|
||||||
settings.text_leading = gui.get_leading(settings.text_prefab)
|
|
||||||
settings.text_scale = gui.get_scale(settings.text_prefab)
|
|
||||||
settings.node_scale = gui.get_scale(settings.node_prefab)
|
|
||||||
settings.is_multiline = gui.get_line_break(settings.text_prefab)
|
|
||||||
settings.parent = settings.parent
|
|
||||||
|
|
||||||
-- default settings for a word
|
-- default settings for a word
|
||||||
-- will be assigned to each word unless tags override the values
|
-- will be assigned to each word unless tags override the values
|
||||||
local font = gui.get_font(settings.text_prefab)
|
local font = gui.get_font(settings.text_prefab)
|
||||||
@ -518,18 +497,17 @@ end
|
|||||||
function M.adjust_to_area(words, settings, lines_metrics)
|
function M.adjust_to_area(words, settings, lines_metrics)
|
||||||
local last_line_metrics = lines_metrics
|
local last_line_metrics = lines_metrics
|
||||||
|
|
||||||
local area_size = gui.get_size(settings.parent)
|
|
||||||
if not settings.is_multiline then
|
if not settings.is_multiline then
|
||||||
if lines_metrics.text_width > area_size.x then
|
if lines_metrics.text_width > settings.width then
|
||||||
last_line_metrics = M.set_text_scale(words, settings, area_size.x / lines_metrics.text_width)
|
last_line_metrics = M.set_text_scale(words, settings, settings.width / lines_metrics.text_width)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Multiline adjusting is very tricky stuff...
|
-- Multiline adjusting is very tricky stuff...
|
||||||
-- It's do a lot of calculations, beware!
|
-- It's do a lot of calculations, beware!
|
||||||
if lines_metrics.text_width > area_size.x or lines_metrics.text_height > area_size.y then
|
if lines_metrics.text_width > settings.width or lines_metrics.text_height > settings.height then
|
||||||
local scale_koef = math.sqrt(area_size.y / lines_metrics.text_height)
|
local scale_koef = math.sqrt(settings.height / lines_metrics.text_height)
|
||||||
if lines_metrics.text_width * scale_koef > area_size.x then
|
if lines_metrics.text_width * scale_koef > settings.width then
|
||||||
scale_koef = math.sqrt(area_size.x / lines_metrics.text_width)
|
scale_koef = math.sqrt(settings.width / lines_metrics.text_width)
|
||||||
end
|
end
|
||||||
local adjust_scale = math.min(scale_koef, 1)
|
local adjust_scale = math.min(scale_koef, 1)
|
||||||
|
|
||||||
|
@ -2599,7 +2599,7 @@ nodes {
|
|||||||
id: "rich_text_5_NW/icon_prefab"
|
id: "rich_text_5_NW/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_N
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_NW/root"
|
parent: "rich_text_5_NW/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -2615,6 +2615,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
@ -2893,7 +2894,7 @@ nodes {
|
|||||||
id: "rich_text_5_N/icon_prefab"
|
id: "rich_text_5_N/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_N
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_N/root"
|
parent: "rich_text_5_N/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -2909,6 +2910,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
@ -3187,7 +3189,7 @@ nodes {
|
|||||||
id: "rich_text_5_NE/icon_prefab"
|
id: "rich_text_5_NE/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_N
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_NE/root"
|
parent: "rich_text_5_NE/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -3203,6 +3205,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
@ -4362,7 +4365,7 @@ nodes {
|
|||||||
id: "rich_text_5_SW/icon_prefab"
|
id: "rich_text_5_SW/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_S
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_SW/root"
|
parent: "rich_text_5_SW/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -4378,6 +4381,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
@ -4656,7 +4660,7 @@ nodes {
|
|||||||
id: "rich_text_5_S/icon_prefab"
|
id: "rich_text_5_S/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_S
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_S/root"
|
parent: "rich_text_5_S/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -4672,6 +4676,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
@ -4950,7 +4955,7 @@ nodes {
|
|||||||
id: "rich_text_5_SE/icon_prefab"
|
id: "rich_text_5_SE/icon_prefab"
|
||||||
xanchor: XANCHOR_NONE
|
xanchor: XANCHOR_NONE
|
||||||
yanchor: YANCHOR_NONE
|
yanchor: YANCHOR_NONE
|
||||||
pivot: PIVOT_CENTER
|
pivot: PIVOT_S
|
||||||
adjust_mode: ADJUST_MODE_FIT
|
adjust_mode: ADJUST_MODE_FIT
|
||||||
parent: "rich_text_5_SE/root"
|
parent: "rich_text_5_SE/root"
|
||||||
layer: ""
|
layer: ""
|
||||||
@ -4966,6 +4971,7 @@ nodes {
|
|||||||
clipping_inverted: false
|
clipping_inverted: false
|
||||||
alpha: 1.0
|
alpha: 1.0
|
||||||
overridden_fields: 3
|
overridden_fields: 3
|
||||||
|
overridden_fields: 14
|
||||||
template_node_child: true
|
template_node_child: true
|
||||||
size_mode: SIZE_MODE_AUTO
|
size_mode: SIZE_MODE_AUTO
|
||||||
custom_type: 0
|
custom_type: 0
|
||||||
|
@ -48,15 +48,16 @@ function init(self)
|
|||||||
self.druid:new(RichText, "rich_text_4_2"):set_text("Text with image <img=logo,48/>scaled in GUI")
|
self.druid:new(RichText, "rich_text_4_2"):set_text("Text with image <img=logo,48/>scaled in GUI")
|
||||||
self.druid:new(RichText, "rich_text_4_3"):set_text("Text with image <img=logo,48,48/>with fixed height")
|
self.druid:new(RichText, "rich_text_4_3"):set_text("Text with image <img=logo,48,48/>with fixed height")
|
||||||
|
|
||||||
self.druid:new(RichText, "rich_text_5_NW"):set_text("Example text for pivots <img=logo,24/>")
|
-- Docs: For images vertical anchor takes from ImagePrefab
|
||||||
self.druid:new(RichText, "rich_text_5_N"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_NW"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_NE"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_N"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_W"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_NE"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_C"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_W"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_E"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_C"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_SW"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_E"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_S"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_SW"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
self.druid:new(RichText, "rich_text_5_SE"):set_text("Example text for pivots <img=logo,24/>")
|
self.druid:new(RichText, "rich_text_5_S"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
|
self.druid:new(RichText, "rich_text_5_SE"):set_text("Example text for pivots <img=logo,32/>")
|
||||||
|
|
||||||
--self.rich_text_3 = self.druid:new(RichText, "rich_text_3")
|
--self.rich_text_3 = self.druid:new(RichText, "rich_text_3")
|
||||||
--local words3 = self.rich_text_3:set_text("Energy is full. To restore")
|
--local words3 = self.rich_text_3:set_text("Energy is full. To restore")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user