Struct Control

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

struct Control ;

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 margins that represent an offset to the anchor. The margins update automatically when the node, any of its parents, or the screen size change. For more information on Godot's UI system, anchors, margins, and containers, see the related tutorials in the manual. To build flexible UIs, you'll need a mix of UI elements that inherit from Control and Container nodes. User Interface nodes and input Godot sends input events to the scene's root node first, by calling Node.input. Node.input forwards the event down the node tree to the nodes under the mouse cursor, or on keyboard focus. To do so, it calls MainLoop.inputEvent. Call acceptEvent so no other node receives the event. Once you accepted an input, it becomes handled so Node.unhandledInput 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 grabFocus. Control nodes lose focus when another node grabs it, or if you hide the node in focus. Sets mouseFilter to constant 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. 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 addFontOverride. You can override the theme with the inspector.

Properties

NameTypeDescription
anchorBottom[get, set] doubleAnchors 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 anchor constants for convenience.
anchorLeft[get, set] doubleAnchors 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 anchor constants for convenience.
anchorRight[get, set] doubleAnchors 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 anchor constants for convenience.
anchorTop[get, set] doubleAnchors 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 anchor constants for convenience.
focusMode[get, set] Control.FocusModeThe 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.
focusNeighbourBottom[get, set] NodePathTells 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.
focusNeighbourLeft[get, set] NodePathTells 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.
focusNeighbourRight[get, set] NodePathTells 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.
focusNeighbourTop[get, set] NodePathTells 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.
focusNext[get, set] NodePathTells 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.
focusPrevious[get, set] NodePathTells 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.
growHorizontal[get, set] Control.GrowDirectionControls 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.
growVertical[get, set] Control.GrowDirectionControls 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.
hintTooltip[get, set] StringChanges the tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that the mouseFilter property is not constant MOUSE_FILTER_IGNORE. You can change the time required for the tooltip to appear with gui/timers/tooltip_delay_sec option in Project Settings.
marginBottom[get, set] doubleDistance between the node's bottom edge and its parent control, based on anchorBottom. 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 Container. Margins update automatically when you move or resize the node.
marginLeft[get, set] doubleDistance between the node's left edge and its parent control, based on anchorLeft. 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 Container. Margins update automatically when you move or resize the node.
marginRight[get, set] doubleDistance between the node's right edge and its parent control, based on anchorRight. 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 Container. Margins update automatically when you move or resize the node.
marginTop[get, set] doubleDistance between the node's top edge and its parent control, based on anchorTop. 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 Container. Margins update automatically when you move or resize the node.
mouseDefaultCursorShape[get, set] Control.CursorShapeThe 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.
mouseFilter[get, set] Control.MouseFilterControls whether the control will be able to receive mouse button input events through guiInput and how these events should be handled. Also controls whether the control can receive the mouseEntered, and mouseExited signals. See the constants to learn what each does.
rectClipContent[get, set] boolEnables whether rendering of 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.
rectGlobalPosition[get, set] Vector2The node's global position, relative to the world (usually to the top-left corner of the window).
rectMinSize[get, set] Vector2The 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.
rectPivotOffset[get, set] Vector2By default, the node's pivot is its top-left corner. When you change its rectScale, it will scale around this pivot. Set this property to rectSize / 2 to center the pivot in the node's rectangle.
rectPosition[get, set] Vector2The node's position, relative to its parent. It corresponds to the rectangle's top-left corner. The property is not affected by rectPivotOffset.
rectRotation[get, set] doubleThe node's rotation around its pivot, in degrees. See rectPivotOffset to change the pivot's position.
rectScale[get, set] Vector2The node's scale, relative to its rectSize. Change this property to scale the node around its rectPivotOffset.
rectSize[get, set] Vector2The size of the node's bounding rectangle, in pixels. Container nodes update this property automatically.
sizeFlagsHorizontal[get, set] longTells the parent Container nodes how they should resize and place the node on the X axis. Use one of the sizeflags constants to change the flags. See the constants to learn what each does.
sizeFlagsStretchRatio[get, set] doubleIf the node and at least one of its neighbours uses the constant SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.
sizeFlagsVertical[get, set] longTells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the sizeflags constants to change the flags. See the constants to learn what each does.
theme[get, set] ThemeChanging this property replaces the current Theme resource this node and all its Control children use.

Methods

NameDescription
_clipsInput Virtual method to be implemented by the user. Returns whether guiInput should not be called for children controls outside this control's rectangle. Input will be clipped to the Rect of this Control. Similar to rectClipContent, but doesn't affect visibility. If not overridden, defaults to false.
_getMinimumSize Virtual method to be implemented by the user. Returns the minimum size for this control. Alternative to rectMinSize 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 constant Vector2.ZERO.
_getTooltip
_guiInput Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See acceptEvent.
_makeCustomTooltip Virtual method to be implemented by the user. Returns a Control node that should be used as a tooltip instead of the default one. Use for_text parameter to determine what text the tooltip should contain (likely the contents of hintTooltip). The returned node must be of type Control or Control-derieved. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance, not e.g. a node from scene. When null or non-Control node is returned, the default tooltip will be used instead. Note: The tooltip is shrunk to minimal size. If you want to ensure it's fully visible, you might want to set its rectMinSize to some non-zero value. Example of usage with custom-constructed node:
_overrideChanged
_setAnchor
_setGlobalPosition
_setPosition
_setSize
_sizeChanged
_themeChanged
_updateMinimumSize
acceptEvent Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to Node.unhandledInput or Node.unhandledKeyInput.
addColorOverride Overrides the Color with given name in the theme resource the control uses. If the color is empty or invalid, the override is cleared and the color from assigned Theme is used.
addConstantOverride Overrides an integer constant with given name in the theme resource the control uses. If the constant is empty or invalid, the override is cleared and the constant from assigned Theme is used.
addFontOverride Overrides the font with given name in the theme resource the control uses. If font is empty or invalid, the override is cleared and the font from assigned Theme is used.
addIconOverride Overrides the icon with given name in the theme resource the control uses. If icon is empty or invalid, the override is cleared and the icon from assigned Theme is used.
addShaderOverride Overrides the Shader with given name in the theme resource the control uses. If shader is empty or invalid, the override is cleared and the shader from assigned Theme is used.
addStyleboxOverride Overrides the StyleBox with given name in the theme resource the control uses. If stylebox is empty or invalid, the override is cleared and the StyleBox from assigned Theme is used.
canDropData Godot calls this method to test if data from a control's getDragData 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 dropData.
dropData Godot calls this method to pass you the data from a control's getDragData result. Godot first calls canDropData to test if data is allowed to drop at position where position is local to this control.
forceDrag Forces drag and bypasses getDragData and setDragPreview by passing data and preview. Drag will start even if the mouse is neither over nor pressed on this control. The methods canDropData and dropData must be implemented on controls that want to receive drop data.
getAnchor Returns the anchor identified by margin constant from margin enum. A getter method for anchorBottom, anchorLeft, anchorRight and anchorTop.
getBegin Returns marginLeft and marginTop. See also rectPosition.
getColor Returns a color from assigned Theme with given name and associated with Control of given type.
getCombinedMinimumSize Returns combined minimum size from rectMinSize and getMinimumSize.
getConstant Returns a constant from assigned Theme with given name and associated with Control of given type.
getCursorShape Returns the mouse cursor shape the control displays on mouse hover. See cursorshape.
getCustomMinimumSize
getDefaultCursorShape
getDragData 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 canDropData and dropData. position is local to this control. Drag may be forced with forceDrag. A preview that will follow the mouse that should represent the data can be set with setDragPreview. A good time to set the preview is in this method.
getEnd Returns marginRight and marginBottom.
getFocusMode
getFocusNeighbour Returns the focus neighbour identified by margin constant from margin enum. A getter method for focusNeighbourBottom, focusNeighbourLeft, focusNeighbourRight and focusNeighbourTop.
getFocusNext
getFocusOwner Returns the control that has the keyboard focus or null if none.
getFocusPrevious
getFont Returns a font from assigned Theme with given name and associated with Control of given type.
getGlobalPosition
getGlobalRect Returns the position and size of the control relative to the top-left corner of the screen. See rectPosition and rectSize.
getHGrowDirection
getHSizeFlags
getIcon Returns an icon from assigned Theme with given name and associated with Control of given type.
getMargin Returns the anchor identified by margin constant from margin enum. A getter method for marginBottom, marginLeft, marginRight and marginTop.
getMinimumSize Returns the minimum size for this control. See rectMinSize.
getMouseFilter
getParentAreaSize Returns the width/height occupied in the parent control.
getParentControl Returns the parent control node.
getPivotOffset
getPosition
getRect Returns the position and size of the control relative to the top-left corner of the parent Control. See rectPosition and rectSize.
getRotation Returns the rotation (in radians).
getRotationDegrees
getScale
getSize
getStretchRatio
getStylebox Returns a StyleBox from assigned Theme with given name and associated with Control of given type.
getTheme
getTooltip Returns the tooltip, which will appear when the cursor is resting over this control. See hintTooltip.
getVGrowDirection
getVSizeFlags
grabClickFocus Creates an InputEventMouseButton that attempts to click the control. If the event is received, the control acquires focus.
grabFocus Steal the focus from another control and become the focused control (see focusMode).
hasColor Returns true if Color with given name and associated with Control of given type exists in assigned Theme.
hasColorOverride Returns true if Color with given name has a valid override in this Control node.
hasConstant Returns true if constant with given name and associated with Control of given type exists in assigned Theme.
hasConstantOverride Returns true if constant with given name has a valid override in this Control node.
hasFocus Returns true if this is the current focused control. See focusMode.
hasFont Returns true if font with given name and associated with Control of given type exists in assigned Theme.
hasFontOverride Returns true if font with given name has a valid override in this Control node.
hasIcon Returns true if icon with given name and associated with Control of given type exists in assigned Theme.
hasIconOverride Returns true if icon with given name has a valid override in this Control node.
hasPoint 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).
hasShaderOverride Returns true if Shader with given name has a valid override in this Control node.
hasStylebox Returns true if StyleBox with given name and associated with Control of given type exists in assigned Theme.
hasStyleboxOverride Returns true if StyleBox with given name has a valid override in this Control node.
isClippingContents
minimumSizeChanged Invalidates the size cache in this node and in parent nodes up to toplevel. Intended to be used with getMinimumSize when the return value is changed. Setting rectMinSize directly calls this method automatically.
releaseFocus Give up the focus. No other control will be able to receive keyboard input.
setAnchor Sets the anchor identified by margin constant from margin enum to value anchor. A setter method for anchorBottom, anchorLeft, anchorRight and anchorTop. 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.
setAnchorAndMargin Works the same as setAnchor, but instead of keep_margin argument and automatic update of margin, it allows to set the margin offset yourself (see setMargin).
setAnchorsAndMarginsPreset Sets both anchor preset and margin preset. See setAnchorsPreset and setMarginsPreset.
setAnchorsPreset Sets the anchors to a preset from Control.layoutpreset 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.
setBegin Sets marginLeft and marginTop at the same time. Equivalent of changing rectPosition.
setClipContents
setCustomMinimumSize
setDefaultCursorShape
setDragForwarding 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 getDragData, canDropData, and dropData 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
setDragPreview Shows the given control at the mouse pointer. A good time to call this method is in getDragData. The control must not be in the scene tree.
setEnd Sets marginRight and marginBottom at the same time.
setFocusMode
setFocusNeighbour Sets the anchor identified by margin constant from margin enum to Control at neighbor node path. A setter method for focusNeighbourBottom, focusNeighbourLeft, focusNeighbourRight and focusNeighbourTop.
setFocusNext
setFocusPrevious
setGlobalPosition Sets the rectGlobalPosition to given position. If keep_margins is true, control's anchors will be updated instead of margins.
setHGrowDirection
setHSizeFlags
setMargin Sets the margin identified by margin constant from margin enum to given offset. A setter method for marginBottom, marginLeft, marginRight and marginTop.
setMarginsPreset Sets the margins to a preset from Control.layoutpreset enum. This is code equivalent of using the Layout menu in 2D editor. Use parameter resize_mode with constants from Control.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.
setMouseFilter
setPivotOffset
setPosition Sets the rectPosition to given position. If keep_margins is true, control's anchors will be updated instead of margins.
setRotation Sets the rotation (in radians).
setRotationDegrees
setScale
setSize Sets the size (see rectSize). If keep_margins is true, control's anchors will be updated instead of margins.
setStretchRatio
setTheme
setTooltip
setVGrowDirection
setVSizeFlags
showModal 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.
warpMouse Moves the mouse cursor to to_position, relative to rectPosition of this Control.

Enums

NameDescription
Anchor
Constants
CursorShape
FocusMode
GrowDirection
LayoutPreset
LayoutPresetMode
MouseFilter
SizeFlags