From 0046b093f761fb42f03fccb32a56efcf854c2b41 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 17 Oct 2012 11:49:11 +0400 Subject: [PATCH] Link visibility and event handling order. - Hidden widgets don't receive events. - Children handle events in top to bottom order. --- library/lua/gui.lua | 7 +++++-- library/lua/gui/widgets.lua | 11 +++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 90eeb823a..18b0d67d8 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -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 diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 0a6d99ba6..05100c00b 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -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