I’m exploring approaches to handling GUI layout_changed messages.
It would be useful if I could store some GUI state just beforehand, to reapply after the layout changes.
One old thread suggests listening for WINDOW_EVENT_RESIZE. That works, but suffers from the problem of only allowing one listener, whereas we have multiple GUIs. The approach of having one central listener that invokes other listeners doesn’t work, because the calling scope is wrong, and GUI function calls fail with error Node used in the wrong scene
Any suggestions? Are there some C API functions I could use in a native extension to query GUI state without being in the correct scope?
I tried that, but the message arrives after the layout_changed message, so it’s too late to store any GUI state.
Dynamically created nodes, text, spine animations. The most useful attribute would simply be the enabled state of a node, which would allow state to be deduced and I could re-run existing state-based setup functions.
Have been experimenting, one option is to disable automatic GUI layout selection, and then I can respond to window messages manually - saving GUI state before changing layout.
It’s “all or nothing” - it requires some work in every GUI script, even ones that are currently working perfectly:
Modify init() to set an initial layout depending on window size (and do nothing else). It’s necessary to do this with a 0-frame timer as gui.set_layout() can’t be called directly from init().
Do remaining initialisation when the first layout is set
Register for window events via a central lua module
Respond to window size changes to determine if the layout needs to change