Link visibility and event handling order.

- Hidden widgets don't receive events.
- Children handle events in top to bottom order.
develop
Alexander Gavrilov 2012-10-17 11:49:11 +04:00
parent ad4f9908fb
commit 0046b093f7
2 changed files with 10 additions and 8 deletions

@ -457,8 +457,11 @@ function View:onRenderBody(dc)
end
function View:inputToSubviews(keys)
for _,child in ipairs(self.subviews) do
if child.active and child:onInput(keys) then
local children = self.subviews
for i=#children,1,-1 do
local child = children[i]
if child.visible and child.active and child:onInput(keys) then
return true
end
end

@ -7,10 +7,9 @@ local utils = require('utils')
local dscreen = dfhack.screen
local function show_view(view,vis,act)
local function show_view(view,vis)
if view then
view.visible = vis
view.active = act
end
end
@ -79,7 +78,7 @@ Pages = defclass(Pages, Panel)
function Pages:init(args)
for _,v in ipairs(self.subviews) do
show_view(v, false, false)
v.visible = false
end
self:setSelected(args.selected or 1)
end
@ -96,9 +95,9 @@ function Pages:setSelected(idx)
end
end
show_view(self.subviews[self.selected], false, false)
show_view(self.subviews[self.selected], false)
self.selected = math.min(math.max(1, idx), #self.subviews)
show_view(self.subviews[self.selected], true, true)
show_view(self.subviews[self.selected], true)
end
function Pages:getSelected()
@ -583,7 +582,7 @@ function FilteredList:init(info)
text_pen = COLOR_LIGHTRED,
frame = { l = info.icon_width, t = 2 },
}
self:addviews{ self.list, self.edit, self.not_found }
self:addviews{ self.edit, self.list, self.not_found }
self:setChoices(info.choices, info.selected)
end