info: respect newlines

This commit is contained in:
Franzi 2023-12-19 11:06:02 +01:00
parent d17d8f1f23
commit 13b156b6fc

View file

@ -476,24 +476,26 @@ local function view_info(starts, ends, config, x1, y1, x2, y2)
info_text = text_b info_text = text_b
end end
local lines = wrap(
info_text,
font_text, font_size, a.width
)
local y = 0 local y = 0
for idx = 1, #lines do for line in string.gmatch(info_text.."\n", "([^\n]*)\n") do
local x = 0 local lines = wrap(
local w = font_text:width(lines[idx], font_size) line,
font_text, font_size, a.width
)
if align == "right" then for idx = 1, #lines do
x = a.width - w local x = 0
elseif align == "center" then local w = font_text:width(lines[idx], font_size)
x = (a.width - w) / 2
if align == "right" then
x = a.width - w
elseif align == "center" then
x = (a.width - w) / 2
end
text(font_text, x, y, lines[idx], font_size, rgba(default_color,.8))
y = y + font_size
end end
text(font_text, x, y, lines[idx], font_size, rgba(default_color,.8))
y = y + font_size
end end
for now in api.frame_between(starts, ends) do for now in api.frame_between(starts, ends) do
@ -501,18 +503,25 @@ local function view_info(starts, ends, config, x1, y1, x2, y2)
a.draw(now, x1, y1, x2, y2) a.draw(now, x1, y1, x2, y2)
else else
local y = 0 local y = 0
for idx = 1, #lines do for line in string.gmatch(info_text.."\n", "([^\n]*)\n") do
local x = 0 local lines = wrap(
local w = font_text:width(lines[idx], font_size) line,
font_text, font_size, a.width
)
if align == "right" then for idx = 1, #lines do
x = a.width - w local x = 0
elseif align == "center" then local w = font_text:width(lines[idx], font_size)
x = (a.width - w) / 2
if align == "right" then
x = a.width - w
elseif align == "center" then
x = (a.width - w) / 2
end
font_text:write(x, y, lines[idx], font_size, r,g,b,1)
y = y + font_size
end end
font_text:write(x, y, lines[idx], font_size, r,g,b,1)
y = y + font_size
end end
end end
end end