2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/ui/gesturerange.lua

70 lines
2.0 KiB
Lua
Raw Normal View History

local TimeVal = require("ui/timeval")
2013-10-18 20:38:07 +00:00
local GestureRange = {
-- gesture matching type
2014-03-13 13:52:43 +00:00
ges = nil,
-- spatial range limits the gesture emitting position
range = nil,
-- temproal range limits the gesture emitting rate
rate = nil,
-- scale limits of this gesture
2014-03-13 13:52:43 +00:00
scale = nil,
2013-10-18 20:38:07 +00:00
}
function GestureRange:new(from_o)
local o = from_o or {}
2014-03-13 13:52:43 +00:00
setmetatable(o, self)
self.__index = self
return o
2013-10-18 20:38:07 +00:00
end
function GestureRange:match(gs)
2014-03-13 13:52:43 +00:00
if gs.ges ~= self.ges then
return false
end
if self.range then
-- sometimes widget dimenension is not available when creating a gesturerage
-- for some action, now we accept a range function that will be later called
-- and the result of which will be used to check gesture match
-- e.g. range = function() return self.dimen end
-- for inputcontainer given that the x and y field of `self.dimen` is only
-- filled when the inputcontainer is painted into blitbuffer
local range
if type(self.range) == "function" then
range = self.range()
else
range = self.range
end
Text input fixes and enhancements (#4084) InputText, ScrollTextWidget, TextBoxWidget: - proper line scrolling when moving cursor or inserting/deleting text to behave like most text editors do - fix cursor navigation, optimize refreshes when moving only the cursor, don't recreate the textwidget when moving cursor up/down - optimize refresh areas, stick to "ui" to avoid a "partial" black flash every 6 appended or deleted chars InputText: - fix issue when toggling Show password multiple times - new option: InputText.cursor_at_end (default: true) - if no InputText.height provided, measure the text widget height that we would start with, and use a ScrollTextWidget with that fixed height, so widget does not overflow container if we extend the text and increase the number of lines - as we are using "ui" refreshes while text editing, allows refreshing the InputText with a diagonal swipe on it (actually, refresh the whole screen, which allows refreshing the keyboard too if needed) ScrollTextWidget: - properly align scrollbar with its TextBoxWidget TextBoxWidget: - some cleanup (added new properties to avoid many method calls), added proxy methods for upper widgets to get them - reordered/renamed/refactored the *CharPos* methods for easier reading (sorry for the diff that won't help reviewing, but that was needed) InputDialog: - new options: allow_newline = false, -- allow entering new lines cursor_at_end = true, -- starts with cursor at end of text, ready to append fullscreen = false, -- adjust to full screen minus keyboard condensed = false, -- true will prevent adding air and balance between elements add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons add_nav_bar = false, -- append a row of page navigation buttons - find the most adequate text height, when none provided or fullscreen, to not overflow screen (and not be stuck with Cancel/Save buttons hidden) - had to disable the use of a MovableContainer (many issues like becoming transparent when a PathChooser comes in front, Hold to paste from clipboard, moving the InputDialog under the keyboard and getting stuck...) GestureRange: fix possible crash (when event processed after widget destruction ?) LoginDialog: fix some ui stack increase and possible crash when switching focus many times.
2018-07-19 06:30:40 +00:00
if not range or not range:contains(gs.pos) then
2014-03-13 13:52:43 +00:00
return false
end
end
2014-03-13 13:52:43 +00:00
if self.rate then
-- This filed restraints the upper limit rate(matches per second).
-- It's most useful for e-ink devices with less powerfull CPUs and
-- screens that cannot handle gesture events that otherwise will be
-- generated
2014-03-13 13:52:43 +00:00
local last_time = self.last_time or TimeVal:new{}
if gs.time - last_time > TimeVal:new{usec = 1000000 / self.rate} then
self.last_time = gs.time
else
return false
end
end
if self.scale then
local scale = gs.distance or gs.span
if self.scale[1] > scale or self.scale[2] < scale then
2014-03-13 13:52:43 +00:00
return false
end
end
if self.direction then
if self.direction ~= gs.direction then
return false
end
end
return true
2013-10-18 20:38:07 +00:00
end
return GestureRange