From 4c5d1caa920f848aaa14e6674481548ae4d82ed7 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 26 Dec 2013 22:32:34 +0800 Subject: [PATCH 1/4] detect touch event for more responsive UI --- frontend/ui/gesturedetector.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/ui/gesturedetector.lua b/frontend/ui/gesturedetector.lua index e35e658dc..007958d08 100644 --- a/frontend/ui/gesturedetector.lua +++ b/frontend/ui/gesturedetector.lua @@ -350,6 +350,16 @@ function GestureDetector:handleNonTap(tev) return self:switchState("holdState", tev, true) end end, deadline) + DEBUG("handle non-tap", tev) + return { + ges = "touch", + pos = Geom:new{ + x = tev.x, + y = tev.y, + w = 0, h = 0, + }, + time = tev.timev, + } else -- it is not end of touch event, see if we need to switch to -- other states From f12d8eb9b489288931f8c5f5f6d7246f1656c911 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 26 Dec 2013 22:34:00 +0800 Subject: [PATCH 2/4] add align field in WidgetContainer --- frontend/ui/widget/container/widgetcontainer.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/ui/widget/container/widgetcontainer.lua b/frontend/ui/widget/container/widgetcontainer.lua index 78226ba19..4ee53cf3d 100644 --- a/frontend/ui/widget/container/widgetcontainer.lua +++ b/frontend/ui/widget/container/widgetcontainer.lua @@ -40,7 +40,20 @@ end function WidgetContainer:paintTo(bb, x, y) -- default to pass request to first child widget if self[1] then - return self[1]:paintTo(bb, x, y) + x = x + (self.dimen.x or 0) + y = y + (self.dimen.y or 0) + if self.align == "top" then + local contentSize = self[1]:getSize() + self[1]:paintTo(bb, + x + math.floor((self.dimen.w - contentSize.w)/2), y) + elseif self.align == "bottom" then + local contentSize = self[1]:getSize() + self[1]:paintTo(bb, + x + math.floor((self.dimen.w - contentSize.w)/2), + y + (self.dimen.h - contentSize.h)) + else + return self[1]:paintTo(bb, x, y) + end end end From 13d70eec9b620da19ee3c4e94063cee474d2373a Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 26 Dec 2013 22:40:40 +0800 Subject: [PATCH 3/4] add Kindle-like dictionary window follow-up --- frontend/ui/reader/readerdictionary.lua | 28 +++++++++++---- frontend/ui/reader/readerhighlight.lua | 6 ++-- frontend/ui/widget/closebutton.lua | 45 +++++++++++++++++++++++++ frontend/ui/widget/dictquicklookup.lua | 37 +++++++++++++++----- 4 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 frontend/ui/widget/closebutton.lua diff --git a/frontend/ui/reader/readerdictionary.lua b/frontend/ui/reader/readerdictionary.lua index 6388dcd14..aebd6b797 100644 --- a/frontend/ui/reader/readerdictionary.lua +++ b/frontend/ui/reader/readerdictionary.lua @@ -1,19 +1,20 @@ local EventListener = require("ui/widget/eventlistener") local UIManager = require("ui/uimanager") local DictQuickLookup = require("ui/widget/dictquicklookup") +local Geom = require("ui/geometry") local Screen = require("ui/screen") local JSON = require("JSON") local DEBUG = require("dbg") local ReaderDictionary = EventListener:new{} -function ReaderDictionary:onLookupWord(highlight, word) +function ReaderDictionary:onLookupWord(highlight, word, box) self.highlight = highlight - self:stardictLookup(word) + self:stardictLookup(word, box) end -function ReaderDictionary:stardictLookup(word) - DEBUG("lookup word:", word) +function ReaderDictionary:stardictLookup(word, box) + DEBUG("lookup word:", word, box) if word then -- strip punctuation characters around selected word word = string.gsub(word, "^%p+", '') @@ -27,14 +28,25 @@ function ReaderDictionary:stardictLookup(word) --DEBUG("result str:", word, results_str) local ok, results = pcall(JSON.decode, JSON, results_str) --DEBUG("lookup result table:", word, results) - self:showDict(results) + self:showDict(results, box) end end end -function ReaderDictionary:showDict(results) +function ReaderDictionary:showDict(results, box) if results and results[1] then DEBUG("showing quick lookup dictionary window") + local align = nil + local region = Geom:new{x = 0, w = Screen:getWidth()} + if box.y + box.h/2 < Screen:getHeight()/2 then + region.y = box.y + box.h + region.h = Screen:getHeight() - box.y - box.h + align = "top" + else + region.y = 0 + region.h = box.y + align = "bottom" + end UIManager:show(DictQuickLookup:new{ ui = self.ui, highlight = self.highlight, @@ -42,7 +54,9 @@ function ReaderDictionary:showDict(results) results = results, dictionary = self.default_dictionary, width = Screen:getWidth() - Screen:scaleByDPI(120), - height = Screen:getHeight()*0.43, + height = math.min(region.h*0.7, Screen:getHeight()*0.5), + region = region, + align = align, }) end end diff --git a/frontend/ui/reader/readerhighlight.lua b/frontend/ui/reader/readerhighlight.lua index 6f0b63f4a..a406decd2 100644 --- a/frontend/ui/reader/readerhighlight.lua +++ b/frontend/ui/reader/readerhighlight.lua @@ -225,12 +225,14 @@ end function ReaderHighlight:lookup(selected_word) -- if we extracted text directly if selected_word.word then - self.ui:handleEvent(Event:new("LookupWord", self, selected_word.word)) + local word_box = self.view:pageToScreenTransform(selected_word.page, selected_word.sbox) + self.ui:handleEvent(Event:new("LookupWord", self, selected_word.word, word_box)) -- or we will do OCR else local word = self.ui.document:getOCRWord(self.hold_pos.page, selected_word) DEBUG("OCRed word:", word) - self.ui:handleEvent(Event:new("LookupWord", self, word)) + local word_box = self.view:pageToScreenTransform(selected_word.page, selected_word.sbox) + self.ui:handleEvent(Event:new("LookupWord", self, word, word_box)) end end diff --git a/frontend/ui/widget/closebutton.lua b/frontend/ui/widget/closebutton.lua new file mode 100644 index 000000000..a1710fa8b --- /dev/null +++ b/frontend/ui/widget/closebutton.lua @@ -0,0 +1,45 @@ +local InputContainer = require("ui/widget/container/inputcontainer") +local FrameContainer = require("ui/widget/container/framecontainer") +local CenterContainer = require("ui/widget/container/centercontainer") +local TextWidget = require("ui/widget/textwidget") +local GestureRange = require("ui/gesturerange") +local UIManager = require("ui/uimanager") +local Geom = require("ui/geometry") +local Font = require("ui/font") + +--[[ +a button widget that shows an "×" and handles closing window when tapped +--]] +local CloseButton = InputContainer:new{ + align = "right", + window = nil, +} + +function CloseButton:init() + local text_widget = TextWidget:new{ + text = "×", + face = Font:getFace("cfont", 32), + } + self[1] = FrameContainer:new{ + bordersize = 0, + padding = 0, + text_widget + } + + self.dimen = text_widget:getSize():copy() + + self.ges_events.Close = { + GestureRange:new{ + ges = "tap", + range = self.dimen, + }, + doc = "Tap on close button", + } +end + +function CloseButton:onClose() + self.window:onClose() + return true +end + +return CloseButton diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 056b0f20b..d1c23ddf6 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -1,10 +1,13 @@ local InputContainer = require("ui/widget/container/inputcontainer") +local WidgetContainer = require("ui/widget/container/widgetcontainer") local FrameContainer = require("ui/widget/container/framecontainer") local CenterContainer = require("ui/widget/container/centercontainer") +local CloseButton = require("ui/widget/closebutton") local TextWidget = require("ui/widget/textwidget") local TextBoxWidget = require("ui/widget/textboxwidget") local ScrollTextWidget = require("ui/widget/scrolltextwidget") local LineWidget = require("ui/widget/linewidget") +local OverlapGroup = require("ui/widget/overlapgroup") local Screen = require("ui/screen") local GestureRange = require("ui/gesturerange") local Geom = require("ui/geometry") @@ -66,6 +69,10 @@ function DictQuickLookup:init() }, }, } + table.insert(self.dict_bar, + CloseButton:new{ + window = self, + }) end end @@ -101,7 +108,7 @@ function DictQuickLookup:update() text = self.definition, face = self.content_face, width = self.width, - height = self.height*0.8, + height = self.height*0.6, dialog = self, }, } @@ -153,6 +160,11 @@ function DictQuickLookup:update() } } + self.dict_bar = OverlapGroup:new{ + dimen = {w = button_table:getSize().w, h = self.dict_title:getSize().h}, + self.dict_title, + } + self.dict_frame = FrameContainer:new{ radius = 8, bordersize = 3, @@ -161,7 +173,7 @@ function DictQuickLookup:update() background = 0, VerticalGroup:new{ align = "left", - self.dict_title, + self.dict_bar, title_bar, -- word CenterContainer:new{ @@ -189,10 +201,14 @@ function DictQuickLookup:update() } } } - - self[1] = CenterContainer:new{ - dimen = Screen:getSize(), - self.dict_frame, + self[1] = WidgetContainer:new{ + align = self.align, + dimen = self.region:copy(), + FrameContainer:new{ + bordersize = 0, + padding = Screen:scaleByDPI(5), + self.dict_frame, + } } UIManager.repaint_all = true UIManager.full_refresh = true @@ -267,8 +283,7 @@ end function DictQuickLookup:onTapCloseDict(arg, ges_ev) if ges_ev.pos:notIntersectWith(self.dict_frame.dimen) then - UIManager:close(self) - self.highlight:handleEvent(Event:new("Tap")) + self:onClose() return true elseif not ges_ev.pos:notIntersectWith(self.dict_title.dimen) then self.ui:handleEvent(Event:new("UpdateDefaultDict", self.dictionary)) @@ -277,4 +292,10 @@ function DictQuickLookup:onTapCloseDict(arg, ges_ev) return true end +function DictQuickLookup:onClose() + UIManager:close(self) + self.highlight:handleEvent(Event:new("Tap")) + return true +end + return DictQuickLookup From b9d0d6d0e4f2cc22efa8115be905834d8d422075 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 26 Dec 2013 22:56:23 +0800 Subject: [PATCH 4/4] update koreader-base --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index 1f45c486f..ffec35674 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 1f45c486f7ddbe43156ec15633f2b188aba126cb +Subproject commit ffec35674a11d13750224ce1b00704dea0f3f762