Loading...
Loading...
Build Godot 4.x user interfaces with Control nodes: anchors and offsets for responsive layout, Container nodes (VBox/HBox/Grid/Margin) for automatic arrangement, Theme resources for consistent styling, and keyboard/gamepad focus navigation. Use when laying out a HUD, menu, or UI in a Godot project, working with Control/Container nodes, anchors, themes, or focus in a .tscn.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills godot-ui-controlControlContainerThemeControlNode2Dgodot-nodes-scenesgodot-animationcard-gamevisual-novelinput-systemsControlNode2DVBoxContainerHBoxContainerGridContainerMarginContainersize_flagsThemeThemepressedtoggledtext_submittedvalue_changedextends Control
func _ready() -> void:
# Stretch this panel to fill its parent (equivalent to the "Full Rect" preset).
anchors_preset = Control.PRESET_FULL_RECT
# Or set anchors manually: all four edges at the parent's far corners.
# anchor_left = 0; anchor_top = 0; anchor_right = 1; anchor_bottom = 1extends VBoxContainer # children stack vertically, auto-sized
func _ready() -> void:
for child in get_children():
if child is Button:
child.pressed.connect(_on_button_pressed.bind(child.name))
# Give the first button focus so a gamepad can navigate immediately.
if get_child_count() > 0:
(get_child(0) as Control).grab_focus()
func _on_button_pressed(which: StringName) -> void:
match which:
"PlayButton": get_tree().change_scene_to_file("res://game.tscn")
"QuitButton": get_tree().quit()# In a HBoxContainer: a label on the left, a spacer that eats remaining width.
func _ready() -> void:
$Label.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
$Spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL # grows to fillfunc _ready() -> void:
# Per-node overrides: use add_theme_* (type-specific setters).
$Title.add_theme_font_size_override("font_size", 32)
$Title.add_theme_color_override("font_color", Color.GOLD)
$Panel.add_theme_stylebox_override("panel", preload("res://ui/panel.stylebox.tres"))ContainerControlPanelContainerNode2DNode2DCanvasLayerControlgrab_focus()focus_modeFOCUS_NONEThemeadd_theme_*rect_*rect_sizerect_positionrect_min_sizesizepositioncustom_minimum_sizemouse_filterMOUSE_FILTER_IGNORECanvasLayerreferences/layout-and-theming.mdgame-ui-uxgodot-animationgodot-signals-groupsinput-systemscard-gamevisual-novel