Merge pull request #351 from chrox/master

fix lost refresh in inputdialog enter callback
pull/358/head
Qingping Hou 11 years ago
commit 92ede68253

@ -532,29 +532,29 @@ end
--[[
get index of nearest word box around pos
--]]
local function getWordBoxIndices(boxes, pos)
local function inside_box(box)
local x, y = pos.x, pos.y
if box.x0 <= x and box.y0 <= y and box.x1 >= x and box.y1 >= y then
return true
end
return false
local function inside_box(box, pos)
local x, y = pos.x, pos.y
if box.x0 <= x and box.y0 <= y and box.x1 >= x and box.y1 >= y then
return true
end
local function box_distance(i, j)
local wb = boxes[i][j]
if inside_box(wb) then
return 0
else
local x0, y0 = pos.x, pos.y
local x1, y1 = (wb.x0 + wb.x1) / 2, (wb.y0 + wb.y1) / 2
return (x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1)
end
return false
end
local function box_distance(box, pos)
if inside_box(box, pos) then
return 0
else
local x0, y0 = pos.x, pos.y
local x1, y1 = (box.x0 + box.x1) / 2, (box.y0 + box.y1) / 2
return (x0 - x1)*(x0 - x1) + (y0 - y1)*(y0 - y1)
end
end
local function getWordBoxIndices(boxes, pos)
local m, n = 1, 1
for i = 1, #boxes do
for j = 1, #boxes[i] do
if box_distance(i, j) < box_distance(m, n) then
if box_distance(boxes[i][j], pos) < box_distance(boxes[m][n], pos) then
m, n = i, j
end
end
@ -586,6 +586,7 @@ end
get text and text boxes between pos0 and pos1
--]]
function KoptInterface:getTextFromBoxes(boxes, pos0, pos1)
if not pos0 or not pos1 then return {} end
local line_text = ""
local line_boxes = {}
local i_start, j_start = getWordBoxIndices(boxes, pos0)
@ -706,12 +707,10 @@ function KoptInterface:nativeToReflowPosTransform(doc, pageno, pos)
local kctx_hash = "kctx|"..context_hash
local cached = Cache:check(kctx_hash)
local kc = self:waitForContext(cached.kctx)
--kc:setDebug()
--DEBUG("transform native pos", pos)
local rpos = {}
rpos.x, rpos.y = kc:nativeToReflowPosTransform(pos.x, pos.y)
--DEBUG("transformed reflowed pos", rpos)
return rpos
local x, y = kc:nativeToReflowPosTransform(pos.x, pos.y)
if x ~= nil and y ~= nil then
return {x=x, y=y}
end
end
--[[

@ -12,6 +12,52 @@ local Input = require("ui/input")
local DEBUG = require("dbg")
local _ = require("gettext")
local HighlightDialog = InputContainer:new{
buttons = nil,
tap_close_callback = nil,
}
function HighlightDialog:init()
if Device:hasKeyboard() then
self.key_events = {
AnyKeyPressed = { { Input.group.Any },
seqtext = "any key", doc = _("close dialog") }
}
else
self.ges_events.TapClose = {
GestureRange:new{
ges = "tap",
range = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
}
}
end
self[1] = CenterContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
ButtonTable:new{
width = Screen:getWidth()*0.9,
buttons = self.buttons,
},
background = 0,
bordersize = 2,
radius = 7,
padding = 2,
}
}
end
function HighlightDialog:onTapClose()
UIManager:close(self)
if self.tap_close_callback then
self.tap_close_callback()
end
return true
end
local ReaderHighlight = InputContainer:new{}
function ReaderHighlight:init()
@ -168,7 +214,8 @@ function ReaderHighlight:onHoldPan(arg, ges)
self.view.highlight.temp[self.hold_pos.page] = self.selected_text.sboxes
-- remove selected word if hold moves out of word box
if self.selected_word and
not self.selected_word.sbox:contains(self.selected_text.sboxes[1]) then
not self.selected_word.sbox:contains(self.selected_text.sboxes[1]) or
#self.selected_text.sboxes > 1 then
self.selected_word = nil
end
UIManager:setDirty(self.dialog, "partial")
@ -198,52 +245,6 @@ function ReaderHighlight:translate(selected_text)
end
end
HighlightDialog = InputContainer:new{
buttons = nil,
tap_close_callback = nil,
}
function HighlightDialog:init()
if Device:hasKeyboard() then
key_events = {
AnyKeyPressed = { { Input.group.Any },
seqtext = "any key", doc = _("close dialog") }
}
else
self.ges_events.TapClose = {
GestureRange:new{
ges = "tap",
range = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = Screen:getHeight(),
}
}
}
end
self[1] = CenterContainer:new{
dimen = Screen:getSize(),
FrameContainer:new{
ButtonTable:new{
width = Screen:getWidth()*0.9,
buttons = self.buttons,
},
background = 0,
bordersize = 2,
radius = 7,
padding = 2,
}
}
end
function HighlightDialog:onTapClose()
UIManager:close(self)
if self.tap_close_callback then
self.tap_close_callback()
end
return true
end
function ReaderHighlight:onHoldRelease(arg, ges)
if self.selected_word then
self:lookup(self.selected_word)

@ -99,7 +99,7 @@ end
function InputText:addChar(char)
if self.enter_callback and char == '\n' then
UIManager:scheduleIn(0.1, function() self.enter_callback() end)
UIManager:scheduleIn(0.3, function() self.enter_callback() end)
return
end
table.insert(self.charlist, self.charpos, char)

Loading…
Cancel
Save