mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[feat] VirtualKeyboard cursor navigation (#3290)
Still lacks Japanese due to insufficient knowledge of the language.
This commit is contained in:
@@ -40,8 +40,8 @@ return {
|
||||
{ "C", "c", "&", "¥", "Ψ", "ψ", "Џ", "џ", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", ":", "£", "Ω", "ω", "Ώ", "ώ", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", "π", "‚", "Β", "β", "Ћ", "ћ", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "е", "‘", "Ν", "ν", "Њ", "њ", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "~", "’", "Μ", "μ", "Ї", "ї", "Ç", "ç", "…", "¨", },
|
||||
{ "N", "n", "е", "↑", "Ν", "ν", "Њ", "њ", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "~", "↓", "Μ", "μ", "Ї", "ї", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ".", ",", ",", ".", "Є", "є", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "‘", "←", ",", ",", "є", "є", ",", ",", ",", ",", },
|
||||
{ ",", ".", "’", "→", ",", ".", "Є", "Є", ",", ".", ",", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
@@ -67,5 +68,3 @@ return {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ return {
|
||||
{ "C", "c", "£", "9", "С", "с", "'", "9", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", "<", "‚", "М", "м", "Ө", "ө", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", ">", ".", "И", "и", "Һ", "һ", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "“", "Т", "т", "Б", "б", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "”", "Ь", "ь", "Ю", "ю", "Ç", "ç", "…", "¨", },
|
||||
{ "N", "n", "‘", "↑", "Т", "т", "Б", "б", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "↓", "Ь", "ь", "Ю", "ю", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ".", ",", ",", ".", "Ё", "ё", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "“", "←", ",", ",", "Ё", "Ё", ",", ",", ",", ",", },
|
||||
{ ",", ".", "”", "→", ",", ".", "ё", "ё", ",", ".", ",", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
|
||||
@@ -40,8 +40,8 @@ return {
|
||||
{ "C", "c", "£", "9", "Ć", "ć", "£", "9", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", "<", "‚", "V", "v", "<", ",", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", ">", ".", "B", "b", ">", ".", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "“", "Ń", "ń", "‘", "“", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "”", "M", "m", "’", "”", "Ç", "ç", "…", "¨", },
|
||||
{ "N", "n", "‘", "↑", "Ń", "ń", "‘", "“", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "↓", "M", "m", "’", "”", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ".", ",", ",", ".", ".PL", ".pl", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "“", "←", ",", ",", ".pl", ".pl", ",", ",", ",", ",", },
|
||||
{ ",", ".", "”", "→", ",", ".", ".PL", ".PL", ",", ".", ",", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
|
||||
@@ -40,8 +40,8 @@ return {
|
||||
{ "C", "c", "£", "9", "Ç", "ç", "£", "9", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", "<", "‚", "V", "v", "<", ",", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", ">", ".", "B", "b", ">", ".", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "“", "N", "n", "‘", "“", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "”", "M", "m", "’", "”", "Ç", "ç", "…", "¨", },
|
||||
{ "N", "n", "‘", "↑", "N", "n", "‘", "“", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "↓", "M", "m", "’", "”", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ".", ",", ",", ".", ".PL", ".pl", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "“", "←", ",", ",", "Ё", "Ё", ",", ",", ",", ",", },
|
||||
{ ",", ".", "”", "→", ",", ".", "ё", "ё", ",", ".", ",", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
|
||||
@@ -40,8 +40,8 @@ return {
|
||||
{ "C", "c", "£", "9", "С", "с", "'", "9", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", "<", "‚", "М", "м", "Ө", "ө", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", ">", ".", "И", "и", "Һ", "һ", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "“", "Т", "т", "Б", "б", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "”", "Ь", "ь", "Ю", "ю", "Ç", "ç", "…", "¨", },
|
||||
{ "N", "n", "‘", "↑", "Т", "т", "Б", "б", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "↓", "Ь", "ь", "Ю", "ю", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ".", ",", ",", ".", "Ё", "ё", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "“", "←", ",", ",", "Ё", "Ё", ",", ",", ",", ",", },
|
||||
{ ".", ".", "”", "→", ".", ".", "ё", "ё", ".", ".", ".", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
|
||||
@@ -39,9 +39,9 @@ return {
|
||||
{ "X", "x", "€", ")", "Х", "х", "№", "@", "É", "é", "Ø", "ø", },
|
||||
{ "C", "c", "¥", "{", "Ц", "ц", "Џ", "џ", "Í", "í", "Þ", "þ", },
|
||||
{ "V", "v", "£", "}", "В", "в", "Ў", "ў", "Ñ", "ñ", "Ý", "ý", },
|
||||
{ "B", "b", "‚", "[", "Б", "б", "Ћ", "ћ", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "]", "Н", "н", "Њ", "њ", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "&", "М", "м", "Ї", "ї", "Ç", "ç", "…", "¨", },
|
||||
{ "B", "b", "‚", "&", "Б", "б", "Ћ", "ћ", "Ó", "ó", "†", "‡", },
|
||||
{ "N", "n", "‘", "↑", "Н", "н", "Њ", "њ", "Ú", "ú", "–", "—", },
|
||||
{ "M", "m", "’", "↓", "М", "м", "Ї", "ї", "Ç", "ç", "…", "¨", },
|
||||
{ label = "Backspace",
|
||||
icon = "resources/icons/appbar.clear.reflect.horizontal.png",
|
||||
width = 1.5
|
||||
@@ -57,8 +57,9 @@ return {
|
||||
{ "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", "Äéß", },
|
||||
{ label = "space",
|
||||
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
|
||||
width = 4.0},
|
||||
{ ",", ".", ",", ".", ",", ".", "Є", "є", ",", ".", ",", ".", },
|
||||
width = 3.0},
|
||||
{ ",", ",", "[", "←", ",", ",", "є", "є", ",", ",", ",", ",", },
|
||||
{ ",", ".", "]", "→", ",", ".", "Є", "Є", ",", ".", ",", ".", },
|
||||
{ label = "Enter",
|
||||
"\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n",
|
||||
icon = "resources/icons/appbar.arrow.enter.png",
|
||||
|
||||
@@ -239,6 +239,30 @@ function InputText:delChar()
|
||||
self:initTextBox(table.concat(self.charlist))
|
||||
end
|
||||
|
||||
function InputText:leftChar()
|
||||
if self.charpos == 1 then return end
|
||||
self.charpos = self.charpos -1
|
||||
self:initTextBox(table.concat(self.charlist))
|
||||
end
|
||||
|
||||
function InputText:rightChar()
|
||||
if self.charpos > #table.concat(self.charlist) then return end
|
||||
self.charpos = self.charpos +1
|
||||
self:initTextBox(table.concat(self.charlist))
|
||||
end
|
||||
|
||||
function InputText:upLine()
|
||||
if self.text_widget.moveCursorUp then
|
||||
self.text_widget:moveCursorUp()
|
||||
end
|
||||
end
|
||||
|
||||
function InputText:downLine()
|
||||
if self.text_widget.moveCursorDown then
|
||||
self.text_widget:moveCursorDown()
|
||||
end
|
||||
end
|
||||
|
||||
function InputText:clear()
|
||||
self.charpos = nil
|
||||
self:initTextBox("")
|
||||
|
||||
@@ -282,6 +282,7 @@ end
|
||||
-- Click event: Move the cursor to a new location with (x, y), in pixels.
|
||||
-- Be aware of virtual line number of the scorllTextWidget.
|
||||
function TextBoxWidget:moveCursor(x, y)
|
||||
if x < 0 or y < 0 then return end
|
||||
if #self.vertical_string_list == 0 then
|
||||
-- if there's no text at all, nothing to do
|
||||
return 1
|
||||
@@ -357,6 +358,26 @@ function TextBoxWidget:getSize()
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxWidget:moveCursorUp()
|
||||
if self.vertical_string_list and #self.vertical_string_list < 2 then return end
|
||||
local x, y
|
||||
x, y = self:_findCharPos()
|
||||
local charpos = self:moveCursor(x, y - self.line_height_px +1)
|
||||
if charpos then
|
||||
self:moveCursorToCharpos(charpos)
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxWidget:moveCursorDown()
|
||||
if self.vertical_string_list and #self.vertical_string_list < 2 then return end
|
||||
local x, y
|
||||
x, y = self:_findCharPos()
|
||||
local charpos = self:moveCursor(x, y + self.line_height_px +1)
|
||||
if charpos then
|
||||
self:moveCursorToCharpos(charpos)
|
||||
end
|
||||
end
|
||||
|
||||
function TextBoxWidget:paintTo(bb, x, y)
|
||||
self.dimen.x, self.dimen.y = x, y
|
||||
bb:blitFrom(self._bb, x, y, 0, 0, self.width, self._bb:getHeight())
|
||||
|
||||
@@ -44,6 +44,14 @@ function VirtualKey:init()
|
||||
elseif self.label == "Backspace" then
|
||||
self.callback = function () self.keyboard:delChar() end
|
||||
self.hold_callback = function () self.keyboard:clear() end
|
||||
elseif self.label =="←" then
|
||||
self.callback = function() self.keyboard:leftChar() end
|
||||
elseif self.label == "→" then
|
||||
self.callback = function() self.keyboard:rightChar() end
|
||||
elseif self.label == "↑" then
|
||||
self.callback = function() self.keyboard:upLine() end
|
||||
elseif self.label == "↓" then
|
||||
self.callback = function() self.keyboard:downLine() end
|
||||
else
|
||||
self.callback = function () self.keyboard:addChar(self.key) end
|
||||
end
|
||||
@@ -307,6 +315,22 @@ function VirtualKeyboard:delChar()
|
||||
self.inputbox:delChar()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:leftChar()
|
||||
self.inputbox:leftChar()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:rightChar()
|
||||
self.inputbox:rightChar()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:upLine()
|
||||
self.inputbox:upLine()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:downLine()
|
||||
self.inputbox:downLine()
|
||||
end
|
||||
|
||||
function VirtualKeyboard:clear()
|
||||
logger.dbg("clear input")
|
||||
self.inputbox:clear()
|
||||
|
||||
Reference in New Issue
Block a user