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

Loading…
Cancel
Save