Use unicode ellipsis to truncate tab's text

For proportional fonts is equivalent to three dots but it makes a
lot of difference for monospaced fonts.
This commit is contained in:
Francesco Abbate 2021-05-15 16:27:29 +02:00
parent f30dfc20fe
commit b223dbca6f
1 changed files with 8 additions and 3 deletions

View File

@ -398,7 +398,7 @@ end
function Node:draw_tabs() function Node:draw_tabs()
local x, y, _, h = self:get_tab_rect(1) local x, y, _, h = self:get_tab_rect(1)
local ds = style.divider_size local ds = style.divider_size
local dots_width = style.font:get_width("...") local dots_width = style.font:get_width("")
core.push_clip_rect(x, y, self.size.x, h) core.push_clip_rect(x, y, self.size.x, h)
renderer.draw_rect(x, y, self.size.x, h, style.background2) renderer.draw_rect(x, y, self.size.x, h, style.background2)
renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider) renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider)
@ -425,8 +425,13 @@ function Node:draw_tabs()
color = style.text color = style.text
end end
local padx = style.padding.x local padx = style.padding.x
core.push_clip_rect(x, y, cx - x, h) -- Normally we should substract "cspace" from text_avail_width and from the
-- clipping width. It is the padding space we give to the left and right of the
-- close button. However, since we are using dots to terminate filenames, we
-- choose to ignore "cspace" accepting that the text can possibly "touch" the
-- close button.
local text_avail_width = cx - x - padx local text_avail_width = cx - x - padx
core.push_clip_rect(x, y, cx - x, h)
x, w = x + padx, w - padx * 2 x, w = x + padx, w - padx * 2
local align = "center" local align = "center"
if style.font:get_width(text) > text_avail_width then if style.font:get_width(text) > text_avail_width then
@ -434,7 +439,7 @@ function Node:draw_tabs()
for i = 1, #text do for i = 1, #text do
local reduced_text = text:sub(1, #text - i) local reduced_text = text:sub(1, #text - i)
if style.font:get_width(reduced_text) + dots_width <= text_avail_width then if style.font:get_width(reduced_text) + dots_width <= text_avail_width then
text = reduced_text .. "..." text = reduced_text .. ""
break break
end end
end end