Control

Inherits: CanvasItem < Node < Object

Inherited By: TextureRect, ColorRect, Label, Tabs, GraphEdit, VideoPlayer, NinePatchRect, LineEdit, Container, TextEdit, BaseButton, Popup, Tree, Separator, ReferenceRect, Panel, TabContainer, Range, RichTextLabel, ItemList

Category: Core

Brief Description

All User Interface nodes inherit from Control. Features anchors and margins to adapt its position and size to its parent.

Member Functions

Vector2 _get_minimum_size ( ) virtual
void _gui_input ( InputEvent event ) virtual
void accept_event ( )
void add_color_override ( String name, Color color )
void add_constant_override ( String name, int constant )
void add_font_override ( String name, Font font )
void add_icon_override ( String name, Texture texture )
void add_shader_override ( String name, Shader shader )
void add_style_override ( String name, StyleBox stylebox )
bool can_drop_data ( Vector2 position, Variant data ) virtual
void drop_data ( Vector2 position, Variant data ) virtual
void force_drag ( Variant data, Control preview )
Vector2 get_begin ( ) const
Color get_color ( String name, String type=”” ) const
Vector2 get_combined_minimum_size ( ) const
int get_constant ( String name, String type=”” ) const
int get_cursor_shape ( Vector2 position=Vector2( 0, 0 ) ) const
int get_default_cursor_shape ( ) const
Object get_drag_data ( Vector2 position ) virtual
Vector2 get_end ( ) const
int get_focus_mode ( ) const
Control get_focus_owner ( ) const
Font get_font ( String name, String type=”” ) const
Vector2 get_global_position ( ) const
Rect2 get_global_rect ( ) const
Texture get_icon ( String name, String type=”” ) const
Vector2 get_minimum_size ( ) const
Vector2 get_parent_area_size ( ) const
Control get_parent_control ( ) const
Rect2 get_rect ( ) const
float get_rotation ( ) const
StyleBox get_stylebox ( String name, String type=”” ) const
String get_tooltip ( Vector2 at_position=Vector2( 0, 0 ) ) const
void grab_click_focus ( )
void grab_focus ( )
bool has_color ( String name, String type=”” ) const
bool has_color_override ( String name ) const
bool has_constant ( String name, String type=”” ) const
bool has_constant_override ( String name ) const
bool has_focus ( ) const
bool has_font ( String name, String type=”” ) const
bool has_font_override ( String name ) const
bool has_icon ( String name, String type=”” ) const
bool has_icon_override ( String name ) const
bool has_point ( Vector2 point ) virtual
bool has_stylebox ( String name, String type=”” ) const
bool has_stylebox_override ( String name ) const
void minimum_size_changed ( )
void release_focus ( )
void set_anchor ( int margin, float anchor, bool keep_margin=false, bool push_opposite_anchor=true )
void set_anchor_and_margin ( int margin, float anchor, float offset, bool push_opposite_anchor=false )
void set_anchors_and_margins_preset ( int preset, int resize_mode=0, int margin=0 )
void set_anchors_preset ( int preset, bool keep_margin=false )
void set_begin ( Vector2 position )
void set_default_cursor_shape ( int shape )
void set_drag_forwarding ( Control target )
void set_drag_preview ( Control control )
void set_end ( Vector2 position )
void set_focus_mode ( int mode )
void set_global_position ( Vector2 position )
void set_margins_preset ( int preset, int resize_mode=0, int margin=0 )
void set_rotation ( float radians )
void show_modal ( bool exclusive=false )
void warp_mouse ( Vector2 to_position )

Signals

  • focus_entered ( )

Emitted when the node gains keyboard focus.

  • focus_exited ( )

Emitted when the node loses keyboard focus.

Emitted when the node receives an InputEvent.

  • minimum_size_changed ( )

Emitted when the node’s minimum size changes.

  • modal_closed ( )

Emitted when a modal Control is closed. See show_modal.

  • mouse_entered ( )

Emitted when the mouse enters the control’s Rect area.

  • mouse_exited ( )

Emitted when the mouse leaves the control’s Rect area.

  • resized ( )

Emitted when the control changes size.

  • size_flags_changed ( )

Emitted when one of the size flags changes. See size_flags_horizontal and size_flags_vertical.

Member Variables

  • float anchor_bottom - Anchors the bottom edge of the node to the origin, the center, or the end of its parent container. It changes how the bottom margin updates when the node moves or changes size. Use one of the ANCHOR\_\* constants. Default value: ANCHOR_BEGIN.
  • float anchor_left - Anchors the left edge of the node to the origin, the center or the end of its parent container. It changes how the left margin updates when the node moves or changes size. Use one of the ANCHOR\_\* constants. Default value: ANCHOR_BEGIN.
  • float anchor_right - Anchors the right edge of the node to the origin, the center or the end of its parent container. It changes how the right margin updates when the node moves or changes size. Use one of the ANCHOR\_\* constants. Default value: ANCHOR_BEGIN.
  • float anchor_top - Anchors the top edge of the node to the origin, the center or the end of its parent container. It changes how the top margin updates when the node moves or changes size. Use one of the ANCHOR\_\* constants. Default value: ANCHOR_BEGIN.
  • NodePath focus_neighbour_bottom - Tells Godot which node it should give keyboard focus to if the user presses Tab, the down arrow on the keyboard, or down on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

If the user presses Tab, Godot will give focus to the closest node to the right first, then to the bottom. If the user presses Shift+Tab, Godot will look to the left of the node, then above it.

  • NodePath focus_neighbour_left - Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab, the left arrow on the keyboard or left on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the left of this one.
  • NodePath focus_neighbour_right - Tells Godot which node it should give keyboard focus to if the user presses Tab, the right arrow on the keyboard or right on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.
  • NodePath focus_neighbour_top - Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab, the top arrow on the keyboard or top on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.
  • NodePath focus_next
  • NodePath focus_previous
  • int grow_horizontal
  • int grow_vertical
  • String hint_tooltip - Changes the tooltip text. The tooltip appears when the user’s mouse cursor stays idle over this control for a few moments.
  • float margin_bottom - Distance between the node’s bottom edge and its parent container, based on anchor_bottom.

Margins are often controlled by one or multiple parent Container nodes. Margins update automatically when you move or resize the node.

  • float margin_left - Distance between the node’s left edge and its parent container, based on anchor_left.
  • float margin_right - Distance between the node’s right edge and its parent container, based on anchor_right.
  • float margin_top - Distance between the node’s top edge and its parent container, based on anchor_top.
  • int mouse_filter
  • bool rect_clip_content
  • Vector2 rect_min_size - The minimum size of the node’s bounding rectangle. If you set it to a value greater than (0, 0), the node’s bounding rectangle will always have at least this size, even if its content is smaller. If it’s set to (0, 0), the node sizes automatically to fit its content, be it a texture or child nodes.
  • Vector2 rect_pivot_offset - By default, the node’s pivot is its top-left corner. When you change its rect_scale, it will scale around this pivot. Set this property to rect_size / 2 to center the pivot in the node’s rectangle.
  • Vector2 rect_position - The node’s position, relative to its parent. It corresponds to the rectangle’s top-left corner. The property is not affected by rect_pivot_offset.
  • float rect_rotation - The node’s rotation around its pivot, in degrees. See rect_pivot_offset to change the pivot’s position.
  • Vector2 rect_scale - The node’s scale, relative to its rect_size. Change this property to scale the node around its rect_pivot_offset.
  • Vector2 rect_size - The size of the node’s bounding rectangle, in pixels. Container nodes update this property automatically.
  • int size_flags_horizontal - Tells the parent Container nodes how they should resize and place the node on the X axis. Use one of the SIZE\_\* constants to change the flags. See the constants to learn what each does.
  • float size_flags_stretch_ratio - If the node and at least one of its neighbours uses the SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.
  • int size_flags_vertical - Tells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the SIZE\_\* constants to change the flags. See the constants to learn what each does.
  • Theme theme - Changing this property replaces the current Theme resource this node and all its Control children use.

Numeric Constants

  • FOCUS_NONE = 0 — The node cannot grab focus. Use with set_focus_mode.
  • FOCUS_CLICK = 1 — The node can only grab focus on mouse clicks. Use with set_focus_mode.
  • FOCUS_ALL = 2 — The node can grab focus on mouse click or using the arrows and the Tab keys on the keyboard. Use with set_focus_mode.
  • NOTIFICATION_RESIZED = 40 — Sent when the node changes size. Use rect_size to get the new size.
  • NOTIFICATION_MOUSE_ENTER = 41 — Sent when the mouse pointer enters the node’s Rect area.
  • NOTIFICATION_MOUSE_EXIT = 42 — Sent when the mouse pointer exits the node’s Rect area.
  • NOTIFICATION_FOCUS_ENTER = 43 — Sent when the node grabs focus.
  • NOTIFICATION_FOCUS_EXIT = 44 — Sent when the node loses focus.
  • NOTIFICATION_THEME_CHANGED = 45 — Sent when the node’s theme changes, right before Godot redraws the Control. Happens when you call one of the add\_\*_override
  • NOTIFICATION_MODAL_CLOSE = 46 — Sent when an open modal dialog closes. See show_modal.
  • CURSOR_ARROW = 0 — Show the system’s arrow mouse cursor when the user hovers the node. Use with set_default_cursor_shape.
  • CURSOR_IBEAM = 1 — Show the system’s I-beam mouse cursor when the user hovers the node. The I-beam pointer has a shape similar to “I”. It tells the user they can highlight or insert text.
  • CURSOR_POINTING_HAND = 2 — Show the system’s pointing hand mouse cursor when the user hovers the node.
  • CURSOR_CROSS = 3 — Show the system’s cross mouse cursor when the user hovers the node.
  • CURSOR_WAIT = 4 — Show the system’s wait mouse cursor, often an hourglass, when the user hovers the node.
  • CURSOR_BUSY = 5 — Show the system’s busy mouse cursor when the user hovers the node. Often an hourglass.
  • CURSOR_DRAG = 6 — Show the system’s drag mouse cursor, often a closed fist or a cross symbol, when the user hovers the node. It tells the user they’re currently dragging an item, like a node in the Scene dock.
  • CURSOR_CAN_DROP = 7 — Show the system’s drop mouse cursor when the user hovers the node. It can be an open hand. It tells the user they can drop an item they’re currently grabbing, like a node in the Scene dock.
  • CURSOR_FORBIDDEN = 8 — Show the system’s forbidden mouse cursor when the user hovers the node. Often a crossed circle.
  • CURSOR_VSIZE = 9 — Show the system’s vertical resize mouse cursor when the user hovers the node. A double headed vertical arrow. It tells the user they can resize the window or the panel vertically.
  • CURSOR_HSIZE = 10 — Show the system’s horizontal resize mouse cursor when the user hovers the node. A double headed horizontal arrow. It tells the user they can resize the window or the panel horizontally.
  • CURSOR_BDIAGSIZE = 11 — Show the system’s window resize mouse cursor when the user hovers the node. The cursor is a double headed arrow that goes from the bottom left to the top right. It tells the user they can resize the window or the panel both horizontally and vertically.
  • CURSOR_FDIAGSIZE = 12 — Show the system’s window resize mouse cursor when the user hovers the node. The cursor is a double headed arrow that goes from the top left to the bottom right, the opposite of CURSOR_BDIAGSIZE. It tells the user they can resize the window or the panel both horizontally and vertically.
  • CURSOR_MOVE = 13 — Show the system’s move mouse cursor when the user hovers the node. It shows 2 double-headed arrows at a 90 degree angle. It tells the user they can move a UI element freely.
  • CURSOR_VSPLIT = 14 — Show the system’s vertical split mouse cursor when the user hovers the node. On Windows, it’s the same as CURSOR_VSIZE.
  • CURSOR_HSPLIT = 15 — Show the system’s horizontal split mouse cursor when the user hovers the node. On Windows, it’s the same as CURSOR_HSIZE.
  • CURSOR_HELP = 16 — Show the system’s help mouse cursor when the user hovers the node, a question mark.
  • PRESET_TOP_LEFT = 0 — Snap all 4 anchors to the top-left of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_TOP_RIGHT = 1 — Snap all 4 anchors to the top-right of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_BOTTOM_LEFT = 2 — Snap all 4 anchors to the bottom-left of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_BOTTOM_RIGHT = 3 — Snap all 4 anchors to the bottom-right of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_CENTER_LEFT = 4 — Snap all 4 anchors to the center of the left edge of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_CENTER_TOP = 5 — Snap all 4 anchors to the center of the top edge of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_CENTER_RIGHT = 6 — Snap all 4 anchors to the center of the right edge of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_CENTER_BOTTOM = 7 — Snap all 4 anchors to the center of the bottom edge of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_CENTER = 8 — Snap all 4 anchors to the center of the parent container’s bounds. Use with set_anchors_preset.
  • PRESET_LEFT_WIDE = 9 — Snap all 4 anchors to the left edge of the parent container. The left margin becomes relative to the left edge and the top margin relative to the top left corner of the node’s parent. Use with set_anchors_preset.
  • PRESET_TOP_WIDE = 10 — Snap all 4 anchors to the top edge of the parent container. The left margin becomes relative to the top left corner, the top margin relative to the top edge, and the right margin relative to the top right corner of the node’s parent. Use with set_anchors_preset.
  • PRESET_RIGHT_WIDE = 11 — Snap all 4 anchors to the right edge of the parent container. The right margin becomes relative to the right edge and the top margin relative to the top right corner of the node’s parent. Use with set_anchors_preset.
  • PRESET_BOTTOM_WIDE = 12 — Snap all 4 anchors to the bottom edge of the parent container. The left margin becomes relative to the bottom left corner, the bottom margin relative to the bottom edge, and the right margin relative to the bottom right corner of the node’s parent. Use with set_anchors_preset.
  • PRESET_VCENTER_WIDE = 13 — Snap all 4 anchors to a vertical line that cuts the parent container in half. Use with set_anchors_preset.
  • PRESET_HCENTER_WIDE = 14 — Snap all 4 anchors to a horizontal line that cuts the parent container in half. Use with set_anchors_preset.
  • PRESET_WIDE = 15 — Snap all 4 anchors to the respective corners of the parent container. Set all 4 margins to 0 after you applied this preset and the Control will fit its parent container. Use with set_anchors_preset.
  • PRESET_MODE_MINSIZE = 0
  • PRESET_MODE_KEEP_WIDTH = 1
  • PRESET_MODE_KEEP_HEIGHT = 2
  • PRESET_MODE_KEEP_SIZE = 3
  • SIZE_FILL = 1 — Tells the parent Container to expand the bounds of this node to fill all the available space without pushing any other node. Use with size_flags_horizontal and size_flags_vertical.
  • SIZE_EXPAND = 2 — Tells the parent Container to let this node take all the available space on the axis you flag. If multiple neighboring nodes are set to expand, they’ll share the space based on their stretch ratio. See size_flags_stretch_ratio. Use with size_flags_horizontal and size_flags_vertical.
  • SIZE_EXPAND_FILL = 3 — Sets the node’s size flags to both fill and expand. See the 2 constants above for more information.
  • SIZE_SHRINK_CENTER = 4 — Tells the parent Container to center the node in itself. It centers the Control based on its bounding box, so it doesn’t work with the fill or expand size flags. Use with size_flags_horizontal and size_flags_vertical.
  • SIZE_SHRINK_END = 8 — Tells the parent Container to align the node with its end, either the bottom or the right edge. It doesn’t work with the fill or expand size flags. Use with size_flags_horizontal and size_flags_vertical.
  • MOUSE_FILTER_STOP = 0
  • MOUSE_FILTER_PASS = 1
  • MOUSE_FILTER_IGNORE = 2
  • GROW_DIRECTION_BEGIN = 0
  • GROW_DIRECTION_END = 1
  • ANCHOR_BEGIN = 0 — Snaps one of the 4 anchor’s sides to the origin of the node’s Rect, in the top left. Use it with one of the anchor\_\* member variables, like anchor_left. To change all 4 anchors at once, use set_anchors_preset.
  • ANCHOR_END = 1 — Snaps one of the 4 anchor’s sides to the end of the node’s Rect, in the bottom right. Use it with one of the anchor\_\* member variables, like anchor_left. To change all 4 anchors at once, use set_anchors_preset.

Description

Base class for all User Interface or UI related nodes. Control features a bounding rectangle that defines its extents, an anchor position relative to its parent and margins that represent an offset to the anchor. The margins update automatically when the node, any of its parents, or the screen size change.

For more information on Godot’s UI system, anchors, margins, and containers, see the related tutorials in the manual. To build flexible UIs, you’ll need a mix of UI elements that inherit from Control and Container nodes.

User Interface nodes and input

Godot sends input events to the scene’s root node first, by calling Node._input. Node._input forwards the event down the node tree to the nodes under the mouse cursor, or on keyboard focus. To do so, it calls MainLoop._input_event. Call accept_event so no other node receives the event. Once you accepted an input, it becomes handled so Node._unhandled_input will not process it.

Only one Control node can be in keyboard focus. Only the node in focus will receive keyboard events. To get the foucs, call set_focus_mode. Control nodes lose focus when another node grabs it, or if you hide the node in focus.

Call set_ignore_mouse to tell a Control node to ignore mouse or touch events. You’ll need it if you place an icon on top of a button.

Theme resources change the Control’s appearance. If you change the Theme on a Control node, it affects all of its children. To override some of the theme’s parameters, call one of the add\_\*_override methods, like add_font_override. You can override the theme with the inspector.

Member Function Description

  • Vector2 _get_minimum_size ( ) virtual

Returns the minimum size this Control can shrink to. The node can never be smaller than this minimum size.

The node’s parent forwards input events to this method. Use it to process and accept inputs on UI elements. See accept_event.

Replaces Godot 2’s _input_event.

  • void accept_event ( )

Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to Node._unhandled_input or Node._unhandled_key_input.

Overrides the color in the theme resource the node uses.

  • void add_constant_override ( String name, int constant )

Overrides an integer constant in the Theme resource the node uses. If the constant is invalid, Godot clears the override. See Theme.INVALID_CONSTANT for more information.

  • void add_font_override ( String name, Font font )

Overrides the name font in the theme resource the node uses. If font is empty, Godot clears the override.

Overrides the name icon in the theme resource the node uses. If icon is empty, Godot clears the override.

Overrides the name shader in the theme resource the node uses. If shader is empty, Godot clears the override.

Overrides the name Stylebox in the theme resource the node uses. If stylebox is empty, Godot clears the override.

  • Vector2 get_combined_minimum_size ( ) const
  • int get_cursor_shape ( Vector2 position=Vector2( 0, 0 ) ) const

Returns the mouse cursor shape the control displays on mouse hover, one of the CURSOR\_\* constants.

  • int get_default_cursor_shape ( ) const

Returns the default cursor shape for this control. See enum CURSOR\_\* for the list of shapes.

Returns MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see set_margin).

  • int get_focus_mode ( ) const

Returns the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL) (see set_focus_mode).

  • Control get_focus_owner ( ) const

Return which control is owning the keyboard focus, or null if no one.

  • Vector2 get_global_position ( ) const

Returns the Control position, relative to the top-left corner of the parent Control and independent of the anchor mode.

  • Rect2 get_global_rect ( ) const

Return position and size of the Control, relative to the top-left corner of the window Control. This is a helper (see get_global_position, get_size).

  • Vector2 get_minimum_size ( ) const

Return the minimum size this Control can shrink to. A control will never be displayed or resized smaller than its minimum size.

  • Vector2 get_parent_area_size ( ) const
  • Control get_parent_control ( ) const
  • Rect2 get_rect ( ) const

Return position and size of the Control, relative to the top-left corner of the parent Control. This is a helper (see get_position, get_size).

  • float get_rotation ( ) const

Return the rotation (in radians)

  • String get_tooltip ( Vector2 at_position=Vector2( 0, 0 ) ) const

Return the tooltip, which will appear when the cursor is resting over this control.

  • void grab_click_focus ( )
  • void grab_focus ( )

Steal the focus from another control and become the focused control (see set_focus_mode).

  • bool has_constant_override ( String name ) const
  • bool has_focus ( ) const

Return whether the Control is the current focused control (see set_focus_mode).

  • bool has_stylebox_override ( String name ) const
  • void minimum_size_changed ( )
  • void release_focus ( )

Give up the focus, no other control will be able to receive keyboard input.

  • void set_anchor ( int margin, float anchor, bool keep_margin=false, bool push_opposite_anchor=true )
  • void set_anchor_and_margin ( int margin, float anchor, float offset, bool push_opposite_anchor=false )
  • void set_anchors_and_margins_preset ( int preset, int resize_mode=0, int margin=0 )
  • void set_anchors_preset ( int preset, bool keep_margin=false )
  • void set_begin ( Vector2 position )

Sets MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see set_margin).

  • void set_default_cursor_shape ( int shape )

Sets the default cursor shape for this control. See CURSOR\_\* for the list of available cursor shapes. Useful for Godot plugins and applications or games that use the system’s mouse cursors.

  • void set_drag_forwarding ( Control target )
  • void set_drag_preview ( Control control )
  • void set_end ( Vector2 position )

Sets MARGIN_RIGHT and MARGIN_BOTTOM at the same time. This is a helper (see set_margin).

  • void set_focus_mode ( int mode )

Set the focus access mode for the control (FOCUS_NONE, FOCUS_CLICK, FOCUS_ALL). Only one Control can be focused at the same time, and it will receive keyboard signals.

  • void set_global_position ( Vector2 position )

Move the Control to a new position, relative to the top-left corner of the window Control, and without changing current anchor mode. (see set_margin).

  • void set_margins_preset ( int preset, int resize_mode=0, int margin=0 )
  • void set_rotation ( float radians )

Set the rotation (in radians).

  • void show_modal ( bool exclusive=false )

Display a Control as modal. Control must be a subwindow. Modal controls capture the input signals until closed or the area outside them is accessed. When a modal control loses focus, or the ESC key is pressed, they automatically hide. Modal controls are used extensively for popup dialogs and menus.

  • void warp_mouse ( Vector2 to_position )