It would be useful if LuaGuiElement allowed creating multiple child elements with the same name.
This would be useful in tables, where (for example) two columns are reserved for buttons. All buttons in the same column could have the same name. To differentiate multiple buttons with the same name, LuaGuiElement.index could be used.
LuaGuiElement[element_name] could still work the same way as it does now: instead, now it would return the first child element with matching name instead.
Allow multiple LuaGuiElement in the same parent with duplicate names
-
- Long Handed Inserter
- Posts: 68
- Joined: Thu Jan 15, 2015 2:20 pm
- Contact:
Re: Allow multiple LuaGuiElement in the same parent with duplicate names
So why use the name at all?
-
- Long Handed Inserter
- Posts: 68
- Joined: Thu Jan 15, 2015 2:20 pm
- Contact:
Re: Allow multiple LuaGuiElement in the same parent with duplicate names
I've written a sizable widget framework that introduces a concept of a "Widget". Multiple factorio elements can be bound to a single widget. All events from bound elements are delivered to a corresponding widget. Within each widget I use LuaGuiElement.name to differentiate between different event sources. Because each table row is logically contained, I put each row into a separate widget.
I could store indices of LuaGuiElement in each row for separate columns and match against those in event handler, but that's not as elegant way to do things.
Since unique name restriction feels rather arbitrary, I feel that the better solution would be to lift that.
As to not break any existing designs that rely on unique names, LuaGuiElement.set_name_forced(id, new_name) or similar could be used to override the name while bypassing the unique name restriction.
I could store indices of LuaGuiElement in each row for separate columns and match against those in event handler, but that's not as elegant way to do things.
Since unique name restriction feels rather arbitrary, I feel that the better solution would be to lift that.
As to not break any existing designs that rely on unique names, LuaGuiElement.set_name_forced(id, new_name) or similar could be used to override the name while bypassing the unique name restriction.
Re: Allow multiple LuaGuiElement in the same parent with duplicate names
I really don't see the point, if you are sorting by widget name, to send the event somewhere, but you end up matching against index anyway.
In this case, you can just match against the ID directly, since you must be storing it somewhere anyway,
or why not add an index to the name, and then you can do a partial match against name, then retrieve the index from the name
Making names non-unique just isn't something worth looking into, it will no doubt end up causing more problems than we can anticipate
In this case, you can just match against the ID directly, since you must be storing it somewhere anyway,
or why not add an index to the name, and then you can do a partial match against name, then retrieve the index from the name
Making names non-unique just isn't something worth looking into, it will no doubt end up causing more problems than we can anticipate
-
- Long Handed Inserter
- Posts: 68
- Joined: Thu Jan 15, 2015 2:20 pm
- Contact:
Re: Allow multiple LuaGuiElement in the same parent with duplicate names
Fair enough.
I was a bit optimistic that the change would be super easy to implement, but it's hard to estimate it without knowing how stuff is done on Factorio side. In the end, I've implemented my own concept of element name and achieved the behavior I wanted.
I appreciate you taking time to respond to this.
I was a bit optimistic that the change would be super easy to implement, but it's hard to estimate it without knowing how stuff is done on Factorio side. In the end, I've implemented my own concept of element name and achieved the behavior I wanted.
I appreciate you taking time to respond to this.