InfoMessage: avoid overflowing screen height with long messages

When no height= provided, and the InfoMessage would overflow
screen height when some long message is provided, decrease the
font size until the widget fit.
pull/4487/head
poire-z 5 years ago
parent c327069f43
commit f533acb7f9

@ -439,13 +439,11 @@ You can enable individual tweaks on this book with a tap, or view more details a
callback = function()
UIManager:show(InfoMessage:new{
text = item.info_text,
face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"),
})
end,
hold_callback = function()
UIManager:show(InfoMessage:new{
text = item.info_text,
face = Font:getFace(item.smaller_font and "x_smallinfofont" or "smallinfofont"),
})
end,
separator = item.separator,

@ -263,7 +263,6 @@ width: 100% !important;
title = _("Alternative TOC hints"),
{
title = _("About alternative TOC"),
smaller_font = true,
info_text = _([[
An alternative table of content can be built with a long-press on the "Table of content" menu item.

@ -117,11 +117,13 @@ function Font:getFace(font, size)
end
--- Freetype font face wrapper object
-- @table FontFaceObj
-- @field orig_font font name requested
-- @field size size of the font face (after scaled by screen size)
-- @field orig_size raw size of the font face (before scale)
-- @field ftface font face object from freetype
-- @field hash hash key for this font face
face_obj = {
orig_font = font,
size = size,
orig_size = orig_size,
ftface = face,

@ -129,21 +129,46 @@ function InfoMessage:init()
width = text_width,
}
end
self.movable = MovableContainer:new{
FrameContainer:new{
background = Blitbuffer.COLOR_WHITE,
HorizontalGroup:new{
align = "center",
image_widget,
HorizontalSpan:new{ width = (self.show_icon and Size.span.horizontal_default or 0) },
text_widget,
}
local frame = FrameContainer:new{
background = Blitbuffer.COLOR_WHITE,
HorizontalGroup:new{
align = "center",
image_widget,
HorizontalSpan:new{ width = (self.show_icon and Size.span.horizontal_default or 0) },
text_widget,
}
}
self.movable = MovableContainer:new{
frame,
}
self[1] = CenterContainer:new{
dimen = Screen:getSize(),
self.movable,
}
if not self.height then
-- Reduce font size until widget fit screen height if needed
local cur_size = frame:getSize()
if cur_size and cur_size.h > 0.95 * Screen:getHeight() then
local orig_font = text_widget.face.orig_font
local orig_size = text_widget.face.orig_size
local real_size = text_widget.face.size
if orig_size > 10 then -- don't go too small
while true do
orig_size = orig_size - 1
self.face = Font:getFace(orig_font, orig_size)
-- scaleBySize() in Font:getFace() may give the same
-- real font size even if we decreased orig_size,
-- so check we really got a smaller real font size
if self.face.size < real_size then
break
end
end
-- re-init this widget
self:free()
self:init()
end
end
end
end
function InfoMessage:onCloseWidget()

Loading…
Cancel
Save