mirror of
https://codeberg.org/1414codeforge/yui.git
synced 2025-06-05 22:19:11 +02:00
[*] General code improvement.
* Rework navigation allowing direct management and triggering for grabkeyboard widgets. * Navigation code now behaves better with deeply nested layouts. * Allow widget hierarchies deeper than 2 (__call() is implemented for every Widget metatable). * Make BASE locals more secure (match '<filename>$' in regexp)
This commit is contained in:
30
input.lua
30
input.lua
@ -1,12 +1,15 @@
|
||||
local BASE = (...):gsub('input', '')
|
||||
local BASE = (...):gsub('input$', '')
|
||||
|
||||
local Widget = require(BASE..'widget')
|
||||
local core = require(BASE..'core')
|
||||
|
||||
local utf8 = require 'utf8'
|
||||
|
||||
-- Grabs keyboard on focus
|
||||
local Input = setmetatable({ grabkeyboard = true }, Widget)
|
||||
-- NOTE: Input manages keyboard directly.
|
||||
local Input = setmetatable({
|
||||
grabkeyboard = true,
|
||||
__call = function(cls, args) return cls.new(args) end
|
||||
}, Widget)
|
||||
Input.__index = Input
|
||||
|
||||
|
||||
@ -28,6 +31,18 @@ function Input.new(args)
|
||||
return self
|
||||
end
|
||||
|
||||
-- NOTE: Input steals keyboard input on focus.
|
||||
function Input:gainFocus()
|
||||
love.keyboard.setTextInput(true, self.x,self.y,self.w,self.h)
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
end
|
||||
function Input:loseFocus()
|
||||
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
|
||||
love.keyboard.setTextInput(false)
|
||||
end
|
||||
love.keyboard.setKeyRepeat(false)
|
||||
end
|
||||
|
||||
function Input:onPointerInput(px,py, clicked)
|
||||
if clicked then
|
||||
self:grabFocus()
|
||||
@ -92,9 +107,12 @@ function Input:keyreleased(key)
|
||||
self.cursor = 1
|
||||
elseif key == 'end' then
|
||||
self.cursor = utf8.len(self.text)+1
|
||||
elseif key == 'return' then
|
||||
self:onChange(self.text)
|
||||
self.cursor = 1
|
||||
elseif key == 'up' or key == 'down' then
|
||||
self.ui:navigate(key)
|
||||
elseif key == 'tab' or key == 'return' then
|
||||
self.ui:navigate('right')
|
||||
elseif key == 'escape' then
|
||||
self.ui:navigate('cancel')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user