mirror of https://github.com/koreader/koreader
add on-screen keyboard widget
parent
63ee951a19
commit
fb4b6979f5
@ -0,0 +1,109 @@
|
||||
require "ui/widget/container"
|
||||
require "ui/widget/inputtext"
|
||||
|
||||
InputDialog = InputContainer:new{
|
||||
title = "",
|
||||
input = "",
|
||||
input_hint = "",
|
||||
buttons = nil,
|
||||
input_type = nil,
|
||||
|
||||
width = nil,
|
||||
height = nil,
|
||||
|
||||
title_face = Font:getFace("tfont", 22),
|
||||
input_face = Font:getFace("cfont", 20),
|
||||
|
||||
title_padding = scaleByDPI(5),
|
||||
title_margin = scaleByDPI(2),
|
||||
input_padding = scaleByDPI(10),
|
||||
input_margin = scaleByDPI(10),
|
||||
button_padding = scaleByDPI(14),
|
||||
}
|
||||
|
||||
function InputDialog:init()
|
||||
self.title = FrameContainer:new{
|
||||
padding = self.title_padding,
|
||||
margin = self.title_margin,
|
||||
bordersize = 0,
|
||||
TextWidget:new{
|
||||
text = self.title,
|
||||
face = self.title_face,
|
||||
width = self.width,
|
||||
}
|
||||
}
|
||||
self.input = InputText:new{
|
||||
text = self.input,
|
||||
hint = self.input_hint,
|
||||
face = self.input_face,
|
||||
width = self.width * 0.9,
|
||||
input_type = self.input_type,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
}
|
||||
local button_table = ButtonTable:new{
|
||||
width = self.width,
|
||||
button_font_face = "cfont",
|
||||
button_font_size = 20,
|
||||
buttons = self.buttons,
|
||||
zero_sep = true,
|
||||
}
|
||||
local title_bar = LineWidget:new{
|
||||
--background = 8,
|
||||
dimen = Geom:new{
|
||||
w = button_table:getSize().w + self.button_padding,
|
||||
h = scaleByDPI(2),
|
||||
}
|
||||
}
|
||||
|
||||
self.dialog_frame = FrameContainer:new{
|
||||
radius = 8,
|
||||
bordersize = 3,
|
||||
padding = 0,
|
||||
margin = 0,
|
||||
background = 0,
|
||||
VerticalGroup:new{
|
||||
align = "left",
|
||||
self.title,
|
||||
title_bar,
|
||||
-- input
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = title_bar:getSize().w,
|
||||
h = self.input:getSize().h,
|
||||
},
|
||||
self.input,
|
||||
},
|
||||
-- buttons
|
||||
CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = title_bar:getSize().w,
|
||||
h = button_table:getSize().h,
|
||||
},
|
||||
button_table,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight() - self.input:getKeyboardDimen().h,
|
||||
},
|
||||
self.dialog_frame,
|
||||
}
|
||||
UIManager.repaint_all = true
|
||||
UIManager.full_refresh = true
|
||||
end
|
||||
|
||||
function InputDialog:onShowKeyboard()
|
||||
self.input:onShowKeyboard()
|
||||
end
|
||||
|
||||
function InputDialog:getInputText()
|
||||
return self.input:getText()
|
||||
end
|
||||
|
||||
function InputDialog:onClose()
|
||||
self.input:onCloseKeyboard()
|
||||
end
|
@ -0,0 +1,137 @@
|
||||
require "ui/graphics"
|
||||
require "ui/widget/text"
|
||||
require "ui/widget/keyboard"
|
||||
require "ui/widget/container"
|
||||
|
||||
InputText = InputContainer:new{
|
||||
text = "",
|
||||
hint = "demo hint",
|
||||
charlist = {}, -- table to store input string
|
||||
charpos = 1,
|
||||
input_type = nil,
|
||||
|
||||
width = nil,
|
||||
height = nil,
|
||||
face = Font:getFace("cfont", 22),
|
||||
|
||||
padding = 5,
|
||||
margin = 5,
|
||||
bordersize = 2,
|
||||
|
||||
parent = nil, -- parent dialog that will be set dirty
|
||||
scroll = false,
|
||||
}
|
||||
|
||||
function InputText:init()
|
||||
self:StringToCharlist(self.text)
|
||||
self:initTextBox()
|
||||
self:initKeyboard()
|
||||
end
|
||||
|
||||
function InputText:initTextBox()
|
||||
local bgcolor = nil
|
||||
local fgcolor = nil
|
||||
if self.text == "" then
|
||||
self.text = self.hint
|
||||
bgcolor = 0.0
|
||||
fgcolor = 0.5
|
||||
else
|
||||
bgcolor = 0.0
|
||||
fgcolor = 1.0
|
||||
end
|
||||
local text_widget = nil
|
||||
if self.scroll then
|
||||
text_widget = ScrollTextWidget:new{
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
bgcolor = bgcolor,
|
||||
fgcolor = fgcolor,
|
||||
width = self.width,
|
||||
height = self.height,
|
||||
}
|
||||
else
|
||||
text_widget = TextBoxWidget:new{
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
bgcolor = bgcolor,
|
||||
fgcolor = fgcolor,
|
||||
width = self.width,
|
||||
height = self.height,
|
||||
}
|
||||
end
|
||||
self[1] = FrameContainer:new{
|
||||
bordersize = self.bordersize,
|
||||
padding = self.padding,
|
||||
margin = self.margin,
|
||||
text_widget,
|
||||
}
|
||||
self.dimen = self[1]:getSize()
|
||||
end
|
||||
|
||||
function InputText:initKeyboard()
|
||||
local keyboard_layout = 2
|
||||
if self.input_type == "number" then
|
||||
keyboard_layout = 3
|
||||
end
|
||||
self.keyboard = VirtualKeyboard:new{
|
||||
layout = keyboard_layout,
|
||||
inputbox = self,
|
||||
}
|
||||
end
|
||||
|
||||
function InputText:onShowKeyboard()
|
||||
UIManager:show(self.keyboard)
|
||||
end
|
||||
|
||||
function InputText:onCloseKeyboard()
|
||||
UIManager:close(self.keyboard)
|
||||
end
|
||||
|
||||
function InputText:getKeyboardDimen()
|
||||
return self.keyboard.dimen
|
||||
end
|
||||
|
||||
function InputText:addChar(char)
|
||||
table.insert(self.charlist, self.charpos, char)
|
||||
self.charpos = self.charpos + 1
|
||||
self.text = self:CharlistToString()
|
||||
self:initTextBox()
|
||||
UIManager:setDirty(self.parent, "partial")
|
||||
end
|
||||
|
||||
function InputText:delChar()
|
||||
self.charpos = self.charpos - 1
|
||||
table.remove(self.charlist, self.charpos)
|
||||
self.text = self:CharlistToString()
|
||||
self:initTextBox()
|
||||
UIManager:setDirty(self.parent, "partial")
|
||||
end
|
||||
|
||||
function InputText:getText()
|
||||
return self.text
|
||||
end
|
||||
|
||||
function InputText:StringToCharlist(text)
|
||||
if text == nil then return end
|
||||
-- clear
|
||||
self.charlist = {}
|
||||
self.charpos = 1
|
||||
local prevcharcode, charcode = 0
|
||||
for uchar in string.gfind(text, "([%z\1-\127\194-\244][\128-\191]*)") do
|
||||
charcode = util.utf8charcode(uchar)
|
||||
if prevcharcode then -- utf8
|
||||
self.charlist[#self.charlist+1] = uchar
|
||||
end
|
||||
prevcharcode = charcode
|
||||
end
|
||||
self.text = self:CharlistToString()
|
||||
self.charpos = #self.charlist+1
|
||||
end
|
||||
|
||||
function InputText:CharlistToString()
|
||||
local s, i = ""
|
||||
for i=1, #self.charlist do
|
||||
s = s .. self.charlist[i]
|
||||
end
|
||||
return s
|
||||
end
|
Binary file not shown.
After Width: | Height: | Size: 347 B |
Binary file not shown.
After Width: | Height: | Size: 283 B |
Binary file not shown.
After Width: | Height: | Size: 433 B |
Binary file not shown.
After Width: | Height: | Size: 510 B |
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 48 48"
|
||||
enable-background="new 0 0 76.00 76.00"
|
||||
xml:space="preserve"
|
||||
id="svg2"
|
||||
inkscape:version="0.48.3.1 r9886"
|
||||
sodipodi:docname="appbar.arrow.left.svg"><metadata
|
||||
id="metadata10"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1680"
|
||||
inkscape:window-height="1022"
|
||||
id="namedview6"
|
||||
showgrid="true"
|
||||
inkscape:zoom="6.2105263"
|
||||
inkscape:cx="84.532094"
|
||||
inkscape:cy="4.7422124"
|
||||
inkscape:window-x="1280"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg2"><inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid2989"
|
||||
empspacing="5"
|
||||
visible="true"
|
||||
enabled="true"
|
||||
snapvisiblegridlinesonly="true" /></sodipodi:namedview>
|
||||
<path
|
||||
d="M 43,30.428571 43,23.571429 43,9 l -6.918919,0 0,14.571429 -20.756756,0 0,-8.571429 L 3,27 l 12.324325,12 0,-8.571429 24.216216,0"
|
||||
id="path4"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#000000;fill-opacity:1;stroke-width:0.2;stroke-linejoin:round"
|
||||
sodipodi:nodetypes="ccccccccccc" />
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.1"
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 48 48"
|
||||
enable-background="new 0 0 76.00 76.00"
|
||||
xml:space="preserve"
|
||||
id="svg2"
|
||||
inkscape:version="0.48.3.1 r9886"
|
||||
sodipodi:docname="appbar.arrow.shift.svg"
|
||||
inkscape:export-filename="/home/chrox/dev/koreader/resources/icons/appbar.arrow.shift.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90"><metadata
|
||||
id="metadata10"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1680"
|
||||
inkscape:window-height="1022"
|
||||
id="namedview6"
|
||||
showgrid="true"
|
||||
inkscape:zoom="12.421053"
|
||||
inkscape:cx="17.939741"
|
||||
inkscape:cy="18.973393"
|
||||
inkscape:window-x="1280"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg2"><inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid2987"
|
||||
empspacing="5"
|
||||
visible="true"
|
||||
enabled="true"
|
||||
snapvisiblegridlinesonly="true" /></sodipodi:namedview>
|
||||
<path
|
||||
d="m 17,35 14,0 -0.003,-11.537082 8.076834,0 L 24.074,10 9.0741666,23.462918 l 8.0768334,0 z"
|
||||
id="path4"
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:none;stroke:#000000;stroke-width:3;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
|
||||
sodipodi:nodetypes="cccccccc" />
|
||||
</svg>
|
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="appbar_globe" Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" UseLayoutRounding="False">
|
||||
<Path Width="28" Height="28" Canvas.Left="10" Canvas.Top="10" Stretch="Fill" Fill="#FF000000" Data="F1 M 24,10C 31.732,10 38,16.268 38,24C 38,31.732 31.732,38 24,38C 16.268,38 10,31.732 10,24C 10,16.268 16.268,10 24,10 Z M 12.0411,23L 16.0201,23C 16.0868,21.3448 16.318,19.7691 16.6852,18.3225C 15.7561,17.9966 14.8987,17.6104 14.1296,17.1735C 12.9651,18.854 12.2187,20.8464 12.0411,23 Z M 18.9815,13.0966C 17.6191,13.7247 16.3945,14.6007 15.3654,15.6667C 15.9385,15.9635 16.5723,16.2309 17.2568,16.4638C 17.7247,15.1844 18.3082,14.0469 18.9815,13.0966 Z M 23,23L 23,19.4799C 21.4398,19.417 19.9502,19.208 18.5728,18.8767C 18.2729,20.1449 18.0809,21.5352 18.0205,23L 23,23 Z M 23,12.1659C 21.4121,12.6987 20.0356,14.479 19.1312,16.9856C 20.3301,17.252 21.6325,17.4231 23,17.4795L 23,12.1659 Z M 35.9589,23C 35.7812,20.8464 35.0349,18.8541 33.8703,17.1735C 33.1013,17.6104 32.2439,17.9966 31.3148,18.3225C 31.682,19.7691 31.9131,21.3448 31.9799,23L 35.9589,23 Z M 29.0185,13.0966C 29.6918,14.0469 30.2753,15.1844 30.7432,16.4638C 31.4277,16.2309 32.0614,15.9635 32.6346,15.6667C 31.6055,14.6007 30.3809,13.7247 29.0185,13.0966 Z M 25,23L 29.9794,23C 29.919,21.5352 29.727,20.145 29.4272,18.8767C 28.0498,19.208 26.5602,19.417 25,19.4799L 25,23 Z M 25,12.1659L 25,17.4795C 26.3674,17.4231 27.6699,17.252 28.8687,16.9856C 27.9643,14.479 26.5879,12.6987 25,12.1659 Z M 35.9589,25L 31.9799,25C 31.9131,26.6552 31.682,28.2309 31.3148,29.6775C 32.2439,30.0035 33.1013,30.3896 33.8704,30.8266C 35.0349,29.146 35.7812,27.1536 35.9589,25 Z M 29.0184,34.9034C 30.3809,34.2753 31.6055,33.3993 32.6346,32.3333C 32.0614,32.0365 31.4277,31.7691 30.7432,31.5362C 30.2753,32.8156 29.6918,33.9531 29.0184,34.9034 Z M 25,25L 25,28.5201C 26.5602,28.583 28.0498,28.792 29.4272,29.1233C 29.7271,27.8551 29.919,26.4648 29.9794,25L 25,25 Z M 25,35.8341C 26.5879,35.3013 27.9643,33.521 28.8687,31.0144C 27.6699,30.748 26.3674,30.5769 25,30.5205L 25,35.8341 Z M 12.0411,25C 12.2187,27.1536 12.9651,29.146 14.1296,30.8266C 14.8987,30.3897 15.7561,30.0035 16.6852,29.6775C 16.318,28.2309 16.0868,26.6552 16.0201,25L 12.0411,25 Z M 18.9815,34.9034C 18.3082,33.9531 17.7247,32.8156 17.2568,31.5362C 16.5723,31.7691 15.9385,32.0365 15.3654,32.3333C 16.3945,33.3994 17.6191,34.2753 18.9815,34.9034 Z M 23,25L 18.0205,25C 18.0809,26.4648 18.2729,27.8551 18.5728,29.1233C 19.9502,28.792 21.4398,28.583 23,28.5201L 23,25 Z M 23,35.8341L 23,30.5205C 21.6325,30.5769 20.3301,30.748 19.1312,31.0144C 20.0356,33.521 21.4121,35.3013 23,35.8341 Z "/>
|
||||
</Canvas>
|
Loading…
Reference in New Issue