This lets GUI scripts create and remove GUI Objects dynamically.does a few things:
It leverages [[ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | Template Literals ]] and D2768.1. Introduce a new XML tag `component` that uses JS to generate its own XML, and creates a corresponding instance of the JS object.
1. `Engine.GetGuiObject` returns the JS component for components instead of a 'fake' C++ object, making them effectively equivalent to the XML node.
1. JS Components proxy to the C++ so things still work
1. Objects can add children at runtime by using `appendChild` and putting XML in there, either an object or a component.
1. Rewrite the developer overlay as a test bed & example of this feature.
The design goals are:
- Reducing the barrier between JS and C++ Objects, making it possible to create generic JS components that enhance raw C++ functionality (or even components entirely out of JS).
- Making it easier to develop for the GUI, allowing more dynamic setups.
The Dev overlay was chosen to test because it fits an arbitrary number of commands, with somewhat arbitrary capabilities that don't all neatly fix a checkbox.
----
Known issues:
- The c++ code needs a lot of work
- appendChild taking XML is kinda dumb. It would be a better API to take a class name and a dict of attributes directly (or components at least), since that would allow passing real JS stuff such as lambdas.
- Cannot define sub-XML for a component from XML (has to be done in the JS of the component) which is a bit limiting.
- Probably want increased communication to the JS object to hook into more stuff.
----
Other considerations:
- This moves us towards needing fewer GUI pages, for sure.
- This moves us towards looking a lot more like the DOM.
- This makes it particularly visible that having no mechanism to include JS scripts is kind of annoying.
----
My simple GUI mod works here but I haven't actually checked for all edge cases, and there's probably an opportunity to do more before merging thisight embark / make irrelevant:
- #5405
- #5369
- #5387
...