From 63ee951a19405e0e40474903f0a167cbf9b6749a Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 16:21:19 +0800 Subject: [PATCH 1/9] add keyboard widget test in wtest --- wtest.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) mode change 100644 => 100755 wtest.lua diff --git a/wtest.lua b/wtest.lua old mode 100644 new mode 100755 index cc42500ae..a22bb9a48 --- a/wtest.lua +++ b/wtest.lua @@ -1,3 +1,6 @@ +#!./koreader-base + +require "defaults" print(package.path) package.path = "./frontend/?.lua" require "ui/uimanager" @@ -5,6 +8,7 @@ require "ui/widget/menu" require "ui/widget/infomessage" require "ui/widget/confirmbox" require "ui/widget/touchmenu" +require "ui/widget/keyboard" require "document/document" require "ui/readerui" require "dbg" @@ -250,7 +254,9 @@ touch_menu = TouchMenu:new{ }, } - +keyboard = VirtualKeyboard:new{ + layout = 2 +} ----------------------------------------------------------------------- -- you may want to uncomment following show calls to see the changes @@ -261,7 +267,8 @@ UIManager:show(TestGrid) --UIManager:show(M) --UIManager:show(Quiz) --UIManager:show(readerwindow) -UIManager:show(touch_menu) +--UIManager:show(touch_menu) +UIManager:show(keyboard) UIManager:run() From fb4b6979f5db171a1cf14ec0c000bf014c6b3242 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:07:33 +0800 Subject: [PATCH 2/9] add on-screen keyboard widget --- frontend/ui/widget/inputdialog.lua | 109 +++++++ frontend/ui/widget/inputtext.lua | 137 ++++++++ frontend/ui/widget/keyboard.lua | 298 ++++++++++++++++++ resources/icons/appbar.arrow.enter.png | Bin 0 -> 347 bytes resources/icons/appbar.arrow.shift.png | Bin 0 -> 283 bytes .../icons/appbar.clear.reflect.horizontal.png | Bin 0 -> 433 bytes resources/icons/appbar.globe.wire.png | Bin 0 -> 510 bytes resources/icons/src/appbar.arrow.enter.svg | 54 ++++ resources/icons/src/appbar.arrow.left.svg | 5 + resources/icons/src/appbar.arrow.shift.svg | 57 ++++ resources/icons/src/appbar.globe.wire.xaml | 4 + 11 files changed, 664 insertions(+) create mode 100644 frontend/ui/widget/inputdialog.lua create mode 100644 frontend/ui/widget/inputtext.lua create mode 100644 frontend/ui/widget/keyboard.lua create mode 100644 resources/icons/appbar.arrow.enter.png create mode 100644 resources/icons/appbar.arrow.shift.png create mode 100644 resources/icons/appbar.clear.reflect.horizontal.png create mode 100644 resources/icons/appbar.globe.wire.png create mode 100644 resources/icons/src/appbar.arrow.enter.svg create mode 100644 resources/icons/src/appbar.arrow.left.svg create mode 100644 resources/icons/src/appbar.arrow.shift.svg create mode 100644 resources/icons/src/appbar.globe.wire.xaml diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua new file mode 100644 index 000000000..90859e0a2 --- /dev/null +++ b/frontend/ui/widget/inputdialog.lua @@ -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 diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua new file mode 100644 index 000000000..17893e521 --- /dev/null +++ b/frontend/ui/widget/inputtext.lua @@ -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 diff --git a/frontend/ui/widget/keyboard.lua b/frontend/ui/widget/keyboard.lua new file mode 100644 index 000000000..9e90da9fb --- /dev/null +++ b/frontend/ui/widget/keyboard.lua @@ -0,0 +1,298 @@ +require "ui/font" +require "ui/widget/text" +require "ui/widget/image" +require "ui/widget/group" +require "ui/widget/container" + +VirtualKey = InputContainer:new{ + key = nil, + icon = nil, + label = nil, + + keyboard = nil, + callback = nil, + + width = nil, + height = nil, + bordersize = 2, + face = Font:getFace("infont", 22), +} + +function VirtualKey:init() + if self.label == "Sym" or self.label == "ABC" then + self.callback = function () self.keyboard:setLayout(self.key or self.label) end + elseif self.label == "Shift" then + self.callback = function () self.keyboard:setLayout(self.key or self.label) end + elseif self.label == "IM" then + self.callback = function () self.keyboard:setLayout(self.key or self.label) end + elseif self.label == "Backspace" then + self.callback = function () self.keyboard:delChar() end + else + self.callback = function () self.keyboard:addChar(self.key) end + end + + local label_widget = nil + if self.icon then + label_widget = ImageWidget:new{ + file = self.icon, + } + else + label_widget = TextWidget:new{ + text = self.label, + face = self.face, + } + end + self[1] = FrameContainer:new{ + margin = 0, + bordersize = self.bordersize, + background = 0, + radius = 5, + padding = 0, + CenterContainer:new{ + dimen = Geom:new{ + w = self.width - 2*self.bordersize, + h = self.height - 2*self.bordersize, + }, + label_widget, + }, + } + self.dimen = Geom:new{ + w = self.width, + h = self.height, + } + --self.dimen = self[1]:getSize() + if Device:isTouchDevice() then + self.ges_events = { + TapSelect = { + GestureRange:new{ + ges = "tap", + range = self.dimen, + }, + }, + DoubleTapSelect = { + GestureRange:new{ + ges = "double_tap", + range = self.dimen, + }, + }, + } + end +end + +function VirtualKey:onTapSelect() + self[1].invert = true + if self.callback then + self.callback() + end + UIManager:scheduleIn(0.08, function() self:invert(false) end) + return true +end + +function VirtualKey:onDoubleTapSelect() + self[1].invert = true + if self.callback then + self.callback() -- once + self.callback() -- twice + end + UIManager:scheduleIn(0.08, function() self:invert(false) end) + return true +end + +function VirtualKey:invert(invert) + self[1].invert = invert + UIManager.update_region_func = function() + DEBUG("update key region", self[1].dimen) + return self[1].dimen + end + UIManager:setDirty(self.keyboard, "partial") +end + +VirtualKeyboard = InputContainer:new{ + is_always_active = true, + inputbox = nil, + KEYS = {}, -- table to store layouts + min_layout = 2, + max_layout = 9, + layout = 2, + shiftmode = false, + symbolmode = false, + utf8mode = false, + + width = 600, + height = 256, + bordersize = 2, + padding = 2, + key_padding = scaleByDPI(6), +} + +function VirtualKeyboard:init() + self.KEYS = { + -- first row + { + { "Q", "q", "1", "!", "Я", "я", "1", "!", }, + { "W", "w", "2", "?", "Ж", "ж", "2", "?", }, + { "E", "e", "3", "|", "Е", "е", "3", "«", }, + { "R", "r", "4", "#", "Р", "р", "4", "»", }, + { "T", "t", "5", "@", "Т", "т", "5", ":", }, + { "Y", "y", "6", "‰", "Ы", "ы", "6", ";", }, + { "U", "u", "7", "'", "У", "у", "7", "~", }, + { "I", "i", "8", "`", "И", "и", "8", "(", }, + { "O", "o", "9", ":", "О", "о", "9", ")", }, + { "P", "p", "0", ";", "П", "п", "0", "=", }, + }, + -- second raw + { + { "A", "a", "+", "…", "А", "а", "Ш", "ш", }, + { "S", "s", "-", "_", "С", "с", "Ѕ", "ѕ", }, + { "D", "d", "*", "=", "Д", "д", "Э", "э", }, + { "F", "f", "/", "\\", "Ф", "ф", "Ю", "ю", }, + { "G", "g", "%", "„", "Г", "г", "Ґ", "ґ", }, + { "H", "h", "^", "“", "Ч", "ч", "Ј", "ј", }, + { "J", "j", "<", "”", "Й", "й", "І", "і", }, + { "K", "k", "=", "\"", "К", "к", "Ќ", "ќ", }, + { "L", "l", ">", "~", "Л", "л", "Љ", "љ", }, + }, + -- third raw + { + { label = "Shift", + icon = "resources/icons/appbar.arrow.shift.png", + width = 1.5 + }, + { "Z", "z", "(", "$", "З", "з", "Щ", "щ", }, + { "X", "x", ")", "€", "Х", "х", "№", "@", }, + { "C", "c", "&", "¥", "Ц", "ц", "Џ", "џ", }, + { "V", "v", ":", "£", "В", "в", "Ў", "ў", }, + { "B", "b", "π", "‚", "Б", "б", "Ћ", "ћ", }, + { "N", "n", "е", "‘", "Н", "н", "Њ", "њ", }, + { "M", "m", "~", "’", "М", "м", "Ї", "ї", }, + { label = "Backspace", + icon = "resources/icons/appbar.clear.reflect.horizontal.png", + width = 1.5 + }, + }, + -- fourth raw + { + { "Sym", "Sym", "ABC", "ABC", "Sym", "Sym", "ABC", "ABC", + width = 1.5}, + { label = "IM", + icon = "resources/icons/appbar.globe.wire.png", + }, + { label = "space", + " ", " ", " ", " ", " ", " ", " ", " ", + width = 5.0}, + { ",", ".", ".", ",", ",", ".", "Є", "є", }, + { label = "Enter", + "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", + icon = "resources/icons/appbar.arrow.enter.png", + width = 1.5, + }, + + } + } + self:initLayout(self.layout) +end + +function VirtualKeyboard:initLayout(layout) + local function VKLayout(b1, b2, b3) + local function boolnum(bool) + return bool and 1 or 0 + end + return 2 - boolnum(b1) + 2 * boolnum(b2) + 4 * boolnum(b3) + end + + if layout then + -- to be sure layout is selected properly + layout = math.max(layout, self.min_layout) + layout = math.min(layout, self.max_layout) + self.layout = layout + -- fill the layout modes + layout = layout % 4 + self.shiftmode = (layout == 1 or layout == 3) + self.symbolmode = (layout == 3 or layout == 4) + self.utf8mode = (self.layout > 5) + else -- or, without input parameter, restore layout from current layout modes + self.layout = VKLayout(self.shiftmode, self.symbolmode, self.utf8mode) + end + self:addKeys() +end + +function VirtualKeyboard:addKeys() + local base_key_width = math.floor((self.width - 11*self.key_padding - 2*self.padding)/10) + local base_key_height = math.floor((self.height - 5*self.key_padding - 2*self.padding)/4) + local h_key_padding = HorizontalSpan:new{width = self.key_padding} + local v_key_padding = VerticalSpan:new{width = self.key_padding} + local vertical_group = VerticalGroup:new{} + for i = 1, #self.KEYS do + local horizontal_group = HorizontalGroup:new{} + for j = 1, #self.KEYS[i] do + 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.layout] + local key = VirtualKey:new{ + key = self.KEYS[i][j][self.layout], + icon = self.KEYS[i][j].icon, + label = label, + keyboard = self, + width = key_width, + height = key_height, + } + table.insert(horizontal_group, key) + if j ~= #self.KEYS[i] then + table.insert(horizontal_group, h_key_padding) + end + end + table.insert(vertical_group, horizontal_group) + if i ~= #self.KEYS then + table.insert(vertical_group, v_key_padding) + end + end + + local size = vertical_group:getSize() + local keyboard_frame = FrameContainer:new{ + margin = 0, + bordersize = self.bordersize, + background = 0, + radius = 0, + padding = self.padding, + CenterContainer:new{ + dimen = Geom:new{ + w = self.width - 2*self.bordersize -2*self.padding, + h = self.height - 2*self.bordersize -2*self.padding, + }, + vertical_group, + } + } + self[1] = BottomContainer:new{ + dimen = Screen:getSize(), + keyboard_frame, + } + self.dimen = keyboard_frame:getSize() +end + +function VirtualKeyboard:setLayout(key) + if key == "Shift" then + self.shiftmode = not self.shiftmode + elseif key == "Sym" or key == "ABC" then + self.symbolmode = not self.symbolmode + elseif key == "IM" then + self.utf8mode = not self.utf8mode + end + self:initLayout() + UIManager:setDirty(self, "partial") +end + +function VirtualKeyboard:addChar(key) + DEBUG("add char", key) + self.inputbox:addChar(key) + UIManager:setDirty(self, "partial") + UIManager:setDirty(self.inputbox, "partial") +end + +function VirtualKeyboard:delChar() + DEBUG("delete char") + self.inputbox:delChar() + UIManager:setDirty(self, "partial") + UIManager:setDirty(self.inputbox, "partial") +end diff --git a/resources/icons/appbar.arrow.enter.png b/resources/icons/appbar.arrow.enter.png new file mode 100644 index 0000000000000000000000000000000000000000..ce3fd48d9a235015b22fa2e1dc05b7eb839c62fe GIT binary patch literal 347 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}trX+877l!}s{b%+Ad7K3vk;M!Q z+`=Ht$S`Y;1W=H@#M9T6{Vuy4o4UZ_-1a!2kYtH#M2T~LZf(Q!`~$B>A_$$$ROZ(P>U*_e2xDUh3OH>=JS!!|*$|MI=ff!u8i zS>+|RWMm#>XVY$by=C(Qn`W`2#~y2HoimOw{Ieid=FQ?sA1!odoPOY=`dCsz;$L!u z<$uWl1w)4IQ9K)SOdhYyaTIC$xWti3EFjCqj5{MPcqW>^+Ap-^o~OC-=s44$rjF6*2UngAs^d<_5q literal 0 HcmV?d00001 diff --git a/resources/icons/appbar.arrow.shift.png b/resources/icons/appbar.arrow.shift.png new file mode 100644 index 0000000000000000000000000000000000000000..840f4f7db204c1790125b3f6c870f2429403fb48 GIT binary patch literal 283 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}trX+877l!}s{b%+Ad7K3vk;M!Q z+`=Ht$S`Y;1W=H@#M9T6{Vuy4o2Fr5`>sBqkYtH#M2T~LZfQM;#$V@Sl|x7Qr`8Web3E|wkoyFNx-PxS4SD>Dq%ecYea^GNVo z)j^*I2F5!@?^*XaG|azO-C!(j!f1A0C}DXz=Z4B@4D+9JgnZ&@jI#4zFzdX~is!{F zVV@+KvVWEzT7O(@zT1ybbL$88C(eKGyR~LoUB@qVZh;Ss2D|)9>Tfx|&=pchsD8k( Y)>1BG>a9-)fKFoYboFyt=akR{06%bKDgXcg literal 0 HcmV?d00001 diff --git a/resources/icons/appbar.clear.reflect.horizontal.png b/resources/icons/appbar.clear.reflect.horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..b800bf14cfedddfdbab3557505f756165c58163b GIT binary patch literal 433 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1SD@H?L1u^Ln02pyypoYw#_teT0G^@ zO6f4e9F)#mi+2c(| zzg(Y^&c0W(XOj-|0gJxa>vuy|ZQolOtKGF}@0I-8)G3!X>6rVJ`@h=0j9=$>?&Wl@ z$1;`k>@!|l?3wF(S;X~X=z{+>buV_+ab}otHf``;yedoPxXww-KZ&hCKXN#Ny!);< Ze`cZ5mqTHBX~4i`@O1TaS?83{1OV2_u%!S1 literal 0 HcmV?d00001 diff --git a/resources/icons/appbar.globe.wire.png b/resources/icons/appbar.globe.wire.png new file mode 100644 index 0000000000000000000000000000000000000000..13c25f6e106cfbcea860f8eabc79cacbac10a493 GIT binary patch literal 510 zcmVeSad^g zZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00C-AL_t(o!|j(ba>6hWMIV_IDskzO zl5|kIqot%xnKDQ46!nWn^T8`{$};71DZ_Xw3_2=D?C8aAXP0 zUH{E9C}p(LN=A(&=}W!wy=CtV=o`L~mC@##`bI`pO#q?;aPqrSaY4OM<>zu0zI>?%#?FnrGu*9!N(6t^HGtgtzj2=aR3E#@tdz%Z(><0200**`{g-h7V1Z>HTPk); zozyUEF`dykY054Z&^~N8Dmc-~h!7(>vZ1w9l+L#Fk`SE9<(W=&xt_9(SfZ_uSTJC6 z7Qk)qunm(~z=+J%$|1JJ)G~DSHtRYcel3%&&*eMSqPthq2b>2FIMGgPT +image/svg+xml + + \ No newline at end of file diff --git a/resources/icons/src/appbar.arrow.left.svg b/resources/icons/src/appbar.arrow.left.svg new file mode 100644 index 000000000..c436355dd --- /dev/null +++ b/resources/icons/src/appbar.arrow.left.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/resources/icons/src/appbar.arrow.shift.svg b/resources/icons/src/appbar.arrow.shift.svg new file mode 100644 index 000000000..9376d4f82 --- /dev/null +++ b/resources/icons/src/appbar.arrow.shift.svg @@ -0,0 +1,57 @@ + +image/svg+xml + + \ No newline at end of file diff --git a/resources/icons/src/appbar.globe.wire.xaml b/resources/icons/src/appbar.globe.wire.xaml new file mode 100644 index 000000000..4443828ab --- /dev/null +++ b/resources/icons/src/appbar.globe.wire.xaml @@ -0,0 +1,4 @@ + + + + From f4767158746420e3d455138a5b7a693c4999f4c6 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:08:10 +0800 Subject: [PATCH 3/9] update keyboard widget test in wtest --- wtest.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wtest.lua b/wtest.lua index a22bb9a48..30b24e7be 100755 --- a/wtest.lua +++ b/wtest.lua @@ -9,6 +9,7 @@ require "ui/widget/infomessage" require "ui/widget/confirmbox" require "ui/widget/touchmenu" require "ui/widget/keyboard" +require "ui/widget/inputtext" require "document/document" require "ui/readerui" require "dbg" @@ -254,8 +255,9 @@ touch_menu = TouchMenu:new{ }, } -keyboard = VirtualKeyboard:new{ - layout = 2 +inputtext = InputText:new{ + width = 400, + height = 300, } ----------------------------------------------------------------------- @@ -268,8 +270,7 @@ UIManager:show(TestGrid) --UIManager:show(Quiz) --UIManager:show(readerwindow) --UIManager:show(touch_menu) -UIManager:show(keyboard) +--UIManager:show(keyboard) +UIManager:show(inputtext) + UIManager:run() - - - From 57a5f18406f463f0f545f7780a73e1414c240d66 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:09:08 +0800 Subject: [PATCH 4/9] add goto page menu entry for pdfreader --- frontend/ui/reader/readergoto.lua | 80 +++++++++++++++++++++++++++++++ frontend/ui/readerui.lua | 9 ++++ 2 files changed, 89 insertions(+) create mode 100644 frontend/ui/reader/readergoto.lua diff --git a/frontend/ui/reader/readergoto.lua b/frontend/ui/reader/readergoto.lua new file mode 100644 index 000000000..fe78e80ae --- /dev/null +++ b/frontend/ui/reader/readergoto.lua @@ -0,0 +1,80 @@ +require "ui/widget/container" +require "ui/widget/inputdialog" + + +ReaderGoto = InputContainer:new{ + goto_menu_title = _("Go To"), + goto_dialog_title = _("Go to Page or Location"), +} + +function ReaderGoto:init() + self.goto_dialog = InputDialog:new{ + title = self.goto_dialog_title, + input_hint = "(1 - "..self.document.info.number_of_pages..")", + buttons = { + { + { + text = _("Cancel"), + enabled = true, + callback = function() + self:onClose() + end, + }, + { + text = _("Page"), + enabled = self.document.info.has_pages, + callback = function() + self:onGotoPage() + end, + }, + { + text = _("Location"), + enabled = not self.document.info.has_pages, + callback = function() + self:onGotoLocation() + end, + }, + }, + }, + input_type = "number", + width = Screen:getWidth() * 0.8, + height = Screen:getHeight() * 0.2, + } + self.ui.menu:registerToMainMenu(self) +end + +function ReaderGoto:addToMainMenu(tab_item_table) + -- insert goto command to main reader menu + table.insert(tab_item_table.navi, { + text = self.goto_menu_title, + callback = function() + self:onShowGotoDialog() + end, + }) +end + +function ReaderGoto:onShowGotoDialog() + DEBUG("show goto dialog") + self.goto_dialog:onShowKeyboard() + UIManager:show(self.goto_dialog) +end + +function ReaderGoto:onClose() + self.goto_dialog:onClose() + UIManager:close(self.goto_dialog) +end + +function ReaderGoto:onGotoPage() + local number = tonumber(self.goto_dialog:getInputText()) + if number then + DEBUG("go to page", number) + self.ui:handleEvent(Event:new("PageUpdate", number)) + end + self:onClose() + return true +end + +function ReaderGoto:onGotoLocation() + -- TODO: implement go to location + self:onClose() +end diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index 58d4068a3..96b8fd079 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -9,6 +9,7 @@ require "ui/reader/readerbookmark" require "ui/reader/readerfont" require "ui/reader/readertypeset" require "ui/reader/readermenu" +require "ui/reader/readergoto" require "ui/reader/readerconfig" require "ui/reader/readercropping" require "ui/reader/readerkopt" @@ -106,6 +107,14 @@ function ReaderUI:init() document = self.document, } table.insert(self, highlight) + -- goto + local goto = ReaderGoto:new{ + dialog = self.dialog, + view = self[1], + ui = self, + document = self.document, + } + table.insert(self, goto) -- dictionary local dict = ReaderDictionary:new{ dialog = self.dialog, From 6457f424072764506bba3af5fbc09d74aa6a23f7 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:10:40 +0800 Subject: [PATCH 5/9] fix fractional pixel coordinates in paintTo function --- frontend/ui/widget/container.lua | 18 ++++++++++-------- frontend/ui/widget/group.lua | 12 ++++++++---- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/frontend/ui/widget/container.lua b/frontend/ui/widget/container.lua index de0e2d4bc..c5cdb448a 100644 --- a/frontend/ui/widget/container.lua +++ b/frontend/ui/widget/container.lua @@ -79,7 +79,7 @@ function BottomContainer:paintTo(bb, x, y) -- for now, we ignore this end self[1]:paintTo(bb, - x + (self.dimen.w - contentSize.w)/2, + x + math.floor((self.dimen.w - contentSize.w)/2), y + (self.dimen.h - contentSize.h)) end @@ -97,10 +97,10 @@ function CenterContainer:paintTo(bb, x, y) local x_pos = x local y_pos = y if self.ignore ~= "height" then - y_pos = y + (self.dimen.h - contentSize.h)/2 + y_pos = y + math.floor((self.dimen.h - contentSize.h)/2) end if self.ignore ~= "width" then - x_pos = x + (self.dimen.w - contentSize.w)/2 + x_pos = x + math.floor((self.dimen.w - contentSize.w)/2) end self[1]:paintTo(bb, x_pos, y_pos) end @@ -116,7 +116,7 @@ function LeftContainer:paintTo(bb, x, y) -- throw error? paint to scrap buffer and blit partially? -- for now, we ignore this end - self[1]:paintTo(bb, x , y + (self.dimen.h - contentSize.h)/2) + self[1]:paintTo(bb, x , y + math.floor((self.dimen.h - contentSize.h)/2)) end --[[ @@ -132,7 +132,7 @@ function RightContainer:paintTo(bb, x, y) end self[1]:paintTo(bb, x + (self.dimen.w - contentSize.w), - y + (self.dimen.h - contentSize.h)/2) + y + math.floor((self.dimen.h - contentSize.h)/2)) end --[[ @@ -186,7 +186,9 @@ function FrameContainer:paintTo(bb, x, y) y + self.margin + self.bordersize + self.padding) end if self.invert then - bb:invertRect(x, y, container_width, container_height) + bb:invertRect(x + self.bordersize, y + self.bordersize, + container_width - 2*self.bordersize, + container_height - 2*self.bordersize) end end @@ -220,7 +222,7 @@ function UnderlineContainer:paintTo(bb, x, y) local content_size = self:getContentSize() local p_y = y if self.vertical_align == "center" then - p_y = (container_size.h - content_size.h) / 2 + y + p_y = math.floor((container_size.h - content_size.h) / 2) + y elseif self.vertical_align == "bottom" then p_y = (container_size.h - content_size.h) + y end @@ -285,7 +287,7 @@ function InputContainer:paintTo(bb, x, y) if self[1] then if self.vertical_align == "center" then local content_size = self[1]:getSize() - self[1]:paintTo(bb, x, y + (self.dimen.h - content_size.h)/2) + self[1]:paintTo(bb, x, y + math.floor((self.dimen.h - content_size.h)/2)) else self[1]:paintTo(bb, x, y) end diff --git a/frontend/ui/widget/group.lua b/frontend/ui/widget/group.lua index 27d06ca19..292aa3af7 100644 --- a/frontend/ui/widget/group.lua +++ b/frontend/ui/widget/group.lua @@ -35,7 +35,7 @@ function HorizontalGroup:paintTo(bb, x, y) if self.align == "center" then widget:paintTo(bb, x + self._offsets[i].x, - y + (size.h - self._offsets[i].y) / 2) + y + math.floor((size.h - self._offsets[i].y) / 2)) elseif self.align == "top" then widget:paintTo(bb, x + self._offsets[i].x, y) elseif self.align == "bottom" then @@ -93,11 +93,15 @@ function VerticalGroup:paintTo(bb, x, y) for i, widget in ipairs(self) do if self.align == "center" then - widget:paintTo(bb, x + (size.w - self._offsets[i].x) / 2, y + self._offsets[i].y) + widget:paintTo(bb, + x + math.floor((size.w - self._offsets[i].x) / 2), + y + self._offsets[i].y) elseif self.align == "left" then widget:paintTo(bb, x, y + self._offsets[i].y) elseif self.align == "right" then - widget:paintTo(bb, x + size.w - self._offsets[i].x, y + self._offsets[i].y) + widget:paintTo(bb, + x + size.w - self._offsets[i].x, + y + self._offsets[i].y) end end end @@ -158,7 +162,7 @@ function OverlapGroup:paintTo(bb, x, y) if wget.align == "right" then wget:paintTo(bb, x+size.w-wget_size.w, y) elseif wget.align == "center" then - wget:paintTo(bb, x+(size.w-wget_size.w)/2, y) + wget:paintTo(bb, x+math.floor((size.w-wget_size.w)/2), y) else -- default to left wget:paintTo(bb, x, y) From b774c1468f3b5f9247c42740fee6716b0ab67409 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:13:24 +0800 Subject: [PATCH 6/9] refactoring font face variable in ScrollText widget --- frontend/ui/widget/dict.lua | 2 +- frontend/ui/widget/text.lua | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/ui/widget/dict.lua b/frontend/ui/widget/dict.lua index 482352e34..82d1d7490 100644 --- a/frontend/ui/widget/dict.lua +++ b/frontend/ui/widget/dict.lua @@ -83,7 +83,7 @@ function DictQuickLookup:update() bordersize = 0, ScrollTextWidget:new{ text = self.definition, - font_face = self.content_face, + face = self.content_face, width = self.width, height = self.height*0.8, dialog = self, diff --git a/frontend/ui/widget/text.lua b/frontend/ui/widget/text.lua index e78269491..14076877c 100644 --- a/frontend/ui/widget/text.lua +++ b/frontend/ui/widget/text.lua @@ -300,9 +300,11 @@ Text widget with vertical scroll bar --]] ScrollTextWidget = InputContainer:new{ text = nil, - font_face = nil, + face = nil, + bgcolor = 0.0, -- [0.0, 1.0] + fgcolor = 1.0, -- [0.0, 1.0] width = 400, - height = 300, + height = 20, scroll_bar_width = scaleByDPI(6), text_scroll_span = scaleByDPI(6), dialog = nil, @@ -311,7 +313,9 @@ ScrollTextWidget = InputContainer:new{ function ScrollTextWidget:init() self.text_widget = TextBoxWidget:new{ text = self.text, - face = self.font_face, + face = self.face, + bgcolor = self.bgcolor, + fgcolor = self.fgcolor, width = self.width - self.scroll_bar_width - self.text_scroll_span, height = self.height } From 196f72a0532545bf9c9b6f1b2d90c259933cb326 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:37:51 +0800 Subject: [PATCH 7/9] add onGotoPage handler in readerpaging --- frontend/ui/reader/readergoto.lua | 19 +++++++++---------- frontend/ui/reader/readerpaging.lua | 5 ++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frontend/ui/reader/readergoto.lua b/frontend/ui/reader/readergoto.lua index fe78e80ae..739d71704 100644 --- a/frontend/ui/reader/readergoto.lua +++ b/frontend/ui/reader/readergoto.lua @@ -17,21 +17,21 @@ function ReaderGoto:init() text = _("Cancel"), enabled = true, callback = function() - self:onClose() + self:close() end, }, { text = _("Page"), enabled = self.document.info.has_pages, callback = function() - self:onGotoPage() + self:gotoPage() end, }, { text = _("Location"), enabled = not self.document.info.has_pages, callback = function() - self:onGotoLocation() + self:gotoLocation() end, }, }, @@ -59,22 +59,21 @@ function ReaderGoto:onShowGotoDialog() UIManager:show(self.goto_dialog) end -function ReaderGoto:onClose() +function ReaderGoto:close() self.goto_dialog:onClose() UIManager:close(self.goto_dialog) end -function ReaderGoto:onGotoPage() +function ReaderGoto:gotoPage() local number = tonumber(self.goto_dialog:getInputText()) if number then - DEBUG("go to page", number) - self.ui:handleEvent(Event:new("PageUpdate", number)) + self.ui:handleEvent(Event:new("GotoPage", number)) end - self:onClose() + self:close() return true end -function ReaderGoto:onGotoLocation() +function ReaderGoto:gotoLocation() -- TODO: implement go to location - self:onClose() + self:close() end diff --git a/frontend/ui/reader/readerpaging.lua b/frontend/ui/reader/readerpaging.lua index 3266c3fc8..c65779d60 100644 --- a/frontend/ui/reader/readerpaging.lua +++ b/frontend/ui/reader/readerpaging.lua @@ -670,4 +670,7 @@ function ReaderPaging:gotoPage(number, orig) return true end - +function ReaderPaging:onGotoPage(number) + self:gotoPage(number) + return true +end From 32bd30aae9c62d092226c981088ed6727b621022 Mon Sep 17 00:00:00 2001 From: chrox Date: Tue, 30 Jul 2013 23:38:57 +0800 Subject: [PATCH 8/9] UI tweaks --- frontend/ui/widget/inputtext.lua | 2 ++ frontend/ui/widget/keyboard.lua | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 17893e521..35aecbb22 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -76,6 +76,8 @@ function InputText:initKeyboard() self.keyboard = VirtualKeyboard:new{ layout = keyboard_layout, inputbox = self, + width = Screen:getWidth(), + height = Screen:getHeight()*0.32, } end diff --git a/frontend/ui/widget/keyboard.lua b/frontend/ui/widget/keyboard.lua index 9e90da9fb..472ca89aa 100644 --- a/frontend/ui/widget/keyboard.lua +++ b/frontend/ui/widget/keyboard.lua @@ -84,7 +84,7 @@ function VirtualKey:onTapSelect() if self.callback then self.callback() end - UIManager:scheduleIn(0.08, function() self:invert(false) end) + UIManager:scheduleIn(0.02, function() self:invert(false) end) return true end @@ -94,7 +94,7 @@ function VirtualKey:onDoubleTapSelect() self.callback() -- once self.callback() -- twice end - UIManager:scheduleIn(0.08, function() self:invert(false) end) + UIManager:scheduleIn(0.02, function() self:invert(false) end) return true end From ef7f3fec90799dd524c01a12500da9d27cc9a964 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 31 Jul 2013 13:51:01 +0800 Subject: [PATCH 9/9] fix keyboard in landscape --- frontend/ui/reader/readergoto.lua | 30 +++++++++++++++--------------- frontend/ui/widget/inputtext.lua | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/frontend/ui/reader/readergoto.lua b/frontend/ui/reader/readergoto.lua index 739d71704..e0a59dfd4 100644 --- a/frontend/ui/reader/readergoto.lua +++ b/frontend/ui/reader/readergoto.lua @@ -8,6 +8,21 @@ ReaderGoto = InputContainer:new{ } function ReaderGoto:init() + self.ui.menu:registerToMainMenu(self) +end + +function ReaderGoto:addToMainMenu(tab_item_table) + -- insert goto command to main reader menu + table.insert(tab_item_table.navi, { + text = self.goto_menu_title, + callback = function() + self:onShowGotoDialog() + end, + }) +end + +function ReaderGoto:onShowGotoDialog() + DEBUG("show goto dialog") self.goto_dialog = InputDialog:new{ title = self.goto_dialog_title, input_hint = "(1 - "..self.document.info.number_of_pages..")", @@ -40,21 +55,6 @@ function ReaderGoto:init() width = Screen:getWidth() * 0.8, height = Screen:getHeight() * 0.2, } - self.ui.menu:registerToMainMenu(self) -end - -function ReaderGoto:addToMainMenu(tab_item_table) - -- insert goto command to main reader menu - table.insert(tab_item_table.navi, { - text = self.goto_menu_title, - callback = function() - self:onShowGotoDialog() - end, - }) -end - -function ReaderGoto:onShowGotoDialog() - DEBUG("show goto dialog") self.goto_dialog:onShowKeyboard() UIManager:show(self.goto_dialog) end diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 35aecbb22..7c347a74b 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -77,7 +77,7 @@ function InputText:initKeyboard() layout = keyboard_layout, inputbox = self, width = Screen:getWidth(), - height = Screen:getHeight()*0.32, + height = math.max(Screen:getWidth(), Screen:getHeight())*0.33, } end