[*] 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:
2022-08-24 11:18:48 +02:00
parent 3b2b460012
commit 1d42498ee7
13 changed files with 283 additions and 187 deletions

View File

@ -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