[Kinda added with swap_children] Modding - order property in LuaGuiElement

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
snouz
Inserter
Inserter
Posts: 27
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

[Kinda added with swap_children] Modding - order property in LuaGuiElement

Post by snouz »

TL;DR
Adding an "order" property to LuaGuiElement, to be able to sort (e.g.) buttons
What ?
An "order" property would define the display order of LuaGuiElement like buttons, and work just like the recipe's order property.

Image
Why ?
Currently, GuiElements are displayed by order of creation and the only way to re-order the buttons is destroying and re-creating them, which can bring a number of problems (and sometimes not work). The index property is read-only.
In my mod, I'm unifying top-left mod buttons. One thing that could make it better: being able to sort them by theme, importance etc.
Last edited by snouz on Sat Nov 06, 2021 11:13 pm, edited 1 time in total.
Graphically contributed to : Bio Industries (soon) | Warehousing | MFerrari's mods | Brevven's mods | Bob Artisanal Reskins | Mining Drones | Teleporters | Emoji signals

PFQNiet
Filter Inserter
Filter Inserter
Posts: 257
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by PFQNiet »

Potential duplicate: viewtopic.php?f=28&t=99233

curiosity
Fast Inserter
Fast Inserter
Posts: 174
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by curiosity »

PFQNiet wrote:
Sun Sep 19, 2021 4:42 pm
Potential duplicate: viewtopic.php?f=28&t=99233
Less a duplicate and more an elaboration. They want the order property to be writable specifically, so that rearranging elements is as easy as changing their order.

edit: Personally, I would love to see a way to rearrange elements.
Last edited by curiosity on Mon Sep 20, 2021 1:01 am, edited 1 time in total.

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

Re: Modding - order property in LuaGuiElement

Post by eradicator »

snouz wrote:
Sun Sep 19, 2021 1:37 pm
GuiElements are displayed by order of creation
Related: 89834

LuaGuiElement.add{index=} was added to allow out-of-order creation of elements. Allows limited re-ordering by destroy/recreating only some elements instead of all. I suspect that "write support for index of existing element" is much more complex to implmement than it sounds or they'd have added it long ago. And without writable index there can't be writable order.
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.

curiosity
Fast Inserter
Fast Inserter
Posts: 174
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by curiosity »

eradicator wrote:
Mon Sep 20, 2021 12:26 am
I suspect that "write support for index of existing element" is much more complex to implmement than it sounds or they'd have added it long ago. And without writable index there can't be writable order.
I struggle to imagine what may let you add a new element at a position, but not move an existing one there. More likely that GUI is just unpopular with the devs.

User avatar
snouz
Inserter
Inserter
Posts: 27
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by snouz »

Making index RW would work (index doesn't need to be sequential apparently, according to my tests) but it needs to be unique, so there would be conflict if 2 mods used the same index, or one already sequentially attributed.
But if it's a separate property (order) like recipes and items, it eliminates that problem and allows for button categories, like "t[train]-tsm", "a[calculator]" etc.
Graphically contributed to : Bio Industries (soon) | Warehousing | MFerrari's mods | Brevven's mods | Bob Artisanal Reskins | Mining Drones | Teleporters | Emoji signals

luc
Fast Inserter
Fast Inserter
Posts: 218
Joined: Sun Jul 17, 2016 9:53 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by luc »

Congratulations on the 100'000th topic :)

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

Re: Modding - order property in LuaGuiElement

Post by Raiguard »

LuaGuiElement::swap_children() was added in today's release. It's not quite as good as just moving an element to a specified index, but you can accomplish that by creating a hidden element at the intended location, swapping it with your current element, then deleting the temp element. It will still be much faster than recreating the element from scratch in complex GUIs.
Don't forget, you're here forever.

mrvn
Smart Inserter
Smart Inserter
Posts: 5112
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Modding - order property in LuaGuiElement

Post by mrvn »

One word (or two?): Bubble-sort

User avatar
snouz
Inserter
Inserter
Posts: 27
Joined: Sun Jan 03, 2021 6:01 pm
Contact:

Re: Modding - order property in LuaGuiElement

Post by snouz »

I don't know if it's a result of this request, but thanks to the devs for adding that !
Graphically contributed to : Bio Industries (soon) | Warehousing | MFerrari's mods | Brevven's mods | Bob Artisanal Reskins | Mining Drones | Teleporters | Emoji signals

Post Reply

Return to “Modding interface requests”