ImageViewer: allow browsing images list with keys (#8927)

pull/9004/head
Tesseract Cat 2 years ago committed by GitHub
parent 77accf6546
commit e38a82453a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,11 +80,21 @@ local ImageViewer = InputContainer:new{
function ImageViewer:init()
if Device:hasKeys() then
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" },
}
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{
@ -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…
Cancel
Save