How to have dynamic spacing of children in any FlowContainer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By UkdPeter

On a project I was working on recently, I was using the HFlowContainer node (introduced in Godot 3.5) to order nodes in a flow layout. The container worked well with nodes of the same size but the problem came when trying to add nodes of different sizes. I expected the nodes to be added with their original sizes, but adding a larger-sized node into the container made all the nodes the size of the former.All child nodes take largest child node I wrote a script to fix this, but I had another problem.

    func set_dimensions():
        max_height = DIMENSION.HEIGHT if (
	        title.text.empty() and note.text.empty()

        ) else (

	        max(DIMENSION.HEIGHT,
		        note.get_line_height() * note.get_line_count() +
		        title.get_line_height() * title.get_line_count() +
		        SPACING
	        )
        )
        max_width = DIMENSION.WIDTH
        rect_min_size = Vector2(DIMENSION.WIDTH,DIMENSION.HEIGHT)
        var size := Vector2(
	        clamp(rect_size.x, rect_min_size.x, max_width),
	        clamp(rect_size.y, rect_min_size.y, max_height)
	        )
        _set_size(size)

When I added more children to the HFlowContainer node, the nodes larger in size overlapped with the node one line below it.The overlap problem I tried fixing it by adjusting the area of the nodes that were added. The added nodes had a child MarginContainer node with name ‘Margin’ and I was using the margins of this node to adjust the area.

    func _on_Holder_child_entered_tree(node):
        if node.get_class() == "HBoxContainer":
	        yield(node,"ready")
	        for i in get_children():
		        if i.get_index() > 5:
			        yield(node.get_node("Margin"),"ready")
			        if node.get_rect().intersects(i.get_rect()):
				        yield(node.get_node("Margin"),"ready")
				        node.get_node("Margin").margin_top = (
					        (
						        int(
							        ((node.get_rect().clip(i.get_rect())).size.y) + 
							        custom_vsep
						        )
					        )
				        )

The nodes still overlapped each other. I was wondering if there was a fix for this, or a better and more efficient solution to this problem?
Thanks.