–1 vote

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 (

                note.get_line_height() * note.get_line_count() +
                title.get_line_height() * title.get_line_count() +
        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)

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":
            for i in get_children():
                if i.get_index() > 5:
                    if node.get_rect().intersects(i.get_rect()):
                        node.get_node("Margin").margin_top = (
                                    ((node.get_rect().clip(i.get_rect())).size.y) + 

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?

Godot version 3.5
in Engine by (13 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.