Allow multiple LuaGuiElement in the same parent with duplicate names

Things that we aren't going to implement
tux_mark_5
Long Handed Inserter
Long Handed Inserter
Posts: 68
Joined: Thu Jan 15, 2015 2:20 pm
Contact:

Allow multiple LuaGuiElement in the same parent with duplicate names

Post by tux_mark_5 »

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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5289
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Allow multiple LuaGuiElement in the same parent with duplicate names

Post by Klonan »

tux_mark_5 wrote: Wed May 01, 2019 7:29 pmLuaGuiElement.index could be used.
So why use the name at all?
tux_mark_5
Long Handed Inserter
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

Post by tux_mark_5 »

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.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5289
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Allow multiple LuaGuiElement in the same parent with duplicate names

Post by Klonan »

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
tux_mark_5
Long Handed Inserter
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

Post by tux_mark_5 »

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.
Post Reply

Return to “Won't implement”