Fix long filename text in history textbox (#2322)

Fix long filename text in history textbox
This commit is contained in:
robert00s
2016-11-08 19:05:34 +01:00
committed by Qingping Hou
parent 75f96c5508
commit 09f2db3729
3 changed files with 40 additions and 28 deletions

View File

@@ -233,4 +233,22 @@ function RenderText:renderUtf8Text(dest_bb, x, baseline, face, text, kerning, bo
return pen_x
end
local ellipsis, space = "", " "
local ellipsis_width, space_width
function RenderText:truncateTextByWidth(text, face, max_width, prepend_space)
if not ellipsis_width then
ellipsis_width = self:sizeUtf8Text(0, max_width, face, ellipsis).x
end
if not space_width then
space_width = self:sizeUtf8Text(0, max_width, face, space).x
end
local new_txt_width = max_width - ellipsis_width - space_width
local sub_txt = self:getSubTextByWidth(text, face, new_txt_width)
if prepend_space then
return space.. sub_txt .. ellipsis
else
return sub_txt .. ellipsis .. space
end
end
return RenderText