DictQuickLookup: allow continuous reading with keys

We could scroll a definition with keys. Now, when
reaching top or bottom, switch to prev/next result.
reviewable/pr7134/r1
poire-z 3 years ago
parent 27b493afef
commit ebf997dd99

@ -28,6 +28,7 @@ local logger = require("logger")
local util = require("util") local util = require("util")
local _ = require("gettext") local _ = require("gettext")
local C_ = _.pgettext local C_ = _.pgettext
local Input = Device.input
local Screen = Device.screen local Screen = Device.screen
local T = require("ffi/util").template local T = require("ffi/util").template
@ -70,6 +71,8 @@ function DictQuickLookup:init()
self.image_alt_face = Font:getFace("cfont", font_size_alt) self.image_alt_face = Font:getFace("cfont", font_size_alt)
if Device:hasKeys() then if Device:hasKeys() then
self.key_events = { self.key_events = {
ReadPrevResult = {{Input.group.PgBack}, doc = "read prev result"},
ReadNextResult = {{Input.group.PgFwd}, doc = "read next result"},
Close = { {"Back"}, doc = "close quick lookup" } Close = { {"Back"}, doc = "close quick lookup" }
} }
end end
@ -948,9 +951,19 @@ function DictQuickLookup:changeToDefaultDict()
end end
]]-- ]]--
function DictQuickLookup:onAnyKeyPressed() function DictQuickLookup:onReadNextResult()
-- triggered by our defined key events self:changeToNextDict()
UIManager:close(self) return true
end
function DictQuickLookup:onReadPrevResult()
local prev_index = self.dict_index
self:changeToPrevDict()
if self.dict_index ~= prev_index then
-- Jump directly to bottom of previous dict definition
-- to keep "continuous reading with tap" consistent
self.definition_widget[1]:scrollToRatio(1) -- 1 = 100% = bottom
end
return true return true
end end
@ -971,15 +984,9 @@ function DictQuickLookup:onTap(arg, ges_ev)
-- will pop it up for us here when it can't scroll anymore). -- will pop it up for us here when it can't scroll anymore).
-- This allow for continuous reading of results' definitions with tap. -- This allow for continuous reading of results' definitions with tap.
if BD.flipIfMirroredUILayout(ges_ev.pos.x < Screen:getWidth()/2) then if BD.flipIfMirroredUILayout(ges_ev.pos.x < Screen:getWidth()/2) then
local prev_index = self.dict_index self:onReadPrevResult()
self:changeToPrevDict()
if self.dict_index ~= prev_index then
-- Jump directly to bottom of previous dict definition
-- to keep "continuous reading with tap" consistent
self.definition_widget[1]:scrollToRatio(1) -- 1 = 100% = bottom
end
else else
self:changeToNextDict() self:onReadNextResult()
end end
end end
return true return true

@ -150,28 +150,28 @@ end
function ScrollHtmlWidget:onTapScrollText(arg, ges) function ScrollHtmlWidget:onTapScrollText(arg, ges)
if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then
if self.htmlbox_widget.page_number > 1 then return self:onScrollUp()
self:scrollText(-1)
return true
end
else else
if self.htmlbox_widget.page_number < self.htmlbox_widget.page_count then return self:onScrollDown()
self:scrollText(1) end
return true end
end
function ScrollHtmlWidget:onScrollUp()
if self.htmlbox_widget.page_number > 1 then
self:scrollText(-1)
return true
end end
-- if we couldn't scroll (because we're already at top or bottom), -- if we couldn't scroll (because we're already at top or bottom),
-- let it propagate up (e.g. for quickdictlookup to go to next/prev result) -- let it propagate up (e.g. for quickdictlookup to go to next/prev result)
end end
function ScrollHtmlWidget:onScrollDown() function ScrollHtmlWidget:onScrollDown()
self:scrollText(1) if self.htmlbox_widget.page_number < self.htmlbox_widget.page_count then
return true self:scrollText(1)
end return true
end
function ScrollHtmlWidget:onScrollUp() -- if we couldn't scroll (because we're already at top or bottom),
self:scrollText(-1) -- let it propagate up (e.g. for quickdictlookup to go to next/prev result)
return true
end end
return ScrollHtmlWidget return ScrollHtmlWidget

@ -252,28 +252,28 @@ function ScrollTextWidget:onTapScrollText(arg, ges)
end end
-- same tests as done in TextBoxWidget:scrollUp/Down -- same tests as done in TextBoxWidget:scrollUp/Down
if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then
if self.text_widget.virtual_line_num > 1 then return self:onScrollUp()
self:scrollText(-1)
return true
end
else else
if self.text_widget.virtual_line_num + self.text_widget:getVisLineCount() <= #self.text_widget.vertical_string_list then return self:onScrollDown()
self:scrollText(1) end
return true end
end
function ScrollTextWidget:onScrollUp()
if self.text_widget.virtual_line_num > 1 then
self:scrollText(-1)
return true
end end
-- if we couldn't scroll (because we're already at top or bottom), -- if we couldn't scroll (because we're already at top or bottom),
-- let it propagate up (e.g. for quickdictlookup to go to next/prev result) -- let it propagate up (e.g. for quickdictlookup to go to next/prev result)
end end
function ScrollTextWidget:onScrollDown() function ScrollTextWidget:onScrollDown()
self:scrollText(1) if self.text_widget.virtual_line_num + self.text_widget:getVisLineCount() <= #self.text_widget.vertical_string_list then
return true self:scrollText(1)
end return true
end
function ScrollTextWidget:onScrollUp() -- if we couldn't scroll (because we're already at top or bottom),
self:scrollText(-1) -- let it propagate up (e.g. for quickdictlookup to go to next/prev result)
return true
end end
function ScrollTextWidget:onPanText(arg, ges) function ScrollTextWidget:onPanText(arg, ges)

Loading…
Cancel
Save