mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Top menu: long-press on truncated menu item to show full text
This commit is contained in:
@@ -50,6 +50,7 @@ local TextWidget = Widget:new{
|
||||
_height = 0,
|
||||
_baseline_h = 0,
|
||||
_maxlength = 1200,
|
||||
_is_truncated = nil,
|
||||
|
||||
-- Additional properties only used when using xtext
|
||||
use_xtext = G_reader_settings:nilOrTrue("use_xtext"),
|
||||
@@ -122,6 +123,7 @@ function TextWidget:updateSize()
|
||||
self._length = 0
|
||||
return
|
||||
end
|
||||
self._is_truncated = false
|
||||
|
||||
-- Compute width:
|
||||
if self.use_xtext then
|
||||
@@ -170,6 +172,7 @@ function TextWidget:updateSize()
|
||||
-- smaller than max_width when dropping the truncated glyph).
|
||||
tsize = RenderText:sizeUtf8Text(0, self.max_width, self.face, self._text_to_draw, true, self.bold)
|
||||
self._length = math.floor(tsize.x)
|
||||
self._is_truncated = true
|
||||
end
|
||||
end
|
||||
dbg:guard(TextWidget, "updateSize",
|
||||
@@ -227,6 +230,7 @@ function TextWidget:_measureWithXText()
|
||||
self._shape_idx_to_substitute_with_ellipsis = self._shape_end
|
||||
end
|
||||
end
|
||||
self._is_truncated = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -294,6 +298,11 @@ function TextWidget:getWidth()
|
||||
return self._length
|
||||
end
|
||||
|
||||
function TextWidget:isTruncated()
|
||||
self:updateSize()
|
||||
return self._is_truncated
|
||||
end
|
||||
|
||||
function TextWidget:getBaseline()
|
||||
self:updateSize()
|
||||
return self._baseline_h
|
||||
|
||||
@@ -105,6 +105,15 @@ function TouchMenuItem:init()
|
||||
face = self.face
|
||||
end
|
||||
end
|
||||
local text_widget = TextWidget:new{
|
||||
text = text,
|
||||
max_width = text_max_width,
|
||||
fgcolor = item_enabled ~= false and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
||||
face = face,
|
||||
forced_baseline = forced_baseline,
|
||||
forced_height = forced_height,
|
||||
}
|
||||
self.text_truncated = text_widget:isTruncated()
|
||||
self.item_frame = FrameContainer:new{
|
||||
width = self.dimen.w,
|
||||
bordersize = 0,
|
||||
@@ -115,14 +124,7 @@ function TouchMenuItem:init()
|
||||
dimen = Geom:new{ w = checked_widget:getSize().w },
|
||||
checkmark_widget,
|
||||
},
|
||||
TextWidget:new{
|
||||
text = text,
|
||||
max_width = text_max_width,
|
||||
fgcolor = item_enabled ~= false and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
||||
face = face,
|
||||
forced_baseline = forced_baseline,
|
||||
forced_height = forced_height,
|
||||
},
|
||||
text_widget,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -228,7 +230,7 @@ function TouchMenuItem:onHoldSelect(arg, ges)
|
||||
if enabled == false then return end
|
||||
|
||||
if G_reader_settings:isFalse("flash_ui") then
|
||||
self.menu:onMenuHold(self.item)
|
||||
self.menu:onMenuHold(self.item, self.text_truncated)
|
||||
else
|
||||
-- The item frame's width stops at the text width, but we want it to match the menu's length instead
|
||||
local highlight_dimen = self.item_frame.dimen
|
||||
@@ -242,7 +244,7 @@ function TouchMenuItem:onHoldSelect(arg, ges)
|
||||
|
||||
-- Force the repaint *now*, so we don't have to delay the callback to see the invert...
|
||||
UIManager:forceRePaint()
|
||||
self.menu:onMenuHold(self.item)
|
||||
self.menu:onMenuHold(self.item, self.text_truncated)
|
||||
UIManager:forceRePaint()
|
||||
--UIManager:waitForVSync()
|
||||
|
||||
@@ -880,7 +882,7 @@ function TouchMenu:onMenuSelect(item)
|
||||
return true
|
||||
end
|
||||
|
||||
function TouchMenu:onMenuHold(item)
|
||||
function TouchMenu:onMenuHold(item, text_truncated)
|
||||
if self.touch_menu_callback then
|
||||
self.touch_menu_callback()
|
||||
end
|
||||
@@ -917,6 +919,8 @@ function TouchMenu:onMenuHold(item)
|
||||
if help_text then
|
||||
UIManager:show(InfoMessage:new{ text = help_text, })
|
||||
end
|
||||
elseif text_truncated then
|
||||
UIManager:show(InfoMessage:new{ text = getMenuText(item), })
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user