Centering items of a VBoxContainer vertically based on the center item in the container

Godot Version

4.3

Question

This might be a weird one, but I have a VBoxContainer with a bunch of controls in it.
For argument’s sake, let’s say each item in the container is simply a MarginContainer with some padding, containing a LineEdit.

This VBoxContainer is made in a way, where it will always have an odd number of items in it, meaning, the items count will be 2*n+1, where there are n items at the top and bottom, and a center item.

What I want, is for the items to always be centered in a way, where the middle item doesn’t visibly move.

Now, this already works in the scenario I proposed above, where all the items in the VBoxContainer are essentially the same height. However, there are multiple item types that can be shown at the same time, for instance, say one with a MarginContainer containing a TextEdit with a larger given height, along with the line edit one mentioned above. This will shift the entire interface and throw the middle item off the center of the container visually.

I was wondering if there is some way, which I doubt, because this is a very niche scenario I ended up with, to visually make it so that the item in the middle, stays in the middle.

Could you reparent the VBoxContainer to a CenterContainer?

Unfortunately not, it’s the same as using a VBoxContainer, given the context

Could you post some screenshots of your Scene Tree and what the 2D view looks like?

You might try a VBox Container containing the central item and a VBoxContainer on top and bottom. If the actual central item changes, just swap it out.

If that doesn’t work, then try just placing the central item with a VBox container on top and bottom.