[layout] Improve focus management

This commit is contained in:
Lorenzo Cogotti 2023-09-19 18:17:22 +02:00
parent 1c09a094c4
commit c52d9e1608
1 changed files with 12 additions and 14 deletions

View File

@ -14,7 +14,6 @@
local BASE = (...):gsub('layout$', '')
local Widget = require(BASE..'widget')
local core = require(BASE..'core')
local gear = require 'lib.gear'
@ -126,12 +125,21 @@ function Layout:layoutWidgets()
self.y = ry
self.w = math.max(rw, 0)
self.h = math.max(rh, 0)
-- A Layout ignores focus if empty or containing only nofocus widgets
self.nofocus = true
for _,w in ipairs(self) do
if not w.nofocus then
self.nofocus = false
break
end
end
end
-- Find layout's child containing the provided widget.
local function childof(layout, widget)
local parent = widget.parent
while parent ~= layout do
while not rawequal(parent, layout) do
widget = parent
parent = widget.parent
end
@ -173,16 +181,6 @@ function Layout:new(args)
self.padding = self.padding or 0
self.stack = {}
-- A Layout ignores focus if empty or containing only nofocus widgets
self.nofocus = true
for _,w in ipairs(self) do
if not w.nofocus then
self.nofocus = false
break
end
end
return self
end
@ -201,7 +199,7 @@ function Layout:after(widget)
widget = childof(self, widget)
for i = 1,#self do
if self[i] == widget then
if rawequal(self[i], widget) then
-- Search to the right/down
return scanforward(self, i+1)
end
@ -213,7 +211,7 @@ function Layout:before(widget)
widget = childof(self, widget)
for i = 1,#self do
if self[i] == widget then
if rawequal(self[i], widget) then
-- Search to the left/up
return scanbackwards(self, i-1)
end