Overview
Control nodes are the foundation of Godot’s UI system. All UI elements inherit from theControl base class, which provides positioning, sizing, input handling, and theming capabilities.
Control nodes inherit from
CanvasItem, which means they share properties like z_index and visible with other 2D nodes.The Control Base Class
TheControl class provides the fundamental building blocks for UI:
- Bounding rectangle that defines its extents
- Anchor position relative to parent control or viewport
- Offsets relative to the anchor
- Automatic layout updates when node, parents, or screen size change
Positioning with Anchors and Margins
Anchors allow UI elements to adapt to different screen sizes. Each side of a Control has an anchor value (0.0 to 1.0) that determines its position relative to the parent:Common Layout Presets
| Preset | Description |
|---|---|
PRESET_TOP_LEFT | Anchored to top-left corner |
PRESET_CENTER | Centered in parent |
PRESET_FULL_RECT | Fills entire parent rectangle |
PRESET_BOTTOM_RIGHT | Anchored to bottom-right corner |
Common Control Nodes
Button
A themed button that can contain text and an icon:text- The button’s display texticon- Optional icon textureflat- Remove button decorationalignment- Text alignment (left, center, right)
Label
Displays plain text with horizontal and vertical alignment:text- Text to displayhorizontal_alignment- Left, center, right, or fillvertical_alignment- Top, center, bottom, or fillautowrap_mode- Enable text wrappingclip_text- Clip text outside bounding box
LineEdit
An input field for single-line text editing:text- Current text valueplaceholder_text- Hint text when emptysecret- Hide characters (for passwords)max_length- Maximum character limiteditable- Enable/disable editing
text_changed- Emitted when text changestext_submitted- Emitted on Enter key pressediting_toggled- Emitted when entering/exiting edit mode
Minimum Size and Layout
Controls can define a minimum size to ensure proper display:_get_minimum_size() to calculate minimum size dynamically.
See Also
Containers
Learn about automatic layout with container nodes
Themes
Customize the appearance of UI elements
Input Handling
Handle mouse, touch, and keyboard input