[UX] Make the reader bottom menu compatible with key navigation (#3785)

* [toggleswitch] Add support for key navigation to this widget

Add the onFocus an onUnfocus event handler
add a new function that just circle the switch if not touch event is
detected

* Add key navigation to the readermenu

The shortcut is still Alt-gr on sdl, to be defined on Kindle

* Remove the old method of handling the Press key.

Now the event is handled by the main widget who implement focusmanager
and then dispatched to the currently focused item.
Modify the fine font tuning only for non touch-devices

See : https://github.com/koreader/koreader/pull/3785#issuecomment-375306466
This commit is contained in:
onde2rock
2018-03-22 21:01:38 +01:00
committed by Frans de Jonge
parent 7e6de30889
commit dfd87447da
9 changed files with 85 additions and 43 deletions

View File

@@ -154,6 +154,14 @@ function ToggleSwitch:togglePosition(position)
self:update()
end
function ToggleSwitch:circlePosition()
if self.position then
self.position = (self.position+1)%self.n_pos
self.position = self.position == 0 and self.n_pos or self.position
self:update()
end
end
function ToggleSwitch:calculatePosition(gev)
local x = (gev.pos.x - self.dimen.x) / self.dimen.w * self.n_pos
local y = (gev.pos.y - self.dimen.y) / self.dimen.h * self.row_count
@@ -168,8 +176,13 @@ function ToggleSwitch:onTapSelect(arg, gev)
return
end
end
local position = self:calculatePosition(gev)
self:togglePosition(position)
if gev then
local position = self:calculatePosition(gev)
self:togglePosition(position)
else
self:circlePosition()
end
--[[
if self.values then
self.values = self.values or {}
@@ -198,4 +211,14 @@ function ToggleSwitch:onHoldSelect(arg, gev)
return true
end
function ToggleSwitch:onFocus()
self.toggle_frame.background = Blitbuffer.COLOR_BLACK
return true
end
function ToggleSwitch:onUnfocus()
self.toggle_frame.background = Blitbuffer.COLOR_WHITE
return true
end
return ToggleSwitch