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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion frontend/ui/data/keyboardlayouts/std.lua
@@ -1,3 +1,28 @@
local _E_ = {
"E",
north = "Ë",
northeast = "É",
northwest = "È",
east = "Ê",
west = "Ẽ",
south = "Ę",
southeast = "€",
southwest = "Ė",
"Ē",
}
local _e_ = {
"e",
north = "ë",
northeast = "é",
northwest = "è",
east = "ê",
west = "ẽ",
south = "ę",
southeast = "€",
southwest = "ė",
"ē",
}

return {
shiftmode_keys = {["Shift"] = true},
symbolmode_keys = {["Sym"] = true, ["ABC"] = true},
Expand All @@ -8,7 +33,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", "¡", },
{ "R", "r", "#", "3", "К", "к", "~", "3", "ß", "ß", "4", "¿", },
{ "T", "t", "+", "=", "Е", "е", "Ә", "ә", "À", "à", "5", "¼", },
{ "Y", "y", "€", "(", "Н", "н", "І", "і", "Â", "â", "6", "½", },
Expand Down
47 changes: 42 additions & 5 deletions frontend/ui/widget/virtualkeyboard.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -311,21 +336,33 @@ 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
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)
if not key_chars then
virtual_key.swipe_callback = nil
end
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
Expand Down