mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Fix long filename text in history textbox (#2322)
Fix long filename text in history textbox
This commit is contained in:
@@ -4,14 +4,13 @@ local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local Screen = require("device").screen
|
||||
local util = require("ffi/util")
|
||||
local _ = require("gettext")
|
||||
local KeyValuePage = require("ui/widget/keyvaluepage")
|
||||
local DocSettings = require("docsettings")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local T = require("ffi/util").template
|
||||
|
||||
|
||||
local RenderText = require("ui/rendertext")
|
||||
local Font = require("ui/font")
|
||||
local FileManagerHistory = InputContainer:extend{
|
||||
hist_menu_title = _("History"),
|
||||
}
|
||||
@@ -82,12 +81,27 @@ function FileManagerHistory:bookInformation(file)
|
||||
end
|
||||
|
||||
function FileManagerHistory:onMenuHold(item)
|
||||
local font_size = Font:getFace("tfont")
|
||||
local text_remove_hist = _("Remove \"%1\" from history")
|
||||
local text_remove_without_item = T(text_remove_hist, "")
|
||||
local text_remove_hist_width = (RenderText:sizeUtf8Text(
|
||||
0, self.width, font_size, text_remove_without_item).x )
|
||||
local text_item_width = (RenderText:sizeUtf8Text(
|
||||
0, self.width , font_size, item.text).x )
|
||||
|
||||
local item_trun
|
||||
if self.width < text_remove_hist_width + text_item_width then
|
||||
item_trun = RenderText:truncateTextByWidth(item.text, font_size, 1.2 * self.width - text_remove_hist_width)
|
||||
else
|
||||
item_trun = item.text
|
||||
end
|
||||
local text_remove = T(text_remove_hist, item_trun)
|
||||
|
||||
self.histfile_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = util.template(_("Remove \"%1\" from history"),
|
||||
item.text),
|
||||
text = text_remove,
|
||||
callback = function()
|
||||
require("readhistory"):removeItem(item)
|
||||
self._manager:updateItemTable()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -38,26 +38,6 @@ local Font = require("ui/font")
|
||||
local Device = require("device")
|
||||
local Screen = Device.screen
|
||||
|
||||
|
||||
local ellipsis, space = "…", " "
|
||||
local ellipsis_width, space_width
|
||||
local function truncateTextByWidth(text, face, max_width, prepend_space)
|
||||
if not ellipsis_width then
|
||||
ellipsis_width = RenderText:sizeUtf8Text(0, max_width, face, ellipsis).x
|
||||
end
|
||||
if not space_width then
|
||||
space_width = RenderText:sizeUtf8Text(0, max_width, face, space).x
|
||||
end
|
||||
local new_txt_width = max_width - ellipsis_width - space_width
|
||||
local sub_txt = RenderText:getSubTextByWidth(text, face, new_txt_width)
|
||||
if prepend_space then
|
||||
return space.. sub_txt .. ellipsis
|
||||
else
|
||||
return sub_txt .. ellipsis .. space
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local KeyValueTitle = VerticalGroup:new{
|
||||
kv_page = nil,
|
||||
title = "",
|
||||
@@ -72,7 +52,7 @@ function KeyValueTitle:init()
|
||||
0, self.width, self.tface, self.title).x
|
||||
local show_title_txt
|
||||
if self.width < (title_txt_width + btn_width) then
|
||||
show_title_txt = truncateTextByWidth(
|
||||
show_title_txt = RenderText:truncateTextByWidth(
|
||||
self.title, self.tface, self.width-btn_width)
|
||||
else
|
||||
show_title_txt = self.title
|
||||
@@ -155,10 +135,10 @@ function KeyValueItem:init()
|
||||
if key_w + value_w > self.width then
|
||||
-- truncate key or value so they fits in one row
|
||||
if key_w >= value_w then
|
||||
self.show_key = truncateTextByWidth(self.key, self.cface, self.width-value_w)
|
||||
self.show_key = RenderText:truncateTextByWidth(self.key, self.cface, self.width-value_w)
|
||||
self.show_value = self.value
|
||||
else
|
||||
self.show_value = truncateTextByWidth(self.value, self.cface, self.width-key_w, true)
|
||||
self.show_value = RenderText:truncateTextByWidth(self.value, self.cface, self.width-key_w, true)
|
||||
self.show_key = self.key
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user