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 _ = require("gettext")
local C_ = _.pgettext
local Input = Device.input
local Screen = Device.screen
local T = require("ffi/util").template
@ -70,6 +71,8 @@ function DictQuickLookup:init()
self.image_alt_face = Font:getFace("cfont", font_size_alt)
if Device:hasKeys() then
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" }
}
end
@ -948,9 +951,19 @@ function DictQuickLookup:changeToDefaultDict()
end
]]--
function DictQuickLookup:onAnyKeyPressed()
-- triggered by our defined key events
UIManager:close(self)
function DictQuickLookup:onReadNextResult()
self:changeToNextDict()
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
end
@ -971,15 +984,9 @@ function DictQuickLookup:onTap(arg, ges_ev)
-- will pop it up for us here when it can't scroll anymore).
-- This allow for continuous reading of results' definitions with tap.
if BD.flipIfMirroredUILayout(ges_ev.pos.x < Screen:getWidth()/2) then
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
self:onReadPrevResult()
else
self:changeToNextDict()
self:onReadNextResult()
end
end
return true

@ -150,28 +150,28 @@ end
function ScrollHtmlWidget:onTapScrollText(arg, ges)
if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then
if self.htmlbox_widget.page_number > 1 then
self:scrollText(-1)
return true
end
return self:onScrollUp()
else
if self.htmlbox_widget.page_number < self.htmlbox_widget.page_count then
self:scrollText(1)
return true
end
return self:onScrollDown()
end
end
function ScrollHtmlWidget:onScrollUp()
if self.htmlbox_widget.page_number > 1 then
self:scrollText(-1)
return true
end
-- 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)
end
function ScrollHtmlWidget:onScrollDown()
self:scrollText(1)
return true
end
function ScrollHtmlWidget:onScrollUp()
self:scrollText(-1)
return true
if self.htmlbox_widget.page_number < self.htmlbox_widget.page_count then
self:scrollText(1)
return true
end
-- 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)
end
return ScrollHtmlWidget

@ -252,28 +252,28 @@ function ScrollTextWidget:onTapScrollText(arg, ges)
end
-- same tests as done in TextBoxWidget:scrollUp/Down
if BD.flipIfMirroredUILayout(ges.pos.x < Screen:getWidth()/2) then
if self.text_widget.virtual_line_num > 1 then
self:scrollText(-1)
return true
end
return self:onScrollUp()
else
if self.text_widget.virtual_line_num + self.text_widget:getVisLineCount() <= #self.text_widget.vertical_string_list then
self:scrollText(1)
return true
end
return self:onScrollDown()
end
end
function ScrollTextWidget:onScrollUp()
if self.text_widget.virtual_line_num > 1 then
self:scrollText(-1)
return true
end
-- 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)
end
function ScrollTextWidget:onScrollDown()
self:scrollText(1)
return true
end
function ScrollTextWidget:onScrollUp()
self:scrollText(-1)
return true
if self.text_widget.virtual_line_num + self.text_widget:getVisLineCount() <= #self.text_widget.vertical_string_list then
self:scrollText(1)
return true
end
-- 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)
end
function ScrollTextWidget:onPanText(arg, ges)

Loading…
Cancel
Save