2017-09-13 14:56:20 +00:00
|
|
|
--[[--
|
|
|
|
Displays some text in a scrollable view.
|
|
|
|
|
|
|
|
@usage
|
|
|
|
local textviewer = TextViewer:new{
|
|
|
|
title = _("I can scroll!"),
|
|
|
|
text = _("I'll need to be longer than this example to scroll."),
|
|
|
|
}
|
|
|
|
UIManager:show(textviewer)
|
2017-07-01 09:30:30 +00:00
|
|
|
]]
|
2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-07-01 09:30:30 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local Device = require("device")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Font = require("ui/font")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2018-01-29 20:27:24 +00:00
|
|
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
2017-07-01 09:30:30 +00:00
|
|
|
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2022-01-08 16:45:18 +00:00
|
|
|
local TitleBar = require("ui/widget/titlebar")
|
2017-07-01 09:30:30 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local Screen = Device.screen
|
|
|
|
|
|
|
|
local TextViewer = InputContainer:new{
|
2021-02-06 20:10:44 +00:00
|
|
|
modal = true,
|
2017-07-01 09:30:30 +00:00
|
|
|
title = nil,
|
|
|
|
text = nil,
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
2017-07-31 17:21:38 +00:00
|
|
|
buttons_table = nil,
|
2019-12-06 21:55:35 +00:00
|
|
|
-- See TextBoxWidget for details about these options
|
|
|
|
-- We default to justified and auto_para_direction to adapt
|
|
|
|
-- to any kind of text we are given (book descriptions,
|
|
|
|
-- bookmarks' text, translation results...).
|
|
|
|
-- When used to display more technical text (HTML, CSS,
|
|
|
|
-- application logs...), it's best to reset them to false.
|
|
|
|
alignment = "left",
|
2018-10-08 16:58:43 +00:00
|
|
|
justified = true,
|
2019-12-06 21:55:35 +00:00
|
|
|
lang = nil,
|
|
|
|
para_direction_rtl = nil,
|
|
|
|
auto_para_direction = true,
|
|
|
|
alignment_strict = false,
|
2017-07-01 09:30:30 +00:00
|
|
|
|
2022-01-08 16:45:18 +00:00
|
|
|
title_face = nil, -- use default from TitleBar
|
|
|
|
title_multilines = nil, -- see TitleBar for details
|
|
|
|
title_shrink_font_to_fit = nil, -- see TitleBar for details
|
2017-07-01 09:30:30 +00:00
|
|
|
text_face = Font:getFace("x_smallinfofont"),
|
2021-08-17 13:24:44 +00:00
|
|
|
fgcolor = Blitbuffer.COLOR_BLACK,
|
2017-09-13 14:56:20 +00:00
|
|
|
text_padding = Size.padding.large,
|
|
|
|
text_margin = Size.margin.small,
|
2017-10-08 15:53:25 +00:00
|
|
|
button_padding = Size.padding.default,
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TextViewer:init()
|
|
|
|
-- calculate window dimension
|
|
|
|
self.align = "center"
|
|
|
|
self.region = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
self.width = self.width or Screen:getWidth() - Screen:scaleBySize(30)
|
|
|
|
self.height = self.height or Screen:getHeight() - Screen:scaleBySize(30)
|
|
|
|
|
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events = {
|
2022-01-23 17:40:37 +00:00
|
|
|
Close = { {Device.input.group.Back}, doc = "close text viewer" }
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapClose = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-01-08 16:45:18 +00:00
|
|
|
local titlebar = TitleBar:new{
|
|
|
|
width = self.width,
|
|
|
|
align = "left",
|
|
|
|
with_bottom_line = true,
|
|
|
|
title = self.title,
|
|
|
|
title_face = self.title_face,
|
|
|
|
title_multilines = self.title_multilines,
|
|
|
|
title_shrink_font_to_fit = self.title_shrink_font_to_fit,
|
|
|
|
close_callback = function() self:onClose() end,
|
|
|
|
show_parent = self,
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 16:45:18 +00:00
|
|
|
local buttons = self.buttons_table or
|
|
|
|
{
|
2017-07-01 09:30:30 +00:00
|
|
|
{
|
2017-07-31 17:21:38 +00:00
|
|
|
{
|
|
|
|
text = _("Close"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self)
|
|
|
|
end,
|
|
|
|
},
|
2017-07-01 09:30:30 +00:00
|
|
|
},
|
2017-07-31 17:21:38 +00:00
|
|
|
}
|
2017-07-01 09:30:30 +00:00
|
|
|
local button_table = ButtonTable:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
width = self.width - 2*self.button_padding,
|
2017-07-01 09:30:30 +00:00
|
|
|
buttons = buttons,
|
|
|
|
zero_sep = true,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
|
2022-01-08 16:45:18 +00:00
|
|
|
local textw_height = self.height - titlebar:getHeight() - button_table:getSize().h
|
2017-07-01 09:30:30 +00:00
|
|
|
|
|
|
|
self.scroll_text_w = ScrollTextWidget:new{
|
2018-01-29 20:27:24 +00:00
|
|
|
text = self.text,
|
|
|
|
face = self.text_face,
|
2021-08-17 13:24:44 +00:00
|
|
|
fgcolor = self.fgcolor,
|
2018-01-29 20:27:24 +00:00
|
|
|
width = self.width - 2*self.text_padding - 2*self.text_margin,
|
|
|
|
height = textw_height - 2*self.text_padding -2*self.text_margin,
|
|
|
|
dialog = self,
|
2019-12-06 21:55:35 +00:00
|
|
|
alignment = self.alignment,
|
2018-10-08 16:58:43 +00:00
|
|
|
justified = self.justified,
|
2019-12-06 21:55:35 +00:00
|
|
|
lang = self.lang,
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
|
|
|
alignment_strict = self.alignment_strict,
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
2018-01-29 20:27:24 +00:00
|
|
|
self.textw = FrameContainer:new{
|
2017-07-01 09:30:30 +00:00
|
|
|
padding = self.text_padding,
|
|
|
|
margin = self.text_margin,
|
|
|
|
bordersize = 0,
|
|
|
|
self.scroll_text_w
|
|
|
|
}
|
|
|
|
|
|
|
|
self.frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
2017-07-01 09:30:30 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
2022-01-08 16:45:18 +00:00
|
|
|
titlebar,
|
2017-07-01 09:30:30 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
2018-01-29 20:27:24 +00:00
|
|
|
h = self.textw:getSize().h,
|
2017-07-01 09:30:30 +00:00
|
|
|
},
|
2018-01-29 20:27:24 +00:00
|
|
|
self.textw,
|
2017-07-01 09:30:30 +00:00
|
|
|
},
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = button_table:getSize().h,
|
|
|
|
},
|
|
|
|
button_table,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 20:27:24 +00:00
|
|
|
self.movable = MovableContainer:new{
|
|
|
|
ignore_events = {"swipe"},
|
|
|
|
self.frame,
|
|
|
|
}
|
2017-07-01 09:30:30 +00:00
|
|
|
self[1] = WidgetContainer:new{
|
|
|
|
align = self.align,
|
|
|
|
dimen = self.region,
|
2018-01-29 20:27:24 +00:00
|
|
|
self.movable,
|
2017-07-01 09:30:30 +00:00
|
|
|
}
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
UIManager:setDirty(self, function()
|
2021-12-25 21:56:24 +00:00
|
|
|
return "partial", self.frame.dimen
|
2017-07-01 09:30:30 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
|
|
|
return "partial", self.frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.frame.dimen
|
|
|
|
end)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onAnyKeyPressed()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onTapClose(arg, ges_ev)
|
|
|
|
if ges_ev.pos:notIntersectWith(self.frame.dimen) then
|
|
|
|
self:onClose()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TextViewer:onSwipe(arg, ges)
|
2018-01-29 20:27:24 +00:00
|
|
|
if ges.pos:intersectWith(self.textw.dimen) then
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(ges.direction)
|
|
|
|
if direction == "west" then
|
2018-01-29 20:27:24 +00:00
|
|
|
self.scroll_text_w:scrollText(1)
|
|
|
|
return true
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "east" then
|
2018-01-29 20:27:24 +00:00
|
|
|
self.scroll_text_w:scrollText(-1)
|
|
|
|
return true
|
|
|
|
else
|
2018-08-19 18:21:03 +00:00
|
|
|
-- trigger a full-screen HQ flashing refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
2018-01-29 20:27:24 +00:00
|
|
|
-- a long diagonal swipe may also be used for taking a screenshot,
|
|
|
|
-- so let it propagate
|
|
|
|
return false
|
|
|
|
end
|
2017-07-01 09:30:30 +00:00
|
|
|
end
|
2018-01-29 20:27:24 +00:00
|
|
|
-- Let our MovableContainer handle swipe outside of text
|
|
|
|
return self.movable:onMovableSwipe(arg, ges)
|
2017-07-01 09:30:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return TextViewer
|