Add GUI elements in the middle of a parent

Post Reply
User avatar
Raiguard
Filter Inserter
Filter Inserter
Posts: 323
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Add GUI elements in the middle of a parent

Post by Raiguard »

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!
Don't forget, you're here forever.

User avatar
Therenas
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Add GUI elements in the middle of a parent

Post by Therenas »

Now this whole request does seem a bit unlikely to happen, but if it did, it would be cool if we could replace elements by index too. I can see this being useful for tables especially.

Qon
Smart Inserter
Smart Inserter
Posts: 1630
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Add GUI elements in the middle of a parent

Post by Qon »

This is the most obvious weirdly missing thing when I started doing mods with GUI. You can abuse flow elements to sort of get insertion, but then you need to make ugly hacks that make the element tree a big workaround that makes every insertion operation add even more elements (for arbitrary insertions). That will just tank performance eventually and make the GUI much more complicated to develop. +1

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5074
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Add GUI elements in the middle of a parent

Post by eradicator »

Raiguard wrote:
Sat Sep 26, 2020 4:58 am
I can guarantee that I'm not the first one to ask for this,
Weird, i thought i requested moving of LuaGuiElement years ago, but i can't find any old threads about it.
+0.5 because creation without moving is insufficient. But if either should happen the other is probably trivial to implement anyway.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Therenas
Fast Inserter
Fast Inserter
Posts: 204
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Add GUI elements in the middle of a parent

Post by Therenas »

Pretty sure this was implemented with 1.1

Bilka
Factorio Staff
Factorio Staff
Posts: 2784
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Add GUI elements in the middle of a parent

Post by Bilka »

Yep, just to make this clear for future readers: the index property in LuaGuiElement::add that was added in 1.1 allows you to choose where your new element is inserted.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”