The existing show/hide methods within Woopsi are designed to allow hidden gadgets to be moved out of the gadget hierarchy entirely. When a gadget is hidden, it gets moved into a separate array within its parent where it is totally ignored until it is shown again. This means that hidden gadgets do not cause any performance loss at all; in fact, other than their memory requirements, hidden gadgets use the same resources as non-existent gadgets.
This can be problematic, though, as John discovered. Hidden gadgets that get re-shown are pushed onto the end of the gadget array, thus losing their original z-index. There’s no point in remembering the original z-index as the gadget order may have changed.
To work around this, I’ve renamed the current hide/show system to “shelve” and “unshelve”. If you want to remove a gadget from the system but don’t want to recreate it later, you can shelve() it. If you want to bring it back, you can unshelve() it. I have added new show() and hide() functions that just make a gadget invisible and non-interactive. However, unlike shelved gadgets Woopsi will attempt (fruitlessly) to interact with hidden gadgets.
There are a couple of other changes. There’s a new Gadget::isEnabled() method that will check that a gadget is enabled by recursing through its ancestors. I’ve replaced the majority of _flags.enabled checks (in Gadget::click(), for example) with calls to this function instead.
The closeChild() and shelveChild() methods weren’t reassigning focus correctly if the child being closed was the only child. This should now be sorted.
It is possible that the changes will introduce bugs, so if you spot anything strange happening when hiding gadgets let me know.