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:
33
widget.lua
33
widget.lua
@ -1,9 +1,7 @@
|
||||
local rectunion = require('lib.gear.rect').union
|
||||
|
||||
local Widget = {
|
||||
__call = function(cls, args)
|
||||
return cls.new(args)
|
||||
end
|
||||
__call = function(cls, args) return cls.new(args) end
|
||||
}
|
||||
Widget.__index = Widget
|
||||
|
||||
@ -40,25 +38,26 @@ function Widget:grabFocus()
|
||||
if focused ~= nil then
|
||||
-- Notify leave
|
||||
focused.hovered = false
|
||||
if focused.grabkeyboard then
|
||||
if love.system.getOS() == 'Android' or love.system.getOS() == 'iOS' then
|
||||
love.keyboard.setTextInput(false)
|
||||
end
|
||||
love.keyboard.setKeyRepeat(false)
|
||||
end
|
||||
|
||||
-- Widget specific focus loss
|
||||
focused:loseFocus()
|
||||
-- Event handler
|
||||
focused:onLeave()
|
||||
|
||||
if focused.grabkeyboard then
|
||||
-- If focused widget stole input,
|
||||
-- then drop current input snapshot, since
|
||||
-- those events should have been already
|
||||
-- managed directly
|
||||
ui.device:snapshot()
|
||||
end
|
||||
end
|
||||
|
||||
local wasHovered = self.hovered
|
||||
|
||||
self.hovered = true
|
||||
if self.grabkeyboard then
|
||||
love.keyboard.setTextInput(true, self.x,self.y,self.w,self.h)
|
||||
love.keyboard.setKeyRepeat(true)
|
||||
end
|
||||
if not wasHovered then
|
||||
-- First time hovered, notify enter
|
||||
self:gainFocus()
|
||||
self:onEnter()
|
||||
end
|
||||
|
||||
@ -100,7 +99,11 @@ function Widget:colorForState()
|
||||
end
|
||||
end
|
||||
|
||||
-- Common NOP event handlers
|
||||
-- NOP hooks for UI internal use
|
||||
function Widget:loseFocus() end
|
||||
function Widget:gainFocus() end
|
||||
|
||||
-- NOP event handlers, publicly overridable
|
||||
function Widget:onHit() end
|
||||
function Widget:onEnter() end
|
||||
function Widget:onLeave() end
|
||||
|
Reference in New Issue
Block a user