Page 1 of 1
[Kinda added with swap_children] Modding - order property in LuaGuiElement
Posted: Sun Sep 19, 2021 1:37 pm
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.
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.
Re: Modding - order property in LuaGuiElement
Posted: Sun Sep 19, 2021 4:42 pm
by PFQNiet
Re: Modding - order property in LuaGuiElement
Posted: Sun Sep 19, 2021 11:00 pm
by curiosity
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.
Re: Modding - order property in LuaGuiElement
Posted: Mon Sep 20, 2021 12:26 am
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.
Re: Modding - order property in LuaGuiElement
Posted: Mon Sep 20, 2021 12:59 am
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.
Re: Modding - order property in LuaGuiElement
Posted: Mon Sep 20, 2021 1:11 pm
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.
Re: Modding - order property in LuaGuiElement
Posted: Thu Sep 23, 2021 11:00 pm
by luc
Congratulations on the 100'000th topic
Re: Modding - order property in LuaGuiElement
Posted: Fri Nov 05, 2021 3:19 pm
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.
Re: Modding - order property in LuaGuiElement
Posted: Fri Nov 05, 2021 3:39 pm
by mrvn
One word (or two?): Bubble-sort
Re: Modding - order property in LuaGuiElement
Posted: Sat Nov 06, 2021 11:12 pm
by snouz
I don't know if it's a result of this request, but thanks to the devs for adding that !