Custom container that alternates row alignment?

Godot Version 4.8

Question

I want to create a container that sorts it’s children left to right on the first row, the right to left on the next row, and so on. In the end I want this container to sort itself dynamically so I can drop something in the middle, the items after it all shift over to make room.

I spent a few hours trying to figure out for-loops and math stuff and it was a lot of fun but now I must recognize that I simply don’t have the time to reinvent the wheel lol

I know I can probably find an engine agnostic answer elsewhere but I would really like a simple Godot-specific one! The next thing I’m going to try is having multiple HboxContainers inside a VBoxContainer and figuring out how to automatically pass the children down as they are added.

Has anyone made something similar before? How would you go about doing it?

What do you mean by “sort”?

What exactly do you need this for?

I guess the proper word is ‘align’

its purely for visual effect

You can achieve that with few containers but it might require some code

You need two horizontal containers, and probably VBox if you want grid-like allignment

image
Then you have to make code that will be used to place stuff inside these, of course it depends entirely but if you want let’s say max limit in each then you just do:

func add(node):
  if frame1.get_children().size() > 5:
    frame2.add_child(node)
  else:
    frame1.add_child(node)

you can change this function later to support more or really anything, also you must set your horizontal frame alignment to begin or end depending on which side you want your nodes to be positioned