Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Add keyboard swipes #4884

Merged
merged 6 commits into from Apr 9, 2019
Merged
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,3 +1,12 @@
local e = {
"e",
north = "ë",
northeast = "é",
northwest = "è",
east = "ê",
west = "",
}

return {
shiftmode_keys = {["Shift"] = true},
symbolmode_keys = {["Sym"] = true, ["ABC"] = true},
@@ -8,7 +17,7 @@ return {
{ -- 1 2 3 4 5 6 7 8 9 10 11 12
{ "Q", "q", "", "0", "Й", "й", "?", "!", "Å", "å", "1", "ª", },
{ "W", "w", "!", "1", "Ц", "ц", "(", "1", "Ä", "ä", "2", "º", },
{ "E", "e", "@", "2", "У", "у", ")", "2", "Ö", "ö", "3", "¡", },
{ "E", e, "@", "2", "У", "у", ")", "2", "Ö", "ö", "3", "¡", },
This conversation was marked as resolved by poire-z

This comment has been minimized.

Copy link
@poire-z

poire-z Apr 8, 2019

Contributor

or name this local variable (and the future ones) _e_, so it's balanced in there, and no risk of confusion (and luacheck complain?) when we use for k, v in pairs() do and we implement swipes for the letters k or v ?

This comment has been minimized.

Copy link
@Frenzie

Frenzie Apr 9, 2019

Author Member

I'm not entirely sure what you mean. It's drop-in and all that's needed is keyboard updates. ;-)

(Did you say k? I think ķ is about the only one possible. But of course such keys would also be good for punctuation characters.)

This comment has been minimized.

Copy link
@poire-z

poire-z Apr 9, 2019

Contributor

I meant just what you just changed, local _e_ = on the first line, so nothing else :)
(this k thing was just an example of another common single char local variable; i in for i, v in pairs() would have been another better example, as we could have ï î :)

{ "R", "r", "#", "3", "К", "к", "~", "3", "ß", "ß", "4", "¿", },
{ "T", "t", "+", "=", "Е", "е", "Ә", "ә", "À", "à", "5", "¼", },
{ "Y", "y", "", "(", "Н", "н", "І", "і", "Â", "â", "6", "½", },
@@ -66,6 +66,9 @@ function VirtualKey:init()
self.callback = function() self.keyboard:downLine() end
else
self.callback = function () self.keyboard:addChar(self.key) end
self.swipe_callback = function(ges)
self.keyboard:addChar(self.key_chars[ges.direction])
end
end

local label_widget
@@ -118,6 +121,12 @@ function VirtualKey:init()
range = self.dimen,
},
},
SwipeKey = {
GestureRange:new{
ges = "swipe",
range = self.dimen,
},
},
}
end
self.flash_keyboard = G_reader_settings:readSetting("flash_keyboard") ~= false
@@ -184,6 +193,22 @@ function VirtualKey:onHoldSelect()
return true
end

function VirtualKey:onSwipeKey(arg, ges)
if self.flash_keyboard and not self.skipswipe then
self[1].inner_bordersize = self.focused_bordersize
self:update_keyboard(false, true)
if self.swipe_callback then
self.swipe_callback(ges)
end
UIManager:tickAfterNext(function() self:invert(false, true) end)
else
if self.swipe_callback then
self.swipe_callback(ges)
end
end
return true
end

function VirtualKey:invert(invert, hold)
if invert then
self[1].inner_bordersize = self.focused_bordersize
@@ -311,21 +336,31 @@ function VirtualKeyboard:addKeys()
local horizontal_group = HorizontalGroup:new{}
local layout_horizontal = {}
for j = 1, #self.KEYS[i] do
local key
local key_chars = self.KEYS[i][j][self.keyboard_layout]
if type(key_chars) == "table" then
key = key_chars[1]
else
key = key_chars
key_chars = nil
end
logger.dbg(key)
This conversation was marked as resolved by poire-z

This comment has been minimized.

Copy link
@poire-z

poire-z Apr 8, 2019

Contributor

Volontary addition, or forgotten logger.dbg() ?

This comment has been minimized.

Copy link
@Frenzie

Frenzie Apr 9, 2019

Author Member

Overlooked. :-)

local width_factor = self.KEYS[i][j].width or 1.0
local key_width = math.floor((base_key_width + self.key_padding) * width_factor)
- self.key_padding
local key_height = base_key_height
local label = self.KEYS[i][j].label or self.KEYS[i][j][self.keyboard_layout]
local key = VirtualKey:new{
key = self.KEYS[i][j][self.keyboard_layout],
local label = self.KEYS[i][j].label or key
local virtual_key = VirtualKey:new{
key = key,
key_chars = key_chars,
icon = self.KEYS[i][j].icon,
label = label,
keyboard = self,
width = key_width,
height = key_height,
}
table.insert(horizontal_group, key)
table.insert(layout_horizontal, key)
table.insert(horizontal_group, virtual_key)
table.insert(layout_horizontal, virtual_key)
if j ~= #self.KEYS[i] then
table.insert(horizontal_group, h_key_padding)
end
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.