mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[FocusManager] correct cursor keys in RTL (#13362)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
local bit = require("bit")
|
||||
local BD = require("ui/bidi")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local logger = require("logger")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local bit = require("bit")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
--[[
|
||||
Wrapper Widget that manages focus for a whole dialog
|
||||
@@ -156,6 +157,7 @@ function FocusManager:onFocusHalfMove(args)
|
||||
end
|
||||
elseif direction == "left" then
|
||||
dx = - math.floor(#row / 2)
|
||||
if BD.mirroredUILayout() then dx = -dx end
|
||||
if dx == 0 then
|
||||
dx = -1
|
||||
elseif dx + x <= 0 then
|
||||
@@ -163,12 +165,19 @@ function FocusManager:onFocusHalfMove(args)
|
||||
end
|
||||
elseif direction == "right" then
|
||||
dx = math.floor(#row / 2)
|
||||
if BD.mirroredUILayout() then dx = -dx end
|
||||
if dx == 0 then
|
||||
dx = 1
|
||||
elseif dx + x > #row then
|
||||
dx = #row - y -- last column
|
||||
dx = #row - x -- last column
|
||||
end
|
||||
end
|
||||
if dx ~= 0 and BD.mirroredUILayout() then
|
||||
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
|
||||
-- therefore we must account for this when moving the focus. Since we're already inverting dx in the FocusMove
|
||||
-- method, we need to "unfix" our value here, before calling onFocusMove, where it will be flipped again.
|
||||
dx = -dx
|
||||
end
|
||||
return self:onFocusMove({dx, dy})
|
||||
end
|
||||
|
||||
@@ -214,6 +223,13 @@ function FocusManager:onFocusMove(args)
|
||||
end
|
||||
local dx, dy = unpack(args)
|
||||
|
||||
-- Flip horizontal direction in RTL mode
|
||||
if dx ~= 0 and BD.mirroredUILayout() then
|
||||
-- When in RTL we mirror horizontally the elements/buttons on the screen, however we don't mirror self.layout
|
||||
-- therefore we must account for this when moving the focus.
|
||||
dx = -dx
|
||||
end
|
||||
|
||||
if (dx ~= 0 and not self.movement_allowed.x)
|
||||
or (dy ~= 0 and not self.movement_allowed.y) then
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user