Control

    Inherited By: , ColorRect, , GraphEdit, , Label, , NinePatchRect, , Popup, , ReferenceRect, , Separator, , TextEdit, , Tree,

    All user interface nodes inherit from Control. A control’s anchors and margins adapt its position and size relative to its parent.

    Base class for all UI-related nodes. features a bounding rectangle that defines its extents, an anchor position relative to its parent control or the current viewport, 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 forwards the event down the node tree to the nodes under the mouse cursor, or on keyboard focus. To do so, it calls . Call accept_event so no other node receives the event. Once you accepted an input, it becomes handled so 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 focus, call grab_focus. Control nodes lose focus when another node grabs it, or if you hide the node in focus.

    Sets to 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.

    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 . You can override the theme with the inspector.

    Note: Theme items are not Object properties. This means you can’t access their values using and Object.set. Instead, use , get_constant, , get_icon, , and the add_*_override methods provided by this class.

    Tutorials

    Properties

    _clips_input ( ) virtual
    _get_minimum_size ( ) virtual
    void ( InputEvent event ) virtual
    _make_custom_tooltip ( for_text ) virtual
    voidaccept_event ( )
    void ( String name, color )
    voidadd_constant_override ( name, int constant )
    void ( String name, font )
    voidadd_icon_override ( name, Texture texture )
    void ( String name, shader )
    voidadd_stylebox_override ( name, StyleBox stylebox )
    can_drop_data ( position, Variant data ) virtual
    void ( Vector2 position, data ) virtual
    voidforce_drag ( data, Control preview )
    get_anchor ( margin ) const
    Vector2 ( ) const
    Color ( String name, node_type=”” ) const
    Vector2 ( ) const
    int ( String name, node_type=”” ) const
    CursorShape ( Vector2 position=Vector2( 0, 0 ) ) const
    get_drag_data ( position ) virtual
    Vector2 ( ) const
    NodePath ( Margin margin ) const
    get_focus_owner ( ) const
    get_font ( name, String node_type=”” ) const
    get_global_rect ( ) const
    get_icon ( name, String node_type=”” ) const
    get_margin ( margin ) const
    Vector2 ( ) const
    Vector2 ( ) const
    Control ( ) const
    Rect2 ( ) const
    float ( ) const
    StyleBox ( String name, node_type=”” ) const
    String ( Vector2 at_position=Vector2( 0, 0 ) ) const
    void ( )
    voidgrab_focus ( )
    has_color ( name, String node_type=”” ) const
    has_color_override ( name ) const
    bool ( String name, node_type=”” ) const
    bool ( String name ) const
    has_focus ( ) const
    has_font ( name, String node_type=”” ) const
    has_font_override ( name ) const
    bool ( String name, node_type=”” ) const
    bool ( String name ) const
    has_point ( point ) virtual
    bool ( String name ) const
    has_stylebox ( name, String node_type=”” ) const
    has_stylebox_override ( name ) const
    voidminimum_size_changed ( )
    void ( )
    voidset_anchor ( margin, float anchor, keep_margin=false, bool push_opposite_anchor=true )
    void ( Margin margin, anchor, float offset, push_opposite_anchor=false )
    voidset_anchors_and_margins_preset ( preset, LayoutPresetMode resize_mode=0, margin=0 )
    voidset_anchors_preset ( preset, bool keep_margins=false )
    void ( Vector2 position )
    void ( Control target )
    void ( Control control )
    void ( Vector2 position )
    void ( Margin margin, neighbour )
    voidset_global_position ( position, bool keep_margins=false )
    void ( Margin margin, offset )
    voidset_margins_preset ( preset, LayoutPresetMode resize_mode=0, margin=0 )
    voidset_position ( position, bool keep_margins=false )
    void ( float radians )
    void ( Vector2 size, keep_margins=false )
    voidshow_modal ( exclusive=false )
    voidwarp_mouse ( 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 .


    • 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, provided its lets the event reach it.


    • mouse_exited ( )

    Emitted when the mouse leaves the control’s Rect area, provided its mouse_filter lets the event reach it.


    • resized ( )

    Emitted when the control changes size.


    • size_flags_changed ( )

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

    Enumerations

    enum FocusMode:

    • FOCUS_NONE = 0 —- The node cannot grab focus. Use with .
    • FOCUS_CLICK = 1 —- The node can only grab focus on mouse clicks. Use with 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 .

    enum CursorShape:

    • CURSOR_ARROW = 0 —- Show the system’s arrow mouse cursor when the user hovers the node. Use with mouse_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 . 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_HELP = 16 —- Show the system’s help mouse cursor when the user hovers the node, a question mark.

    enum LayoutPreset:

    • PRESET_TOP_LEFT = 0 —- Snap all 4 anchors to the top-left of the parent control’s bounds. Use with set_anchors_preset.
    • PRESET_TOP_RIGHT = 1 —- Snap all 4 anchors to the top-right of the parent control’s bounds. Use with .
    • PRESET_BOTTOM_LEFT = 2 —- Snap all 4 anchors to the bottom-left of the parent control’s bounds. Use with set_anchors_preset.
    • PRESET_BOTTOM_RIGHT = 3 —- Snap all 4 anchors to the bottom-right of the parent control’s bounds. Use with .
    • PRESET_CENTER_LEFT = 4 —- Snap all 4 anchors to the center of the left edge of the parent control’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 control’s bounds. Use with .
    • PRESET_CENTER_RIGHT = 6 —- Snap all 4 anchors to the center of the right edge of the parent control’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 control’s bounds. Use with .
    • PRESET_CENTER = 8 —- Snap all 4 anchors to the center of the parent control’s bounds. Use with set_anchors_preset.
    • PRESET_LEFT_WIDE = 9 —- Snap all 4 anchors to the left edge of the parent control. 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 .
    • PRESET_TOP_WIDE = 10 —- Snap all 4 anchors to the top edge of the parent control. 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 control. 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 .
    • PRESET_BOTTOM_WIDE = 12 —- Snap all 4 anchors to the bottom edge of the parent control. 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 control in half. Use with .
    • PRESET_HCENTER_WIDE = 14 —- Snap all 4 anchors to a horizontal line that cuts the parent control in half. Use with set_anchors_preset.
    • PRESET_WIDE = 15 —- Snap all 4 anchors to the respective corners of the parent control. Set all 4 margins to 0 after you applied this preset and the Control will fit its parent control. This is equivalent to the “Full Rect” layout option in the editor. Use with .

    enum LayoutPresetMode:

    • PRESET_MODE_MINSIZE = 0 —- The control will be resized to its minimum size.
    • PRESET_MODE_KEEP_WIDTH = 1 —- The control’s width will not change.
    • PRESET_MODE_KEEP_HEIGHT = 2 —- The control’s height will not change.
    • PRESET_MODE_KEEP_SIZE = 3 —- The control’s size will not change.

    enum SizeFlags:

    • 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 and size_flags_vertical.
    • SIZE_EXPAND = 2 —- Tells the parent 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 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 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_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 and size_flags_vertical.

    enum MouseFilter:

    • MOUSE_FILTER_STOP = 0 —- The control will receive mouse button input events through if clicked on. And the control will receive the mouse_entered and signals. These events are automatically marked as handled, and they will not propagate further to other controls. This also results in blocking signals in other controls.
    • MOUSE_FILTER_PASS = 1 —- The control will receive mouse button input events through _gui_input if clicked on. And the control will receive the and mouse_exited signals. If this control does not handle the event, the parent control (if any) will be considered, and so on until there is no more parent control to potentially handle it. This also allows signals to fire in other controls. Even if no control handled it at all, the event will still be handled automatically, so unhandled input will not be fired.
    • MOUSE_FILTER_IGNORE = 2 —- The control will not receive mouse button input events through . The control will also not receive the mouse_entered nor signals. This will not block other controls from receiving these events or firing the signals. Ignored events will not be handled automatically.

    enum GrowDirection:

    • GROW_DIRECTION_BEGIN = 0 —- The control will grow to the left or top to make up if its minimum size is changed to be greater than its current size on the respective axis.
    • GROW_DIRECTION_END = 1 —- The control will grow to the right or bottom to make up if its minimum size is changed to be greater than its current size on the respective axis.
    • GROW_DIRECTION_BOTH = 2 —- The control will grow in both directions equally to make up if its minimum size is changed to be greater than its current size.

    enum Anchor:

    • 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 .
    • 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 .
    • 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.
    • NOTIFICATION_MOUSE_EXIT = 42 —- Sent when the mouse pointer exits the node.
    • NOTIFICATION_FOCUS_ENTER = 43 —- Sent when the node grabs focus.
    • NOTIFICATION_FOCUS_EXIT = 44 —- Sent when the node loses focus.
    • NOTIFICATION_MODAL_CLOSE = 46 —- Sent when an open modal dialog closes. See .
    • NOTIFICATION_SCROLL_BEGIN = 47 —- Sent when this node is inside a ScrollContainer which has begun being scrolled.
    • NOTIFICATION_SCROLL_END = 48 —- Sent when this node is inside a which has stopped being scrolled.

    Property Descriptions

    Default0.0
    Getterget_anchor()

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


    Default0.0
    Getterget_anchor()

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


    Default0.0
    Getterget_anchor()

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


    Default0.0
    Getterget_anchor()

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


    Default0
    Setterset_focus_mode(value)
    Getterget_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 signals.


    • focus_neighbour_bottom
    DefaultNodePath(“”)
    Setterset_focus_neighbour(value)
    Getterget_focus_neighbour()

    Tells Godot which node it should give keyboard 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 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.


    DefaultNodePath(“”)
    Setterset_focus_neighbour(value)
    Getterget_focus_neighbour()

    Tells Godot which node it should give keyboard 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 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.


    • focus_neighbour_right
    DefaultNodePath(“”)
    Setterset_focus_neighbour(value)
    Getterget_focus_neighbour()

    Tells Godot which node it should give keyboard 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 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 bottom of this one.


    DefaultNodePath(“”)
    Setterset_focus_neighbour(value)
    Getterget_focus_neighbour()

    Tells Godot which node it should give keyboard 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 ui_top 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.


    • focus_next

    Tells Godot which node it should give keyboard focus to if the user presses Tab on a keyboard by default. You can change the key by editing the 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.


    DefaultNodePath(“”)
    Setterset_focus_previous(value)
    Getterget_focus_previous()

    Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab on a keyboard by default. You can change the key by editing the 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.


    • grow_horizontal
    Default1
    Setterset_h_grow_direction(value)
    Getterget_h_grow_direction()

    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.


    Default1
    Setterset_v_grow_direction(value)
    Getterget_v_grow_direction()

    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.


    • hint_tooltip
    Default“”
    Setterset_tooltip(value)

    Changes the 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 . You can change the time required for the tooltip to appear with gui/timers/tooltip_delay_sec option in Project Settings.

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


    Default0.0
    Setterset_margin(value)
    Getterget_margin()

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

    Margins 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 . Margins update automatically when you move or resize the node.


    Default0.0
    Setterset_margin(value)
    Getterget_margin()

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

    Margins 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 . Margins update automatically when you move or resize the node.


    Default0.0
    Setterset_margin(value)
    Getterget_margin()

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

    Margins 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 . Margins update automatically when you move or resize the node.


    Default0.0
    Setterset_margin(value)
    Getterget_margin()

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

    Margins 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 . Margins update automatically when you move or resize the node.


    Default0
    Setterset_default_cursor_shape(value)
    Getterget_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.


    • mouse_filter
    Default0
    Setterset_mouse_filter(value)
    Getterget_mouse_filter()

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


    • rect_clip_content

    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.


    • rect_global_position
    Getterget_global_position()

    DefaultVector2( 0, 0 )
    Setterset_custom_minimum_size(value)
    Getterget_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, 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.


    • rect_pivot_offset
    DefaultVector2( 0, 0 )
    Setterset_pivot_offset(value)
    Getterget_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 / 2 to center the pivot in the node’s rectangle.


    DefaultVector2( 0, 0 )
    Getterget_position()

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


    Default0.0
    Setterset_rotation_degrees(value)
    Getterget_rotation_degrees()

    The node’s rotation around its pivot, in degrees. See to change the pivot’s position.


    DefaultVector2( 1, 1 )
    Setterset_scale(value)
    Getterget_scale()

    The node’s scale, relative to its . Change this property to scale the node around its rect_pivot_offset. The Control’s will also scale according to this value.

    Note: This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the documentation instead of scaling Controls individually.

    Note: If the Control node is a child of a node, the scale will be reset to Vector2(1, 1) when the scene is instanced. To set the Control’s scale when it’s instanced, wait for one frame using yield(get_tree(), "idle_frame") then set its rect_scale property.


    • rect_size
    Default
    Getterget_size()

    The size of the node’s bounding rectangle, in pixels. Container nodes update this property automatically.


    • size_flags_horizontal
    Default1
    Setterset_h_size_flags(value)
    Getterget_h_size_flags()

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


    • float size_flags_stretch_ratio
    Default1.0
    Setterset_stretch_ratio(value)
    Getterget_stretch_ratio()

    If the node and at least one of its neighbours uses the 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.


    • size_flags_vertical
    Default1
    Setterset_v_size_flags(value)
    Getterget_v_size_flags()

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


    Changing this property replaces the current resource this node and all its Control children use.

    Method Descriptions

    • bool _clips_input ( ) virtual

    Virtual method to be implemented by the user. Returns whether should not be called for children controls outside this control’s rectangle. Input will be clipped to the Rect of this Control. Similar to rect_clip_content, but doesn’t affect visibility.

    If not overridden, defaults to false.


    • _get_minimum_size ( ) virtual

    Virtual method to be implemented by the user. Returns the minimum size for this control. Alternative to rect_min_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 .


    Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See .

    Example: clicking a control.

    1. func _gui_input(event):
    2. if event is InputEventMouseButton:
    3. if event.button_index == BUTTON_LEFT and event.pressed:
    4. print("I've been clicked D:")

    The event won’t trigger if:

    * clicking outside the control (see has_point);

    * control has set to MOUSE_FILTER_IGNORE;

    * control is obstructed by another Control on top of it, which doesn’t have set to MOUSE_FILTER_IGNORE;

    * control’s parent has set to MOUSE_FILTER_STOP or has accepted the event;

    * it happens outside parent’s rectangle and the parent has either or _clips_input enabled.


    • _make_custom_tooltip ( String for_text ) virtual

    Virtual method to be implemented by the user. Returns a Control node that should be used as a tooltip instead of the default one. The for_text includes the contents of the property.

    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 can be themed using Theme.set_stylebox for the type "TooltipPanel" (see 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 rect_min_size to some non-zero value.

    Example of usage with a custom-constructed node:

    1. func _make_custom_tooltip(for_text):
    2. var label = Label.new()
    3. label.text = for_text
    4. return label

    Example of usage with a custom scene instance:

    1. func _make_custom_tooltip(for_text):
    2. var tooltip = preload("res://SomeTooltipScene.tscn").instance()
    3. tooltip.get_node("Label").text = for_text
    4. return tooltip

    • void accept_event ( )

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


    • void add_color_override ( name, Color color )

    Overrides the with given name in the theme resource the control uses.

    Note: Unlike other theme overrides, there is no way to undo a color override without manually assigning the previous color.

    Example of overriding a label’s color and resetting it later:


    • void add_constant_override ( name, int constant )

    Overrides an integer constant with given name in the resource the control uses. If the constant is 0, the override is cleared and the constant from assigned Theme is used.


    • void add_font_override ( name, Font font )

    Overrides the font with given name in the resource the control uses. If font is null or invalid, the override is cleared and the font from assigned Theme is used.


    • void add_icon_override ( name, Texture texture )

    Overrides the icon with given name in the resource the control uses. If icon is null or invalid, the override is cleared and the icon from assigned Theme is used.


    • void add_shader_override ( name, Shader shader )

    Overrides the with given name in the theme resource the control uses. If shader is null or invalid, the override is cleared and the shader from assigned is used.


    • void add_stylebox_override ( String name, stylebox )

    Overrides the StyleBox with given name in the resource the control uses. If stylebox is empty or invalid, the override is cleared and the StyleBox from assigned is used.

    Example of modifying a property in a StyleBox by duplicating it:

    1. # The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
    2. # Resources are shared across instances, so we need to duplicate it
    3. # to avoid modifying the appearance of all other buttons.
    4. var new_stylebox_normal = $MyButton.get_stylebox("normal").duplicate()
    5. new_stylebox_normal.border_width_top = 3
    6. new_stylebox_normal.border_color = Color(0, 1, 0.5)
    7. $MyButton.add_stylebox_override("normal", new_stylebox_normal)
    8. # Remove the stylebox override:
    9. $MyButton.add_stylebox_override("normal", null)

    Godot calls this method to test if data from a control’s can be dropped at position. position is local to this control.

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

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

    • void drop_data ( position, Variant data ) virtual

    Godot calls this method to pass you the data from a control’s result. Godot first calls can_drop_data to test if data is allowed to drop at position where position is local to this control.

    1. func can_drop_data(position, data):
    2. return typeof(data) == TYPE_DICTIONARY and data.has("color")
    3. func drop_data(position, data):
    4. color = data["color"]

    Forces drag and bypasses and 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 and drop_data must be implemented on controls that want to receive drop data.


    • get_anchor ( Margin margin ) const

    Returns the anchor identified by margin constant from enum. A getter method for anchor_bottom, , anchor_right and .


    Returns and margin_top. See also .


    • Color get_color ( name, String node_type=”” ) const

    Returns a color from assigned with given name and associated with Control of given node_type.


    • Vector2 get_combined_minimum_size ( ) const

    Returns combined minimum size from and get_minimum_size.


    • get_constant ( String name, node_type=”” ) const

    Returns a constant from assigned Theme with given name and associated with Control of given node_type.


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

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


    • Variant get_drag_data ( position ) 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 can_drop_data and . position is local to this control. Drag may be forced with force_drag.

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

    1. func get_drag_data(position):
    2. var mydata = make_data()
    3. set_drag_preview(make_preview(mydata))
    4. return mydata

    Returns and margin_bottom.


    • get_focus_neighbour ( Margin margin ) const

    Returns the focus neighbour identified by margin constant from enum. A getter method for focus_neighbour_bottom, , focus_neighbour_right and .


    Returns the control that has the keyboard focus or null if none.


    • get_font ( String name, node_type=”” ) const

    • Rect2 get_global_rect ( ) const

    Returns the position and size of the control relative to the top-left corner of the screen. See and rect_size.


    • get_icon ( String name, node_type=”” ) const

    Returns an icon from assigned Theme with given name and associated with Control of given node_type.


    • get_margin ( Margin margin ) const

    Returns the anchor identified by margin constant from enum. A getter method for margin_bottom, , margin_right and .


    • Vector2 get_minimum_size ( ) const

    Returns the minimum size for this control. See .


    • Vector2 get_parent_area_size ( ) const

    Returns the width/height occupied in the parent control.


    • get_parent_control ( ) const

    Returns the parent control node.


    • Rect2 get_rect ( ) const

    Returns the position and size of the control relative to the top-left corner of the parent Control. See and rect_size.


    • get_rotation ( ) const

    Returns the rotation (in radians).


    Returns a from assigned Theme with given name and associated with Control of given node_type.


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

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


    • void grab_click_focus ( )

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

    1. grab_click_focus() #when clicking another Control node, this node will be clicked instead

    • void grab_focus ( )

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


    • bool has_color ( name, String node_type=”” ) const

    Returns true if with given name and associated with Control of given node_type exists in assigned Theme.


    • has_color_override ( String name ) const

    Returns true if with given name has a valid override in this Control node.


    • bool has_constant ( name, String node_type=”” ) const

    Returns true if constant with given name and associated with Control of given node_type exists in assigned .


    • bool has_constant_override ( name ) const

    Returns true if constant with given name has a valid override in this Control node.


    • bool has_focus ( ) const

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


    • bool has_font ( name, String node_type=”” ) const

    Returns true if font with given name and associated with Control of given node_type exists in assigned .


    • bool has_font_override ( name ) const

    Returns true if font with given name has a valid override in this Control node.


    • bool has_icon ( name, String node_type=”” ) const

    Returns true if icon with given name and associated with Control of given node_type exists in assigned .


    • bool has_icon_override ( name ) const

    Returns true if icon with given name has a valid override in this Control node.


    • bool has_point ( point ) virtual

    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 get_rect().has_point(point).


    • bool has_shader_override ( name ) const

    Returns true if Shader with given name has a valid override in this Control node.


    • has_stylebox ( String name, node_type=”” ) const

    Returns true if StyleBox with given name and associated with Control of given node_type exists in assigned .


    • bool has_stylebox_override ( name ) const

    Returns true if StyleBox with given name has a valid override in this Control node.


    • void minimum_size_changed ( )

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


    • void release_focus ( )

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


    • void set_anchor ( margin, float anchor, keep_margin=false, bool push_opposite_anchor=true )

    Sets the anchor identified by margin constant from enum to value anchor. A setter method for anchor_bottom, , anchor_right and .

    If keep_margin is true, margins 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_and_margin ( Margin margin, anchor, float offset, push_opposite_anchor=false )

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


    • void set_anchors_and_margins_preset ( LayoutPreset preset, resize_mode=0, int margin=0 )

    Sets both anchor preset and margin preset. See and set_margins_preset.


    • void set_anchors_preset ( preset, bool keep_margins=false )

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

    If keep_margins is true, control’s position will also be updated.


    • void set_begin ( Vector2 position )

    Sets and margin_top at the same time. Equivalent of changing .


    • void set_drag_forwarding ( Control target )

    Forwards the handling of this control’s drag and drop to target control.

    Forwarding can be implemented in the target control similar to the methods , can_drop_data, and but with two differences:

    1. The function name must be suffixed with _fw
    2. The function must take an extra argument that is the control doing the forwarding
    1. # ThisControl.gd
    2. extends Control
    3. func _ready():
    4. set_drag_forwarding(target_control)
    5. # TargetControl.gd
    6. extends Control
    7. func can_drop_data_fw(position, data, from_control):
    8. return true
    9. func drop_data_fw(position, data, from_control):
    10. my_handle_data(data)
    11. func get_drag_data_fw(position, from_control):
    12. set_drag_preview(my_preview)
    13. return my_data()

    • void set_drag_preview ( Control control )

    Shows the given control at the mouse pointer. A good time to call this method is in . The control must not be in the scene tree.


    Sets and margin_bottom at the same time.


    • void set_focus_neighbour ( margin, NodePath neighbour )

    Sets the anchor identified by margin constant from enum to Control at neighbor node path. A setter method for focus_neighbour_bottom, , focus_neighbour_right and .


    • void set_global_position ( Vector2 position, keep_margins=false )

    Sets the rect_global_position to given position.

    If keep_margins is true, control’s anchors will be updated instead of margins.


    • void set_margin ( margin, float offset )

    Sets the margin identified by margin constant from enum to given offset. A setter method for margin_bottom, , margin_right and .


    • void set_margins_preset ( LayoutPreset preset, resize_mode=0, int margin=0 )

    Sets the margins to a preset from enum. This is code equivalent of using the Layout menu in 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. PRESET_LEFT_WIDE.

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


    • void set_position ( position, bool keep_margins=false )

    Sets the to given position.

    If keep_margins is true, control’s anchors will be updated instead of margins.


    • void set_rotation ( float radians )

    Sets the rotation (in radians).


    • void set_size ( size, bool keep_margins=false )

    Sets the size (see ).

    If keep_margins is true, control’s anchors will be updated instead of margins.


    • void show_modal ( bool exclusive=false )

    Displays 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.

    If exclusive is true, other controls will not receive input and clicking outside this control will not close it.


    • void warp_mouse ( to_position )

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