However, the top frame and inner frame elements still exist. And if the button flow is now empty, this odd artifact remains on the screen. Deleting these frames is possible, and I have implemented some logic to do that (shown below). But since mod_gui frames are a shared space used by multiple mods, it would be better if this logic were contained in mod_gui itself, rather than relying on every mod to reimplement this logic. (The shared nature of mod_gui has already caused issues like Removing a mod can invalidate buttons from other mods in mod_gui flow.)
Here is the code that I recently implemented in a mod:
Code: Select all
-- Clean up mod_gui, if there are no other buttons left
-- Maybe we should check parent.get_mod() first, but
-- ownership of mod_gui is not clear in the first place.
local button_flow = mod_gui.get_button_flow(player)
if #button_flow.children == 0 then
local parent = button_flow.parent
if #parent.children == 1 then
parent.destroy()
end
end
