Please! If you have something that explains not just the purpose of each container, but rather overall logic of what stretches where, and how children treated exactly! Give me a link, be so kind! I feel I am going crazy with this stuff.
I am trying to do a seemingly simple thing: unit's UI. A square. Margins inside. Progress bar at the top (max width). Progress bar at the bottom (max width). And name label in the middle.
When I add ProgressBars as children to Control class node, it all works as intended.
I do it like this, look:
func _update_abilities() -> void:
abilityList.clear()
for child in get_children():
if child is Ability:
abilityList.append(child)
if not abilityList.is_empty():
abilityProgress = abilityProgressRes.instantiate()
abilityProgress.set_anchors_preset(Control.PRESET_BOTTOM_WIDE)
abilityProgress.set_visible(true)
ui_layout.add_child(abilityProgress)
func _update_unit_name() -> void:
name_label = nameLabelRes.instantiate()
name_label.set_text(unit_name)
name_label.set_anchors_preset(Control.PRESET_CENTER)
ui_layout.add_child(name_label)
# TEMP (while Visual is just Polygon)
func _set_ui_size() -> void:
var points = Utils.rect2_from_packedvector2array(visual_model.polygon)
ui_layout.set_position(points.position)
ui_layout.set_size(points.size)
But when I add MarginContainer between Control and everything else, it all goes crazy! Name stays in the middle. Both progressbars go to the top, regardless of which anchor_preset I use on them; even if I set them to PRESET_CENTER. Why???...
Of course I could just make a 'margin' by changing Control node position and size by a certain 3px Vector2 (and I will do it)... But it drives me mad that I can't understand what's going on.