Table of Contents

Class Control

Base class for all GUI controls. Adapts its position and size based on its parent control.

Inheritance
Control
Derived

Remarks

Base class for all UI-related nodes. Control features a bounding rectangle that defines its extents, an anchor position relative to its parent control or the current viewport, and offsets relative to the anchor. The offsets update automatically when the node, any of its parents, or the screen size change.

For more information on Godot's UI system, anchors, offsets, 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.

Note: Since both Node2D and Control inherit from CanvasItem, they share several concepts from the class such as the z_index and visible properties.

User Interface nodes and input

Godot propagates input events via viewports. Each Viewport is responsible for propagating InputEvents to their child nodes. As the root is a Window, this already happens automatically for all UI elements in your game.

Input events are propagated through the SceneTree from the root node to all child nodes by calling Node._input. For UI elements specifically, it makes more sense to override the virtual method Control._gui_input, which filters out unrelated input events, such as by checking z-order, mouse_filter, focus, or if the event was inside of the control's bounding box.

Call accept_event so no other node receives the event. Once you accept an input, it becomes handled so Node._unhandled_input will not process it.

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

Sets mouse_filter to Control.MOUSE_FILTER_IGNORE 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. The theme of a Control node affects all of its direct and indirect children (as long as a chain of controls is uninterrupted). To override some of the theme items, call one of the add_theme_*_override methods, like Control.add_theme_font_override. You can also override theme items in the Inspector.

Note: Theme items are not Object properties. This means you can't access their values using Object.get and Object.set. Instead, use the get_theme_* and add_theme_*_override methods provided by this class.

See Also

Fields

NOTIFICATION_RESIZED

Sent when the node changes size. Use size to get the new size.

const NOTIFICATION_RESIZED = 40

NOTIFICATION_MOUSE_ENTER

Sent when the mouse cursor enters the control's (or any child control's) visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect which Control receives the notification.

See also NOTIFICATION_MOUSE_ENTER_SELF.

const NOTIFICATION_MOUSE_ENTER = 41

NOTIFICATION_MOUSE_EXIT

Sent when the mouse cursor leaves the control's (and all child control's) visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect which Control receives the notification.

See also NOTIFICATION_MOUSE_EXIT_SELF.

const NOTIFICATION_MOUSE_EXIT = 42

NOTIFICATION_MOUSE_ENTER_SELF

Sent when the mouse cursor enters the control's visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect which Control receives the notification.

See also NOTIFICATION_MOUSE_ENTER.

const NOTIFICATION_MOUSE_ENTER_SELF = 60

NOTIFICATION_MOUSE_EXIT_SELF

Sent when the mouse cursor leaves the control's visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect which Control receives the notification.

See also NOTIFICATION_MOUSE_EXIT.

const NOTIFICATION_MOUSE_EXIT_SELF = 61

NOTIFICATION_FOCUS_ENTER

Sent when the node grabs focus.

const NOTIFICATION_FOCUS_ENTER = 43

NOTIFICATION_FOCUS_EXIT

Sent when the node loses focus.

const NOTIFICATION_FOCUS_EXIT = 44

NOTIFICATION_THEME_CHANGED

Sent when the node needs to refresh its theme items. This happens in one of the following cases:

  • The theme property is changed on this node or any of its ancestors.

  • The theme_type_variation property is changed on this node.

  • One of the node's theme property overrides is changed.

  • The node enters the scene tree.

Note: As an optimization, this notification won't be sent from changes that occur while this node is outside of the scene tree. Instead, all of the theme item updates can be applied at once when the node enters the scene tree.

Note: This notification is received alongside NOTIFICATION_ENTER_TREE, so if you are instantiating a scene, the child nodes will not be initialized yet. You can use it to setup theming for this node, child nodes created from script, or if you want to access child nodes added in the editor, make sure the node is ready using is_node_ready.

func _notification(what):
    if what == NOTIFICATION_THEME_CHANGED:
        if not is_node_ready():
            await ready # Wait until ready signal.
        $Label.add_theme_color_override("font_color", Color.YELLOW)

const NOTIFICATION_THEME_CHANGED = 45

NOTIFICATION_SCROLL_BEGIN

Sent when this node is inside a ScrollContainer which has begun being scrolled when dragging the scrollable area with a touch event. This notification is not sent when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.

Note: This signal is only emitted on Android or iOS, or on desktop/web platforms when input_devices/pointing/emulate_touch_from_mouse is enabled.

const NOTIFICATION_SCROLL_BEGIN = 47

NOTIFICATION_SCROLL_END

Sent when this node is inside a ScrollContainer which has stopped being scrolled when dragging the scrollable area with a touch event. This notification is not sent when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.

Note: This signal is only emitted on Android or iOS, or on desktop/web platforms when input_devices/pointing/emulate_touch_from_mouse is enabled.

const NOTIFICATION_SCROLL_END = 48

NOTIFICATION_LAYOUT_DIRECTION_CHANGED

Sent when the control layout direction is changed from LTR or RTL or vice versa. This notification is propagated to child Control nodes as result of a change to layout_direction.

const NOTIFICATION_LAYOUT_DIRECTION_CHANGED = 49

Properties

anchor_bottom

Anchors the bottom edge of the node to the origin, the center, or the end of its parent control. It changes how the bottom offset updates when the node moves or changes size. You can use one of the Anchor constants for convenience.

var anchor_bottom : float = 0.0

Property Value

float

Remarks

anchor_left

Anchors the left edge of the node to the origin, the center or the end of its parent control. It changes how the left offset updates when the node moves or changes size. You can use one of the Anchor constants for convenience.

var anchor_left : float = 0.0

Property Value

float

Remarks

anchor_right

Anchors the right edge of the node to the origin, the center or the end of its parent control. It changes how the right offset updates when the node moves or changes size. You can use one of the Anchor constants for convenience.

var anchor_right : float = 0.0

Property Value

float

Remarks

anchor_top

Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top offset updates when the node moves or changes size. You can use one of the Anchor constants for convenience.

var anchor_top : float = 0.0

Property Value

float

Remarks

auto_translate

Toggles if any text should automatically change to its translated version depending on the current locale.

var auto_translate : bool

Property Value

bool

Remarks

  • void set_auto_translate(bool value)
  • bool is_auto_translating

clip_contents

Enables whether rendering of CanvasItem based children should be clipped to this control's rectangle. If true, parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input.

var clip_contents : bool = false

Property Value

bool

Remarks

  • void set_clip_contents(bool value)
  • bool is_clipping_contents

custom_minimum_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. Note that Control nodes have their internal minimum size returned by get_minimum_size. It depends on the control's contents, like text, textures, or style boxes. The actual minimum size is the maximum value of this property and the internal minimum size (see get_combined_minimum_size).

var custom_minimum_size : Vector2 = Vector2(0, 0)

Property Value

Vector2

Remarks

  • void set_custom_minimum_size(Vector2 value)
  • Vector2 get_custom_minimum_size

focus_mode

The focus access mode for the control (None, Click or All). Only one Control can be focused at the same time, and it will receive keyboard, gamepad, and mouse signals.

var focus_mode : int = 0

Property Value

int

Remarks

  • void set_focus_mode(int value)
  • int get_focus_mode

focus_neighbor_bottom

Tells Godot which node it should give focus to if the user presses the down arrow on the keyboard or down on a gamepad by default. You can change the key by editing the input/ui_down input action. 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.

var focus_neighbor_bottom : NodePath = NodePath("")

Property Value

NodePath

Remarks

focus_neighbor_left

Tells Godot which node it should give focus to if the user presses the left arrow on the keyboard or left on a gamepad by default. You can change the key by editing the input/ui_left input action. 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.

var focus_neighbor_left : NodePath = NodePath("")

Property Value

NodePath

Remarks

focus_neighbor_right

Tells Godot which node it should give focus to if the user presses the right arrow on the keyboard or right on a gamepad by default. You can change the key by editing the input/ui_right input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the right of this one.

var focus_neighbor_right : NodePath = NodePath("")

Property Value

NodePath

Remarks

focus_neighbor_top

Tells Godot which node it should give focus to if the user presses the top arrow on the keyboard or top on a gamepad by default. You can change the key by editing the input/ui_up input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the top of this one.

var focus_neighbor_top : NodePath = NodePath("")

Property Value

NodePath

Remarks

focus_next

Tells Godot which node it should give focus to if the user presses Tab on a keyboard by default. You can change the key by editing the input/ui_focus_next input action.

If this property is not set, Godot will select a "best guess" based on surrounding nodes in the scene tree.

var focus_next : NodePath = NodePath("")

Property Value

NodePath

Remarks

focus_previous

Tells Godot which node it should give focus to if the user presses Shift + Tab on a keyboard by default. You can change the key by editing the input/ui_focus_prev input action.

If this property is not set, Godot will select a "best guess" based on surrounding nodes in the scene tree.

var focus_previous : NodePath = NodePath("")

Property Value

NodePath

Remarks

global_position

The node's global position, relative to the world (usually to the CanvasLayer).

var global_position : Vector2

Property Value

Vector2

Remarks

grow_horizontal

Controls the direction on the horizontal axis in which the control should grow if its horizontal minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

var grow_horizontal : int = 1

Property Value

int

Remarks

  • void set_h_grow_direction(int value)
  • int get_h_grow_direction

grow_vertical

Controls the direction on the vertical axis in which the control should grow if its vertical minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.

var grow_vertical : int = 1

Property Value

int

Remarks

  • void set_v_grow_direction(int value)
  • int get_v_grow_direction

layout_direction

Controls layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew). See also is_layout_rtl.

var layout_direction : int = 0

Property Value

int

Remarks

  • void set_layout_direction(int value)
  • int get_layout_direction

localize_numeral_system

If true, automatically converts code line numbers, list indices, SpinBox and ProgressBar values from the Western Arabic (0..9) to the numeral systems used in current locale.

Note: Numbers within the text are not automatically converted, it can be done manually, using TextServer.format_number.

var localize_numeral_system : bool = true

Property Value

bool

Remarks

  • void set_localize_numeral_system(bool value)
  • bool is_localizing_numeral_system

mouse_default_cursor_shape

The default cursor shape for this control. Useful for Godot plugins and applications or games that use the system's mouse cursors.

Note: On Linux, shapes may vary depending on the cursor theme of the system.

var mouse_default_cursor_shape : int = 0

Property Value

int

Remarks

  • void set_default_cursor_shape(int value)
  • int get_default_cursor_shape

mouse_filter

Controls whether the control will be able to receive mouse button input events through Control._gui_input and how these events should be handled. Also controls whether the control can receive the mouse_entered, and mouse_exited signals. See the constants to learn what each does.

var mouse_filter : int = 0

Property Value

int

Remarks

  • void set_mouse_filter(int value)
  • int get_mouse_filter

mouse_force_pass_scroll_events

When enabled, scroll wheel events processed by Control._gui_input will be passed to the parent control even if mouse_filter is set to Control.MOUSE_FILTER_STOP.

You should disable it on the root of your UI if you do not want scroll events to go to the Node._unhandled_input processing.

Note: Because this property defaults to true, this allows nested scrollable containers to work out of the box.

var mouse_force_pass_scroll_events : bool = true

Property Value

bool

Remarks

  • void set_force_pass_scroll_events(bool value)
  • bool is_force_pass_scroll_events

offset_bottom

Distance between the node's bottom edge and its parent control, based on anchor_bottom.

Offsets are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Offsets update automatically when you move or resize the node.

var offset_bottom : float = 0.0

Property Value

float

Remarks

offset_left

Distance between the node's left edge and its parent control, based on anchor_left.

Offsets are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Offsets update automatically when you move or resize the node.

var offset_left : float = 0.0

Property Value

float

Remarks

offset_right

Distance between the node's right edge and its parent control, based on anchor_right.

Offsets are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Offsets update automatically when you move or resize the node.

var offset_right : float = 0.0

Property Value

float

Remarks

offset_top

Distance between the node's top edge and its parent control, based on anchor_top.

Offsets are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Offsets update automatically when you move or resize the node.

var offset_top : float = 0.0

Property Value

float

Remarks

pivot_offset

By default, the node's pivot is its top-left corner. When you change its rotation or scale, it will rotate or scale around this pivot. Set this property to size / 2 to pivot around the Control's center.

var pivot_offset : Vector2 = Vector2(0, 0)

Property Value

Vector2

Remarks

position

The node's position, relative to its containing node. It corresponds to the rectangle's top-left corner. The property is not affected by pivot_offset.

var position : Vector2 = Vector2(0, 0)

Property Value

Vector2

Remarks

rotation

The node's rotation around its pivot, in radians. See pivot_offset to change the pivot's position.

Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use rotation_degrees.

var rotation : float = 0.0

Property Value

float

Remarks

  • void set_rotation(float value)
  • float get_rotation

rotation_degrees

Helper property to access rotation in degrees instead of radians.

var rotation_degrees : float

Property Value

float

Remarks

  • void set_rotation_degrees(float value)
  • float get_rotation_degrees

scale

The node's scale, relative to its size. Change this property to scale the node around its pivot_offset. The Control's tooltip_text will also scale according to this value.

Note: This property is mainly intended to be used for animation purposes. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the documentation instead of scaling Controls individually.

Note: oversampling does not take Control scale into account. This means that scaling up/down will cause bitmap fonts and rasterized (non-MSDF) dynamic fonts to appear blurry or pixelated. To ensure text remains crisp regardless of scale, you can enable MSDF font rendering by enabling gui/theme/default_font_multichannel_signed_distance_field (applies to the default project font only), or enabling Multichannel Signed Distance Field in the import options of a DynamicFont for custom fonts. On system fonts, multichannel_signed_distance_field can be enabled in the inspector.

Note: If the Control node is a child of a Container node, the scale will be reset to Vector2(1, 1) when the scene is instantiated. To set the Control's scale when it's instantiated, wait for one frame using await get_tree().process_frame then set its scale property.

var scale : Vector2 = Vector2(1, 1)

Property Value

Vector2

Remarks

shortcut_context

The Node which must be a parent of the focused Control for the shortcut to be activated. If null, the shortcut can be activated when any control is focused (a global shortcut). This allows shortcuts to be accepted only when the user has a certain area of the GUI focused.

var shortcut_context : Node

Property Value

Node

Remarks

  • void set_shortcut_context(Node value)
  • Node get_shortcut_context

size

The size of the node's bounding rectangle, in the node's coordinate system. Container nodes update this property automatically.

var size : Vector2 = Vector2(0, 0)

Property Value

Vector2

Remarks

size_flags_horizontal

Tells the parent Container nodes how they should resize and place the node on the X axis. Use a combination of the SizeFlags constants to change the flags. See the constants to learn what each does.

var size_flags_horizontal : int = 1

Property Value

int

Remarks

  • void set_h_size_flags(int value)
  • int get_h_size_flags

size_flags_stretch_ratio

If the node and at least one of its neighbors uses the Control.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 neighbor a ratio of 1, this node will take two thirds of the available space.

var size_flags_stretch_ratio : float = 1.0

Property Value

float

Remarks

  • void set_stretch_ratio(float value)
  • float get_stretch_ratio

size_flags_vertical

Tells the parent Container nodes how they should resize and place the node on the Y axis. Use a combination of the SizeFlags constants to change the flags. See the constants to learn what each does.

var size_flags_vertical : int = 1

Property Value

int

Remarks

  • void set_v_size_flags(int value)
  • int get_v_size_flags

theme

The Theme resource this node and all its Control and Window children use. If a child node has its own Theme resource set, theme items are merged with child's definitions having higher priority.

Note: Window styles will have no effect unless the window is embedded.

var theme : Theme

Property Value

Theme

Remarks

theme_type_variation

The name of a theme type variation used by this Control to look up its own theme items. When empty, the class name of the node is used (e.g. Button for the Button control), as well as the class names of all parent classes (in order of inheritance).

When set, this property gives the highest priority to the type of the specified name. This type can in turn extend another type, forming a dependency chain. See Theme.set_type_variation. If the theme item cannot be found using this type or its base types, lookup falls back on the class names.

Note: To look up Control's own items use various get_theme_* methods without specifying theme_type.

Note: Theme items are looked for in the tree order, from branch to root, where each Control node is checked for its theme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.

var theme_type_variation : StringName = &""

Property Value

StringName

Remarks

tooltip_auto_translate_mode

Defines if tooltip text should automatically change to its translated version depending on the current locale. Uses the same auto translate mode as this control when set to Node.AUTO_TRANSLATE_MODE_INHERIT.

Note: Tooltips customized using Control._make_custom_tooltip do not use this auto translate mode automatically.

var tooltip_auto_translate_mode : int = 0

Property Value

int

Remarks

  • void set_tooltip_auto_translate_mode(int value)
  • int get_tooltip_auto_translate_mode

tooltip_text

The default tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that the mouse_filter property is not Control.MOUSE_FILTER_IGNORE. The time required for the tooltip to appear can be changed with the gui/timers/tooltip_delay_sec setting.

This string is the default return value of Control.get_tooltip. Override Control._get_tooltip to generate tooltip text dynamically. Override Control._make_custom_tooltip to customize the tooltip interface and behavior.

The tooltip popup will use either a default implementation, or a custom one that you can provide by overriding Control._make_custom_tooltip. The default tooltip includes a PopupPanel and Label whose theme properties can be customized using Theme methods with the "TooltipPanel" and "TooltipLabel" respectively. For example:

var style_box = StyleBoxFlat.new()
style_box.set_bg_color(Color(1, 1, 0))
style_box.set_border_width_all(2)
# We assume here that the `theme` property has been assigned a custom Theme beforehand.
theme.set_stylebox("panel", "TooltipPanel", style_box)
theme.set_color("font_color", "TooltipLabel", Color(0, 1, 1))

var tooltip_text : String = ""

Property Value

String

Remarks

  • void set_tooltip_text(String value)
  • String get_tooltip_text

Methods

_can_drop_data(Vector2, Variant)

Qualifiers: virtualconst

Godot calls this method to test if data from a control's Control._get_drag_data can be dropped at at_position. at_position is local to this control.

This method should only be used to test the data. Process the data in Control._drop_data.

func _can_drop_data(position, data):
    # Check position if it is relevant to you
    # Otherwise, just check data
    return typeof(data) == TYPE_DICTIONARY and data.has("expected")

bool _can_drop_data(Vector2 at_position, Variant data)

Parameters

at_position Vector2
data Variant

_drop_data(Vector2, Variant)

Qualifiers: virtual

Godot calls this method to pass you the data from a control's Control._get_drag_data result. Godot first calls Control._can_drop_data to test if data is allowed to drop at at_position where at_position is local to this control.

func _can_drop_data(position, data):
    return typeof(data) == TYPE_DICTIONARY and data.has("color")

func _drop_data(position, data):
    var color = data["color"]

void _drop_data(Vector2 at_position, Variant data)

Parameters

at_position Vector2
data Variant

_get_drag_data(Vector2)

Qualifiers: virtual

Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returns null if there is no data to drag. Controls that want to receive drop data should implement Control._can_drop_data and Control._drop_data. at_position is local to this control. Drag may be forced with Control.force_drag.

A preview that will follow the mouse that should represent the data can be set with Control.set_drag_preview. A good time to set the preview is in this method.

func _get_drag_data(position):
    var mydata = make_data() # This is your custom method generating the drag data.
    set_drag_preview(make_preview(mydata)) # This is your custom method generating the preview of the drag data.
    return mydata

Variant _get_drag_data(Vector2 at_position)

Parameters

at_position Vector2

_get_minimum_size

Qualifiers: virtualconst

Virtual method to be implemented by the user. Returns the minimum size for this control. Alternative to custom_minimum_size for controlling minimum size via code. The actual minimum size will be the max value of these two (in each axis separately).

If not overridden, defaults to ZERO.

Note: This method will not be called when the script is attached to a Control node that already overrides its minimum size (e.g. Label, Button, PanelContainer etc.). It can only be used with most basic GUI nodes, like Control, Container, Panel etc.

Vector2 _get_minimum_size

_get_tooltip(Vector2)

Qualifiers: virtualconst

Virtual method to be implemented by the user. Returns the tooltip text for the position at_position in control's local coordinates, which will typically appear when the cursor is resting over this control. See Control.get_tooltip.

Note: If this method returns an empty String and Control._make_custom_tooltip is not overridden, no tooltip is displayed.

String _get_tooltip(Vector2 at_position)

Parameters

at_position Vector2

_gui_input(InputEvent)

Qualifiers: virtual

Virtual method to be implemented by the user. Override this method to handle and accept inputs on UI elements. See also accept_event.

Example: Click on the control to print a message:

func _gui_input(event):
    if event is InputEventMouseButton:
        if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
            print("I've been clicked D:")

If the event inherits InputEventMouse, this method will not be called when:

  • the control's mouse_filter is set to Control.MOUSE_FILTER_IGNORE;

  • the control is obstructed by another control on top, that doesn't have mouse_filter set to Control.MOUSE_FILTER_IGNORE;

  • the control's parent has mouse_filter set to Control.MOUSE_FILTER_STOP or has accepted the event;

  • the control's parent has clip_contents enabled and the event's position is outside the parent's rectangle;

  • the event's position is outside the control (see Control._has_point).

Note: The event's position is relative to this control's origin.

void _gui_input(InputEvent event)

Parameters

event InputEvent

_has_point(Vector2)

Qualifiers: virtualconst

Virtual method to be implemented by the user. Returns whether the given point is inside this control.

If not overridden, default behavior is checking if the point is within control's Rect.

Note: If you want to check if a point is inside the control, you can use Rect2(Vector2.ZERO, size).has_point(point).

bool _has_point(Vector2 point)

Parameters

point Vector2

_make_custom_tooltip(String)

Qualifiers: virtualconst

Virtual method to be implemented by the user. Returns a Control node that should be used as a tooltip instead of the default one. for_text is the return value of Control.get_tooltip.

The returned node must be of type Control or Control-derived. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance (if you want to use a pre-existing node from your scene tree, you can duplicate it and pass the duplicated instance). When null or a non-Control node is returned, the default tooltip will be used instead.

The returned node will be added as child to a PopupPanel, so you should only provide the contents of that panel. That PopupPanel can be themed using Theme.set_stylebox for the type "TooltipPanel" (see tooltip_text for an example).

Note: The tooltip is shrunk to minimal size. If you want to ensure it's fully visible, you might want to set its custom_minimum_size to some non-zero value.

Note: The node (and any relevant children) should have their visible set to true when returned, otherwise, the viewport that instantiates it will not be able to calculate its minimum size reliably.

Note: If overridden, this method is called even if Control.get_tooltip returns an empty string. When this happens with the default tooltip, it is not displayed. To copy this behavior, return null in this method when for_text is empty.

Example: Use a constructed node as a tooltip:

func _make_custom_tooltip(for_text):
    var label = Label.new()
    label.text = for_text
    return label

Example: Usa a scene instance as a tooltip:

func _make_custom_tooltip(for_text):
    var tooltip = preload("res://some_tooltip_scene.tscn").instantiate()
    tooltip.get_node("Label").text = for_text
    return tooltip

Object _make_custom_tooltip(String for_text)

Parameters

for_text String

_structured_text_parser(Array, String)

Qualifiers: virtualconst

User defined BiDi algorithm override function.

Returns an Array of Vector3i text ranges and text base directions, in the left-to-right order. Ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.

Vector3i[] _structured_text_parser(Array args, String text)

Parameters

args Array
text String

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.

Note: This does not affect the methods in Input, only the way events are propagated.

void accept_event

add_theme_color_override(StringName, Color)

Creates a local override for a theme Color with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_color_override.

See also Control.get_theme_color.

Example: Override a Label's color and reset it later:

# Given the child Label node "MyLabel", override its font color with a custom value.
$MyLabel.add_theme_color_override("font_color", Color(1, 0.5, 0))
# Reset the font color of the child label.
$MyLabel.remove_theme_color_override("font_color")
# Alternatively it can be overridden with the default value from the Label type.
$MyLabel.add_theme_color_override("font_color", get_theme_color("font_color", "Label"))

void add_theme_color_override(StringName name, Color color)

Parameters

name StringName
color Color

add_theme_constant_override(StringName, int)

Creates a local override for a theme constant with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_constant_override.

See also Control.get_theme_constant.

void add_theme_constant_override(StringName name, int constant)

Parameters

name StringName
constant int

add_theme_font_override(StringName, Font)

Creates a local override for a theme Font with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_font_override.

See also Control.get_theme_font.

void add_theme_font_override(StringName name, Font font)

Parameters

name StringName
font Font

add_theme_font_size_override(StringName, int)

Creates a local override for a theme font size with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_font_size_override.

See also Control.get_theme_font_size.

void add_theme_font_size_override(StringName name, int font_size)

Parameters

name StringName
font_size int

add_theme_icon_override(StringName, Texture2D)

Creates a local override for a theme icon with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_icon_override.

See also Control.get_theme_icon.

void add_theme_icon_override(StringName name, Texture2D texture)

Parameters

name StringName
texture Texture2D

add_theme_stylebox_override(StringName, StyleBox)

Creates a local override for a theme StyleBox with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with Control.remove_theme_stylebox_override.

See also Control.get_theme_stylebox.

Example: Modify a property in a StyleBox by duplicating it:

# The snippet below assumes the child node "MyButton" has a StyleBoxFlat assigned.
# Resources are shared across instances, so we need to duplicate it
# to avoid modifying the appearance of all other buttons.
var new_stylebox_normal = $MyButton.get_theme_stylebox("normal").duplicate()
new_stylebox_normal.border_width_top = 3
new_stylebox_normal.border_color = Color(0, 1, 0.5)
$MyButton.add_theme_stylebox_override("normal", new_stylebox_normal)
# Remove the stylebox override.
$MyButton.remove_theme_stylebox_override("normal")

void add_theme_stylebox_override(StringName name, StyleBox stylebox)

Parameters

name StringName
stylebox StyleBox

begin_bulk_theme_override

Prevents *_theme_*_override methods from emitting NOTIFICATION_THEME_CHANGED until end_bulk_theme_override is called.

void begin_bulk_theme_override

end_bulk_theme_override

Ends a bulk theme override update. See begin_bulk_theme_override.

void end_bulk_theme_override

find_next_valid_focus

Qualifiers: const

Finds the next (below in the tree) Control that can receive the focus.

Control find_next_valid_focus

find_prev_valid_focus

Qualifiers: const

Finds the previous (above in the tree) Control that can receive the focus.

Control find_prev_valid_focus

find_valid_focus_neighbor(int)

Qualifiers: const

Finds the next Control that can receive the focus on the specified Side.

Note: This is different from Control.get_focus_neighbor, which returns the path of a specified focus neighbor.

Control find_valid_focus_neighbor(int side)

Parameters

side int

force_drag(Variant, Control)

Forces drag and bypasses Control._get_drag_data and Control.set_drag_preview by passing data and preview. Drag will start even if the mouse is neither over nor pressed on this control.

The methods Control._can_drop_data and Control._drop_data must be implemented on controls that want to receive drop data.

void force_drag(Variant data, Control preview)

Parameters

data Variant
preview Control

get_anchor(int)

Qualifiers: const

Returns the anchor for the specified Side. A getter method for anchor_bottom, anchor_left, anchor_right and anchor_top.

float get_anchor(int side)

Parameters

side int

get_begin

Qualifiers: const

Returns offset_left and offset_top. See also position.

Vector2 get_begin

get_combined_minimum_size

Qualifiers: const

Returns combined minimum size from custom_minimum_size and get_minimum_size.

Vector2 get_combined_minimum_size

get_cursor_shape(Vector2)

Qualifiers: const

Returns the mouse cursor shape the control displays on mouse hover. See CursorShape.

int get_cursor_shape(Vector2 position)

Parameters

position Vector2

get_end

Qualifiers: const

Returns offset_right and offset_bottom.

Vector2 get_end

get_focus_neighbor(int)

Qualifiers: const

Returns the focus neighbor for the specified Side. A getter method for focus_neighbor_bottom, focus_neighbor_left, focus_neighbor_right and focus_neighbor_top.

Note: To find the next Control on the specific Side, even if a neighbor is not assigned, use Control.find_valid_focus_neighbor.

NodePath get_focus_neighbor(int side)

Parameters

side int

get_global_rect

Qualifiers: const

Returns the position and size of the control relative to the containing canvas. See global_position and size.

Note: If the node itself or any parent CanvasItem between the node and the canvas have a non default rotation or skew, the resulting size is likely not meaningful.

Note: Setting gui_snap_controls_to_pixels to true can lead to rounding inaccuracies between the displayed control and the returned Rect2.

Rect2 get_global_rect

get_minimum_size

Qualifiers: const

Returns the minimum size for this control. See custom_minimum_size.

Vector2 get_minimum_size

get_offset(int)

Qualifiers: const

Returns the offset for the specified Side. A getter method for offset_bottom, offset_left, offset_right and offset_top.

float get_offset(int offset)

Parameters

offset int

get_parent_area_size

Qualifiers: const

Returns the width/height occupied in the parent control.

Vector2 get_parent_area_size

get_parent_control

Qualifiers: const

Returns the parent control node.

Control get_parent_control

get_rect

Qualifiers: const

Returns the position and size of the control in the coordinate system of the containing node. See position, scale and size.

Note: If rotation is not the default rotation, the resulting size is not meaningful.

Note: Setting gui_snap_controls_to_pixels to true can lead to rounding inaccuracies between the displayed control and the returned Rect2.

Rect2 get_rect

get_screen_position

Qualifiers: const

Returns the position of this Control in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.

Equals to global_position if the window is embedded (see gui_embed_subwindows).

Example: Show a popup at the mouse position:

popup_menu.position = get_screen_position() + get_local_mouse_position()
popup_menu.reset_size()
popup_menu.popup()

Vector2 get_screen_position

get_theme_color(StringName, StringName)

Qualifiers: const

Returns a Color from the first matching Theme in the tree if that Theme has a color item with the specified name and theme_type. If theme_type is omitted the class name of the current control is used as the type, or theme_type_variation if it is defined. If the type is a class name its parent classes are also checked, in order of inheritance. If the type is a variation its base types are checked, in order of dependency, then the control's class name and its parent classes are checked.

For the current control its local overrides are considered first (see Control.add_theme_color_override), then its assigned theme. After the current control, each parent control and its assigned theme are considered; controls without a theme assigned are skipped. If no matching Theme is found in the tree, the custom project Theme (see gui/theme/custom) and the default Theme are used (see ThemeDB).

func _ready():
    # Get the font color defined for the current Control's class, if it exists.
    modulate = get_theme_color("font_color")
    # Get the font color defined for the Button class.
    modulate = get_theme_color("font_color", "Button")

Color get_theme_color(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_theme_constant(StringName, StringName)

Qualifiers: const

Returns a constant from the first matching Theme in the tree if that Theme has a constant item with the specified name and theme_type.

See Control.get_theme_color for details.

int get_theme_constant(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_theme_default_base_scale

Qualifiers: const

Returns the default base scale value from the first matching Theme in the tree if that Theme has a valid default_base_scale value.

See Control.get_theme_color for details.

float get_theme_default_base_scale

get_theme_default_font

Qualifiers: const

Returns the default font from the first matching Theme in the tree if that Theme has a valid default_font value.

See Control.get_theme_color for details.

Font get_theme_default_font

get_theme_default_font_size

Qualifiers: const

Returns the default font size value from the first matching Theme in the tree if that Theme has a valid default_font_size value.

See Control.get_theme_color for details.

int get_theme_default_font_size

get_theme_font(StringName, StringName)

Qualifiers: const

Returns a Font from the first matching Theme in the tree if that Theme has a font item with the specified name and theme_type.

See Control.get_theme_color for details.

Font get_theme_font(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_theme_font_size(StringName, StringName)

Qualifiers: const

Returns a font size from the first matching Theme in the tree if that Theme has a font size item with the specified name and theme_type.

See Control.get_theme_color for details.

int get_theme_font_size(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_theme_icon(StringName, StringName)

Qualifiers: const

Returns an icon from the first matching Theme in the tree if that Theme has an icon item with the specified name and theme_type.

See Control.get_theme_color for details.

Texture2D get_theme_icon(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_theme_stylebox(StringName, StringName)

Qualifiers: const

Returns a StyleBox from the first matching Theme in the tree if that Theme has a stylebox item with the specified name and theme_type.

See Control.get_theme_color for details.

StyleBox get_theme_stylebox(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

get_tooltip(Vector2)

Qualifiers: const

Returns the tooltip text for the position at_position in control's local coordinates, which will typically appear when the cursor is resting over this control. By default, it returns tooltip_text.

This method can be overridden to customize its behavior. See Control._get_tooltip.

Note: If this method returns an empty String and Control._make_custom_tooltip is not overridden, no tooltip is displayed.

String get_tooltip(Vector2 at_position)

Parameters

at_position Vector2

grab_click_focus

Creates an InputEventMouseButton that attempts to click the control. If the event is received, the control gains focus.

func _process(delta):
    grab_click_focus() # When clicking another Control node, this node will be clicked instead.

void grab_click_focus

grab_focus

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

Note: Using this method together with Callable.call_deferred makes it more reliable, especially when called inside _ready.

void grab_focus

has_focus

Qualifiers: const

Returns true if this is the current focused control. See focus_mode.

bool has_focus

has_theme_color(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has a color item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_color(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_color_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme Color with the specified name in this Control node.

See Control.add_theme_color_override.

bool has_theme_color_override(StringName name)

Parameters

name StringName

has_theme_constant(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has a constant item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_constant(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_constant_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme constant with the specified name in this Control node.

See Control.add_theme_constant_override.

bool has_theme_constant_override(StringName name)

Parameters

name StringName

has_theme_font(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has a font item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_font(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_font_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme Font with the specified name in this Control node.

See Control.add_theme_font_override.

bool has_theme_font_override(StringName name)

Parameters

name StringName

has_theme_font_size(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has a font size item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_font_size(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_font_size_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme font size with the specified name in this Control node.

See Control.add_theme_font_size_override.

bool has_theme_font_size_override(StringName name)

Parameters

name StringName

has_theme_icon(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has an icon item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_icon(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_icon_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme icon with the specified name in this Control node.

See Control.add_theme_icon_override.

bool has_theme_icon_override(StringName name)

Parameters

name StringName

has_theme_stylebox(StringName, StringName)

Qualifiers: const

Returns true if there is a matching Theme in the tree that has a stylebox item with the specified name and theme_type.

See Control.get_theme_color for details.

bool has_theme_stylebox(StringName name, StringName theme_type)

Parameters

name StringName
theme_type StringName

has_theme_stylebox_override(StringName)

Qualifiers: const

Returns true if there is a local override for a theme StyleBox with the specified name in this Control node.

See Control.add_theme_stylebox_override.

bool has_theme_stylebox_override(StringName name)

Parameters

name StringName

is_drag_successful

Qualifiers: const

Returns true if a drag operation is successful. Alternative to gui_is_drag_successful.

Best used with NOTIFICATION_DRAG_END.

bool is_drag_successful

is_layout_rtl

Qualifiers: const

Returns true if layout is right-to-left. See also layout_direction.

bool is_layout_rtl

release_focus

Give up the focus. No other control will be able to receive input.

void release_focus

remove_theme_color_override(StringName)

Removes a local override for a theme Color with the specified name previously added by Control.add_theme_color_override or via the Inspector dock.

void remove_theme_color_override(StringName name)

Parameters

name StringName

remove_theme_constant_override(StringName)

Removes a local override for a theme constant with the specified name previously added by Control.add_theme_constant_override or via the Inspector dock.

void remove_theme_constant_override(StringName name)

Parameters

name StringName

remove_theme_font_override(StringName)

Removes a local override for a theme Font with the specified name previously added by Control.add_theme_font_override or via the Inspector dock.

void remove_theme_font_override(StringName name)

Parameters

name StringName

remove_theme_font_size_override(StringName)

Removes a local override for a theme font size with the specified name previously added by Control.add_theme_font_size_override or via the Inspector dock.

void remove_theme_font_size_override(StringName name)

Parameters

name StringName

remove_theme_icon_override(StringName)

Removes a local override for a theme icon with the specified name previously added by Control.add_theme_icon_override or via the Inspector dock.

void remove_theme_icon_override(StringName name)

Parameters

name StringName

remove_theme_stylebox_override(StringName)

Removes a local override for a theme StyleBox with the specified name previously added by Control.add_theme_stylebox_override or via the Inspector dock.

void remove_theme_stylebox_override(StringName name)

Parameters

name StringName

reset_size

Resets the size to get_combined_minimum_size. This is equivalent to calling set_size(Vector2()) (or any size below the minimum).

void reset_size

set_anchor(int, float, bool, bool)

Sets the anchor for the specified Side to anchor. A setter method for anchor_bottom, anchor_left, anchor_right and anchor_top.

If keep_offset is true, offsets aren't updated after this operation.

If push_opposite_anchor is true and the opposite anchor overlaps this anchor, the opposite one will have its value overridden. For example, when setting left anchor to 1 and the right anchor has value of 0.5, the right anchor will also get value of 1. If push_opposite_anchor was false, the left anchor would get value 0.5.

void set_anchor(int side, float anchor, bool keep_offset, bool push_opposite_anchor)

Parameters

side int
anchor float
keep_offset bool
push_opposite_anchor bool

set_anchor_and_offset(int, float, float, bool)

Works the same as Control.set_anchor, but instead of keep_offset argument and automatic update of offset, it allows to set the offset yourself (see Control.set_offset).

void set_anchor_and_offset(int side, float anchor, float offset, bool push_opposite_anchor)

Parameters

side int
anchor float
offset float
push_opposite_anchor bool

set_anchors_and_offsets_preset(int, int, int)

Sets both anchor preset and offset preset. See Control.set_anchors_preset and Control.set_offsets_preset.

void set_anchors_and_offsets_preset(int preset, int resize_mode, int margin)

Parameters

preset int
resize_mode int
margin int

set_anchors_preset(int, bool)

Sets the anchors to a preset from LayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.

If keep_offsets is true, control's position will also be updated.

void set_anchors_preset(int preset, bool keep_offsets)

Parameters

preset int
keep_offsets bool

set_begin(Vector2)

Sets offset_left and offset_top at the same time. Equivalent of changing position.

void set_begin(Vector2 position)

Parameters

position Vector2

set_drag_forwarding(Callable, Callable, Callable)

Sets the given callables to be used instead of the control's own drag-and-drop virtual methods. If a callable is empty, its respective virtual method is used as normal.

The arguments for each callable should be exactly the same as their respective virtual methods, which would be:

  • drag_func corresponds to Control._get_drag_data and requires a Vector2;

  • can_drop_func corresponds to Control._can_drop_data and requires both a Vector2 and a Variant;

  • drop_func corresponds to Control._drop_data and requires both a Vector2 and a Variant.

void set_drag_forwarding(Callable drag_func, Callable can_drop_func, Callable drop_func)

Parameters

drag_func Callable
can_drop_func Callable
drop_func Callable

set_drag_preview(Control)

Shows the given control at the mouse pointer. A good time to call this method is in Control._get_drag_data. The control must not be in the scene tree. You should not free the control, and you should not keep a reference to the control beyond the duration of the drag. It will be deleted automatically after the drag has ended.

@export var color = Color(1, 0, 0, 1)

func _get_drag_data(position):
    # Use a control that is not in the tree
    var cpb = ColorPickerButton.new()
    cpb.color = color
    cpb.size = Vector2(50, 50)
    set_drag_preview(cpb)
    return color

void set_drag_preview(Control control)

Parameters

control Control

set_end(Vector2)

Sets offset_right and offset_bottom at the same time.

void set_end(Vector2 position)

Parameters

position Vector2

set_focus_neighbor(int, NodePath)

Sets the focus neighbor for the specified Side to the Control at neighbor node path. A setter method for focus_neighbor_bottom, focus_neighbor_left, focus_neighbor_right and focus_neighbor_top.

void set_focus_neighbor(int side, NodePath neighbor)

Parameters

side int
neighbor NodePath

set_global_position(Vector2, bool)

Sets the global_position to given position.

If keep_offsets is true, control's anchors will be updated instead of offsets.

void set_global_position(Vector2 position, bool keep_offsets)

Parameters

position Vector2
keep_offsets bool

set_offset(int, float)

Sets the offset for the specified Side to offset. A setter method for offset_bottom, offset_left, offset_right and offset_top.

void set_offset(int side, float offset)

Parameters

side int
offset float

set_offsets_preset(int, int, int)

Sets the offsets to a preset from LayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.

Use parameter resize_mode with constants from LayoutPresetMode to better determine the resulting size of the Control. Constant size will be ignored if used with presets that change size, e.g. Control.PRESET_LEFT_WIDE.

Use parameter margin to determine the gap between the Control and the edges.

void set_offsets_preset(int preset, int resize_mode, int margin)

Parameters

preset int
resize_mode int
margin int

set_position(Vector2, bool)

Sets the position to given position.

If keep_offsets is true, control's anchors will be updated instead of offsets.

void set_position(Vector2 position, bool keep_offsets)

Parameters

position Vector2
keep_offsets bool

set_size(Vector2, bool)

Sets the size (see size).

If keep_offsets is true, control's anchors will be updated instead of offsets.

void set_size(Vector2 size, bool keep_offsets)

Parameters

size Vector2
keep_offsets bool

update_minimum_size

Invalidates the size cache in this node and in parent nodes up to top level. Intended to be used with get_minimum_size when the return value is changed. Setting custom_minimum_size directly calls this method automatically.

void update_minimum_size

warp_mouse(Vector2)

Moves the mouse cursor to position, relative to position of this Control.

Note: Control.warp_mouse is only supported on Windows, macOS and Linux. It has no effect on Android, iOS and Web.

void warp_mouse(Vector2 position)

Parameters

position Vector2

Events

focus_entered

Emitted when the node gains focus.

signal focus_entered

focus_exited

Emitted when the node loses focus.

signal focus_exited

gui_input(InputEvent)

Emitted when the node receives an InputEvent.

signal gui_input(InputEvent event)

Parameters

event InputEvent

minimum_size_changed

Emitted when the node's minimum size changes.

signal minimum_size_changed

mouse_entered

Emitted when the mouse cursor enters the control's (or any child control's) visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect, which Control receives the signal.

signal mouse_entered

mouse_exited

Emitted when the mouse cursor leaves the control's (and all child control's) visible area, that is not occluded behind other Controls or Windows, provided its mouse_filter lets the event reach it and regardless if it's currently focused or not.

Note: z_index doesn't affect, which Control receives the signal.

Note: If you want to check whether the mouse truly left the area, ignoring any top nodes, you can use code like this:

func _on_mouse_exited():
    if not Rect2(Vector2(), size).has_point(get_local_mouse_position()):
        # Not hovering over area.

signal mouse_exited

resized

Emitted when the control changes size.

signal resized

size_flags_changed

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

signal size_flags_changed

theme_changed

Emitted when the NOTIFICATION_THEME_CHANGED notification is sent.

signal theme_changed