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 end
function View:inputToSubviews(keys) function View:inputToSubviews(keys)
for _,child in ipairs(self.subviews) do local children = self.subviews
if child.active and child:onInput(keys) then
for i=#children,1,-1 do
local child = children[i]
if child.visible and child.active and child:onInput(keys) then
return true return true
end end
end end

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