sorting list of buttons

jackhenjackhen Posts: 26Member

I would like create a list of buttons that sorts itself based on a dynamic property. Is there an easy way to do this? how do I change a control nodes position in its parent?

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 3,103Admin

    Maybe use a VBoxContainer, HBoxContainer, or GridContainer node? Then the Control nodes that are children of that node will be sorted relative to their position in the scene tree relative to their parent.

  • jackhenjackhen Posts: 26Member

    @TwistedTwigleg said:
    Maybe use a VBoxContainer, HBoxContainer, or GridContainer node? Then the Control nodes that are children of that node will be sorted relative to their position in the scene tree relative to their parent.

    Im using a vbox container but my problem is i cant change a nodes position in its parent after its been added

  • TwistedTwiglegTwistedTwigleg Posts: 3,103Admin

    @jackhen said:

    @TwistedTwigleg said:
    Maybe use a VBoxContainer, HBoxContainer, or GridContainer node? Then the Control nodes that are children of that node will be sorted relative to their position in the scene tree relative to their parent.

    Im using a vbox container but my problem is i cant change a nodes position in its parent after its been added

    I think, though I have not tested, you can use the move_child function to move a child node's position in the scene tree relative to its parent. It should be something like this:

    # get the node's position relative to its parent
    var parent_index = get_position_in_parent()
    # move the node up one, relative to its parent
    get_parent().move_child(this, parent_index - 1)
    # move the node down one, relative to its parent
    get_parent().move_child(this, parent_index + 1)
    

    That should allow you to change the order of the nodes in the scene tree, which should in turn affect how they are positioned when they are automatically sorted and positioned by the VBoxContainer node.

  • stebulbastebulba Posts: 14Member

    My solution I did :

    • Make and sort your list with a array and dictionary.
    • Create the number of buttons that you have in your array or you want to show.
      name of your Bottom 01, 02 etc

    • Order your list as you want from a array and dictionary.

    • Don't change the position of any of your bottom, BUT change the text and properties of each bottom to be synchronise with the sort of your array and dictionary.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file