mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
ImageViewer: allow browsing images list with keys (#8927)
This commit is contained in:
parent
77accf6546
commit
e38a82453a
@ -80,12 +80,22 @@ local ImageViewer = InputContainer:new{
|
||||
|
||||
function ImageViewer:init()
|
||||
if Device:hasKeys() then
|
||||
if type(self.image) == "table" then
|
||||
-- if self.image is a table, then use hardware keys to change image
|
||||
self.key_events = {
|
||||
Close = { {Device.input.group.Back}, doc = "close viewer" },
|
||||
ShowPrevImage = { {Device.input.group.PgBack}, doc = "Previous image" },
|
||||
ShowNextImage = { {Device.input.group.PgFwd}, doc = "Next image" },
|
||||
}
|
||||
else
|
||||
-- otherwise, use hardware keys to zoom in/out
|
||||
self.key_events = {
|
||||
Close = { {Device.input.group.Back}, doc = "close viewer" },
|
||||
ZoomIn = { {Device.input.group.PgBack}, doc = "Zoom In" },
|
||||
ZoomOut = { {Device.input.group.PgFwd}, doc = "Zoom out" },
|
||||
}
|
||||
end
|
||||
end
|
||||
if Device:isTouchDevice() then
|
||||
local range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
@ -449,6 +459,19 @@ function ImageViewer:switchToImageNum(image_num)
|
||||
self:update()
|
||||
end
|
||||
|
||||
-- Image switching events
|
||||
function ImageViewer:onShowNextImage()
|
||||
if self._images_list_cur < self._images_list_nb then
|
||||
self:switchToImageNum(self._images_list_cur + 1)
|
||||
end
|
||||
end
|
||||
|
||||
function ImageViewer:onShowPrevImage()
|
||||
if self._images_list_cur > 1 then
|
||||
self:switchToImageNum(self._images_list_cur - 1)
|
||||
end
|
||||
end
|
||||
|
||||
function ImageViewer:onTap(_, ges)
|
||||
if ges.pos:notIntersectWith(self.main_frame.dimen) then
|
||||
self:onClose()
|
||||
@ -479,13 +502,9 @@ function ImageViewer:onTap(_, ges)
|
||||
show_next_image = not BD.mirroredUILayout()
|
||||
end
|
||||
if show_prev_image then
|
||||
if self._images_list_cur > 1 then
|
||||
self:switchToImageNum(self._images_list_cur - 1)
|
||||
end
|
||||
self:onShowPrevImage()
|
||||
elseif show_next_image then
|
||||
if self._images_list_cur < self._images_list_nb then
|
||||
self:switchToImageNum(self._images_list_cur + 1)
|
||||
end
|
||||
self:onShowNextImage()
|
||||
else -- toggle buttons when tap on middle 1/3 of screen width
|
||||
self.buttons_visible = not self.buttons_visible
|
||||
self:update()
|
||||
|
Loading…
Reference in New Issue
Block a user