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. I wrote a script to fix this, but I had another problem.
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. 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.
if node.get_class() == "HBoxContainer":
for i in get_children():
if i.get_index() > 5:
node.get_node("Margin").margin_top = (
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?