mirror of https://github.com/koreader/koreader
refactor: add touch zone subsystem to inputcontainer
Touch zone decouples screen size from gesture event registration. The win here is each individual widget does not need to update gesture range on screen rotate/resize anymore. Another advantage is we now have a centralized ordered array to handle all registered touch event listeners, makes it much easier to resolve gesture range conflicts between multiple widgets. This patch also includes the following changes: * migrate readerpaging to use readerui's touch zone * migrate readerfooter to use readerui's touch zone * move inverse read direction setting to touch menu's setting tab * moved kobolight widget from readerview into readerui * various dead code cleanups and commentspull/2416/head
parent
8799b4b6b1
commit
0c49b915de
@ -0,0 +1,77 @@
|
||||
describe("InputContainer widget", function()
|
||||
local InputContainer, Screen
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
InputContainer = require("ui/widget/container/inputcontainer")
|
||||
Screen = require("device").screen
|
||||
end)
|
||||
|
||||
it("should register touch zones", function()
|
||||
local ic = InputContainer:new{}
|
||||
assert.is.same(#ic._touch_zones, 0)
|
||||
|
||||
ic:registerTouchZones({
|
||||
{
|
||||
id = "foo",
|
||||
ges = "swipe",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
||||
},
|
||||
handler = function() end,
|
||||
},
|
||||
{
|
||||
id = "bar",
|
||||
ges = "tap",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0.1, ratio_w = 0.5, ratio_h = 1,
|
||||
},
|
||||
handler = function() end,
|
||||
},
|
||||
})
|
||||
|
||||
local screen_width, screen_height = Screen:getWidth(), Screen:getHeight()
|
||||
assert.is.same(#ic._touch_zones, 2)
|
||||
assert.is.same("foo", ic._touch_zones[1].def.id)
|
||||
assert.is.same(ic._touch_zones[1].def.handler, ic._touch_zones[1].handler)
|
||||
assert.is.same("bar", ic._touch_zones[2].def.id)
|
||||
assert.is.same("tap", ic._touch_zones[2].gs_range.ges)
|
||||
assert.is.same(0, ic._touch_zones[2].gs_range.range.x)
|
||||
assert.is.same(screen_height * 0.1, ic._touch_zones[2].gs_range.range.y)
|
||||
assert.is.same(screen_width / 2, ic._touch_zones[2].gs_range.range.w)
|
||||
assert.is.same(screen_height, ic._touch_zones[2].gs_range.range.h)
|
||||
end)
|
||||
|
||||
it("should support overrides for touch zones", function()
|
||||
local ic = InputContainer:new{}
|
||||
ic:registerTouchZones({
|
||||
{
|
||||
id = "foo",
|
||||
ges = "tap",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 1, ratio_h = 1,
|
||||
},
|
||||
handler = function() end,
|
||||
},
|
||||
{
|
||||
id = "bar",
|
||||
ges = "tap",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 0.5, ratio_h = 1,
|
||||
},
|
||||
handler = function() end,
|
||||
},
|
||||
{
|
||||
id = "baz",
|
||||
ges = "tap",
|
||||
screen_zone = {
|
||||
ratio_x = 0, ratio_y = 0, ratio_w = 0.5, ratio_h = 1,
|
||||
},
|
||||
overrides = { 'foo' },
|
||||
handler = function() end,
|
||||
},
|
||||
})
|
||||
assert.is.same(ic._touch_zones[1].def.id, 'baz')
|
||||
assert.is.same(ic._touch_zones[2].def.id, 'foo')
|
||||
assert.is.same(ic._touch_zones[3].def.id, 'bar')
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue