Add GUI elements in the middle of a parent
Posted: Sat Sep 26, 2020 4:58 am
THE REQUEST:
Add a method for adding a new child to a LuaGuiElement somewhere other than the end. Perhaps add an index key to the element's table that specifies the index in the children list it should be inserted?
THE REASON:
I can guarantee that I'm not the first one to ask for this, but I couldn't find any threads on it, so here I am. Right now, if you need to insert something entirely new in the middle of a GUI, the only way to go about that is to destroy everything after it and re-add them after adding your new bit. This imposes severe limitations on the optimizations we can do, and since creating GUIs is just about the slowest thing you can do in Factorio, it adds up quickly.
The motivation for my asking this now is that I am working on tooling to make GUIs easier. My current work is live in the form of flib's GUI module, but while that code makes creating a GUI a lot easier, updating an already created GUI is still very difficult. In fact, it gets even more difficult with this tooling, because most elements don't get names, so you are forced to either save every element to global or navigate by child index.
If we could insert GUI elements in the middle of other ones, instead of at the end, then I believe I could write sufficiently good tooling for both creating and updating GUIs with one structure. If not, then I'll have to again resort to destroying and recreating everything if something new needs to be added in the middle, absolutely slaughtering performance.
I will hope for the best!
Add a method for adding a new child to a LuaGuiElement somewhere other than the end. Perhaps add an index key to the element's table that specifies the index in the children list it should be inserted?
THE REASON:
I can guarantee that I'm not the first one to ask for this, but I couldn't find any threads on it, so here I am. Right now, if you need to insert something entirely new in the middle of a GUI, the only way to go about that is to destroy everything after it and re-add them after adding your new bit. This imposes severe limitations on the optimizations we can do, and since creating GUIs is just about the slowest thing you can do in Factorio, it adds up quickly.
The motivation for my asking this now is that I am working on tooling to make GUIs easier. My current work is live in the form of flib's GUI module, but while that code makes creating a GUI a lot easier, updating an already created GUI is still very difficult. In fact, it gets even more difficult with this tooling, because most elements don't get names, so you are forced to either save every element to global or navigate by child index.
If we could insert GUI elements in the middle of other ones, instead of at the end, then I believe I could write sufficiently good tooling for both creating and updating GUIs with one structure. If not, then I'll have to again resort to destroying and recreating everything if something new needs to be added in the middle, absolutely slaughtering performance.
I will hope for the best!