[ui] Fix focus stealing, minor style fixes.

master
Lorenzo Cogotti 2 years ago
parent b06d56b945
commit e38e6fcfb5

@ -99,7 +99,7 @@ function Ui.new(args)
self.w,self.h = root.w,root.h
local firstfocus, cancelfocus = resolveautofocus(root)
if firstfocus == nil then
if not firstfocus then
firstfocus = isinstance(root, Layout) and
root:first() or
root
@ -115,34 +115,34 @@ end
function Ui:keypressed(key, scancode, isrepeat)
local focused = self.focused
if focused ~= nil and focused.grabkeyboard then
if focused and focused.grabkeyboard then
focused:keypressed(key, scancode, isrepeat)
end
end
function Ui:keyreleased(key, scancode)
local focused = self.focused
if focused ~= nil and focused.grabkeyboard then
if focused and focused.grabkeyboard then
focused:keyreleased(key, scancode)
end
end
function Ui:textinput(text)
local focused = self.focused
if focused ~= nil and focused.grabkeyboard then
if focused and focused.grabkeyboard then
focused:textinput(text)
end
end
function Ui:textedited(text, start, length)
local focused = self.focused
if focused ~= nil and focused.grabkeyboard then
if focused and focused.grabkeyboard then
focused:textedited(text, start, length)
end
end
local function actionpropagate(widget, action)
while widget ~= nil do
while widget do
if widget:onActionInput(action) then
return true -- action consumed
end
@ -166,7 +166,10 @@ end
local function eventpropagate(ui, snap)
-- 1. Pointer events
if snap.pointer and not ui.grabpointer then
local dropPointer = ui.focused and ui.focused.grabpointer
local dropAction = ui.focused and ui.focused.grabkeyboard
if snap.pointer and not dropPointer then
local root = ui[1]
local x,y,w,h = root.x,root.y,root.w,root.h
@ -176,7 +179,7 @@ local function eventpropagate(ui, snap)
end
-- 2. Actions (keyboard/buttons)
if snap.action and not ui.grabkeyboard then
if snap.action and not dropAction then
local consumed = actionpropagate(ui.focused, snap)
if not consumed then

Loading…
Cancel
Save