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

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

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

User Interface nodes and input

Godot sends input events to the scene’s root node first, by calling Node._Input(Godot.InputEvent). Node._Input(Godot.InputEvent) 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(Godot.InputEvent). Call AcceptEvent() so no other node receives the event. Once you accepted an input, it becomes handled so Node._UnhandledInput(Godot.InputEvent) 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 FocusMode.set. Control nodes lose focus when another node grabs it, or if you hide the node in focus.

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

Theme resources change the Control’s appearance. If you change the Theme on a Control node, it affects all of its children. To override some of the theme’s parameters, call one of the add_*_override methods, like AddFontOverride(string, Godot.Font). You can override the theme with the inspector.

Inheritance Chain

Derived Classes

Static Fields

    public const Int32 NotificationFocusEnter = 43

    public const Int32 NotificationFocusExit = 44

    public const Int32 NotificationModalClose = 46

    public const Int32 NotificationMouseEnter = 41

    public const Int32 NotificationMouseExit = 42

    public const Int32 NotificationResized = 40

    public const Int32 NotificationThemeChanged = 45

Constructors

    public Control()

Signals

    "focus_entered" ()

Emitted when the node gains keyboard focus.

    "focus_exited" ()

Emitted when the node loses keyboard focus.

    "gui_input" (Object ev)

Emitted when the node receives an InputEvent.

    "minimum_size_changed" ()

Emitted when the node’s minimum size changes.

    "modal_closed" ()

Emitted when a modal Control is closed. See ShowModal(bool).

    "mouse_entered" ()

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

    "mouse_exited" ()

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

    "resized" ()

Emitted when the control changes size.

    "size_flags_changed" ()

Emitted when one of the size flags changes. See SizeFlagsHorizontal and SizeFlagsVertical.

Properties

    public float AnchorBottom { get; set; }

Anchors the bottom edge of the node to the origin, the center, or the end of its parent container. It changes how the bottom margin updates when the node moves or changes size. Use one of the ANCHOR_* constants. Default value: ANCHOR_BEGIN.

    public float AnchorLeft { get; set; }

Anchors the left edge of the node to the origin, the center or the end of its parent container. It changes how the left margin updates when the node moves or changes size. Use one of the ANCHOR_* constants. Default value: ANCHOR_BEGIN.

    public float AnchorRight { get; set; }

Anchors the right edge of the node to the origin, the center or the end of its parent container. It changes how the right margin updates when the node moves or changes size. Use one of the ANCHOR_* constants. Default value: ANCHOR_BEGIN.

    public float AnchorTop { get; set; }

Anchors the top edge of the node to the origin, the center or the end of its parent container. It changes how the top margin updates when the node moves or changes size. Use one of the ANCHOR_* constants. Default value: ANCHOR_BEGIN.

    public FocusModeEnum FocusMode { get; set; }

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.

    public NodePath FocusNeighbourBottom { get; set; }

Tells Godot which node it should give keyboard focus to if the user presses Tab, the down arrow on the keyboard, or down on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

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

    public NodePath FocusNeighbourLeft { get; set; }

Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab, the left arrow on the keyboard or left on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the left of this one.

    public NodePath FocusNeighbourRight { get; set; }

Tells Godot which node it should give keyboard focus to if the user presses Tab, the right arrow on the keyboard or right on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

    public NodePath FocusNeighbourTop { get; set; }

Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab, the top arrow on the keyboard or top on a gamepad. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.

    public NodePath FocusNext { get; set; }

    public NodePath FocusPrevious { get; set; }

    public GrowDirection GrowHorizontal { get; set; }

    public GrowDirection GrowVertical { get; set; }

    public string HintTooltip { get; set; }

Changes the tooltip text. The tooltip appears when the user’s mouse cursor stays idle over this control for a few moments.

    public float MarginBottom { get; set; }

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

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

    public float MarginLeft { get; set; }

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

    public float MarginRight { get; set; }

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

    public float MarginTop { get; set; }

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

    public CursorShape MouseDefaultCursorShape { get; set; }

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

    public MouseFilterEnum MouseFilter { get; set; }

Controls whether the control will be able to receive mouse button input events through _GuiInput(Godot.InputEvent) and how these events should be handled. Use one of the MOUSE_FILTER_* constants. See the constants to learn what each does.

    public bool RectClipContent { get; set; }

    public Vector2 RectGlobalPosition { get; set; }

The node’s global position, relative to the world (usually to the top-left corner of the window).

    public Vector2 RectMinSize { get; set; }

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.

    public Vector2 RectPivotOffset { get; set; }

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

    public Vector2 RectPosition { get; set; }

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

    public float RectRotation { get; set; }

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

    public Vector2 RectScale { get; set; }

The node’s scale, relative to its RectSize. Change this property to scale the node around its RectPivotOffset.

    public Vector2 RectSize { get; set; }

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

    public int SizeFlagsHorizontal { get; set; }

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

    public float SizeFlagsStretchRatio { get; set; }

If the node and at least one of its neighbours uses the SIZE_EXPAND size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.

    public int SizeFlagsVertical { get; set; }

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

    public Theme Theme { get; set; }

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

Methods

    public virtual Vector2 _GetMinimumSize()

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

    public virtual void _GuiInput(InputEvent @event)

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

Replaces Godot 2’s _input_event.

    public void AcceptEvent()

Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to Node._UnhandledInput(Godot.InputEvent) or Node._UnhandledKeyInput(Godot.InputEventKey).

    public void AddColorOverride(string name, Color color)

Overrides the color in the Theme resource the node uses.

    public void AddConstantOverride(string name, int constant)

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

    public void AddFontOverride(string name, Font font)

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

    public void AddIconOverride(string name, Texture texture)

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

    public void AddShaderOverride(string name, Shader shader)

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

    public void AddStyleboxOverride(string name, StyleBox stylebox)

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

    public virtual bool CanDropData(Vector2 position, object data)

    public virtual void DropData(Vector2 position, object data)

    public void ForceDrag(object data, Control preview)

    public float GetAnchor(Margin margin)

    public Vector2 GetBegin()

    public Color GetColor(string name, string type = "")

    public Vector2 GetCombinedMinimumSize()

    public int GetConstant(string name, string type = "")

    public CursorShape GetCursorShape(Vector2? position = default(Vector2?))

Returns the mouse cursor shape the control displays on mouse hover, one of the CURSOR_* constants.

    public Vector2 GetCustomMinimumSize()

Getter for RectMinSize

    public CursorShape GetDefaultCursorShape()

Getter for MouseDefaultCursorShape

    public virtual Object GetDragData(Vector2 position)

    public Vector2 GetEnd()

Returns MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see SetMargin(Godot.Margin, float)).

    public FocusModeEnum GetFocusMode()

Getter for FocusMode

    public NodePath GetFocusNeighbour(Margin margin)

    public NodePath GetFocusNext()

Getter for FocusNext

    public Control GetFocusOwner()

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

    public NodePath GetFocusPrevious()

Getter for FocusPrevious

    public Font GetFont(string name, string type = "")

    public Vector2 GetGlobalPosition()

Getter for RectGlobalPosition

    public Rect2 GetGlobalRect()

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

    public GrowDirection GetHGrowDirection()

Getter for GrowHorizontal

    public int GetHSizeFlags()

Getter for SizeFlagsHorizontal

    public Texture GetIcon(string name, string type = "")

    public float GetMargin(Margin margin)

    public Vector2 GetMinimumSize()

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

    public MouseFilterEnum GetMouseFilter()

Getter for MouseFilter

    public Vector2 GetParentAreaSize()

    public Control GetParentControl()

    public Vector2 GetPivotOffset()

Getter for RectPivotOffset

    public Vector2 GetPosition()

Getter for RectPosition

    public Rect2 GetRect()

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

    public float GetRotation()

Return the rotation (in radians)

    public float GetRotationDegrees()

Getter for RectRotation

    public Vector2 GetScale()

Getter for RectScale

    public Vector2 GetSize()

Getter for RectSize

    public float GetStretchRatio()

Getter for SizeFlagsStretchRatio

    public StyleBox GetStylebox(string name, string type = "")

    public Theme GetTheme()

Getter for Theme

    public string GetTooltip(Vector2? atPosition = default(Vector2?))

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

    public GrowDirection GetVGrowDirection()

Getter for GrowVertical

    public int GetVSizeFlags()

Getter for SizeFlagsVertical

    public void GrabClickFocus()

    public void GrabFocus()

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

    public bool HasColor(string name, string type = "")

    public bool HasColorOverride(string name)

    public bool HasConstant(string name, string type = "")

    public bool HasConstantOverride(string name)

    public bool HasFocus()

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

    public bool HasFont(string name, string type = "")

    public bool HasFontOverride(string name)

    public bool HasIcon(string name, string type = "")

    public bool HasIconOverride(string name)

    public virtual bool HasPoint(Vector2 point)

    public bool HasShaderOverride(string name)

    public bool HasStylebox(string name, string type = "")

    public bool HasStyleboxOverride(string name)

    public bool IsClippingContents()

Getter for RectClipContent

    public void MinimumSizeChanged()

    public void ReleaseFocus()

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

    public void SetAnchor(Margin margin, float anchor, bool keepMargin = false, bool pushOppositeAnchor = true)

    public void SetAnchorAndMargin(Margin margin, float anchor, float offset, bool pushOppositeAnchor = false)

    public void SetAnchorsAndMarginsPreset(LayoutPreset preset, LayoutPresetMode resizeMode = LayoutPresetMode.Minsize, int margin = 0)

    public void SetAnchorsPreset(LayoutPreset preset, bool keepMargin = false)

    public void SetBegin(Vector2 position)

Sets MARGIN_LEFT and MARGIN_TOP at the same time. This is a helper (see SetMargin(Godot.Margin, float)).

    public void SetClipContents(bool enable)

Setter for RectClipContent

    public void SetCustomMinimumSize(Vector2 size)

Setter for RectMinSize

    public void SetDefaultCursorShape(CursorShape shape)

Setter for MouseDefaultCursorShape

    public void SetDragForwarding(Control target)

    public void SetDragPreview(Control control)

    public void SetEnd(Vector2 position)

Sets MARGIN_RIGHT and MARGIN_BOTTOM at the same time. This is a helper (see SetMargin(Godot.Margin, float)).

    public void SetFocusMode(FocusModeEnum mode)

Setter for FocusMode

    public void SetFocusNeighbour(Margin margin, NodePath neighbour)

    public void SetFocusNext(NodePath next)

Setter for FocusNext

    public void SetFocusPrevious(NodePath previous)

Setter for FocusPrevious

    public void SetGlobalPosition(Vector2 position)

Setter for RectGlobalPosition

    public void SetHGrowDirection(GrowDirection direction)

Setter for GrowHorizontal

    public void SetHSizeFlags(int flags)

Setter for SizeFlagsHorizontal

    public void SetMargin(Margin margin, float offset)

    public void SetMarginsPreset(LayoutPreset preset, LayoutPresetMode resizeMode = LayoutPresetMode.Minsize, int margin = 0)

    public void SetMouseFilter(MouseFilterEnum filter)

Setter for MouseFilter

    public void SetPivotOffset(Vector2 pivotOffset)

Setter for RectPivotOffset

    public void SetPosition(Vector2 position)

Setter for RectPosition

    public void SetRotation(float radians)

Set the rotation (in radians).

    public void SetRotationDegrees(float degrees)

Setter for RectRotation

    public void SetScale(Vector2 scale)

Setter for RectScale

    public void SetSize(Vector2 size)

Setter for RectSize

    public void SetStretchRatio(float ratio)

Setter for SizeFlagsStretchRatio

    public void SetTheme(Theme theme)

Setter for Theme

    public void SetTooltip(string tooltip)

Setter for HintTooltip

    public void SetVGrowDirection(GrowDirection direction)

Setter for GrowVertical

    public void SetVSizeFlags(int flags)

Setter for SizeFlagsVertical

    public void ShowModal(bool exclusive = false)

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

    public void WarpMouse(Vector2 toPosition)

Inner Types

Anchor

Name Value Description
Begin 0 Snaps one of the 4 anchor’s sides to the origin of the node’s [code]Rect[/code], in the top left. Use it with one of the [code]anchor_*[/code] member variables, like [member anchor_left]. To change all 4 anchors at once, use [method set_anchors_preset].
End 1 Snaps one of the 4 anchor’s sides to the end of the node’s [code]Rect[/code], in the bottom right. Use it with one of the [code]anchor_*[/code] member variables, like [member anchor_left]. To change all 4 anchors at once, use [method set_anchors_preset].

CursorShape

Name Value Description
Arrow 0 Show the system’s arrow mouse cursor when the user hovers the node. Use with [method set_default_cursor_shape].
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.
PointingHand 2 Show the system’s pointing hand mouse cursor when the user hovers the node.
Cross 3 Show the system’s cross mouse cursor when the user hovers the node.
Wait 4 Show the system’s wait mouse cursor, often an hourglass, when the user hovers the node.
Busy 5 Show the system’s busy mouse cursor when the user hovers the node. Often an hourglass.
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.
CanDrop 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.
Forbidden 8 Show the system’s forbidden mouse cursor when the user hovers the node. Often a crossed circle.
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.
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.
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.
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 [code]CURSOR_BDIAGSIZE[/code]. It tells the user they can resize the window or the panel both horizontally and vertically.
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.
Vsplit 14 Show the system’s vertical split mouse cursor when the user hovers the node. On Windows, it’s the same as [code]CURSOR_VSIZE[/code].
Hsplit 15 Show the system’s horizontal split mouse cursor when the user hovers the node. On Windows, it’s the same as [code]CURSOR_HSIZE[/code].
Help 16 Show the system’s help mouse cursor when the user hovers the node, a question mark.

FocusModeEnum

Name Value Description
None 0 The node cannot grab focus. Use with [member set_focus_mode].
Click 1 The node can only grab focus on mouse clicks. Use with [member set_focus_mode].
All 2 The node can grab focus on mouse click or using the arrows and the Tab keys on the keyboard. Use with [member set_focus_mode].

GrowDirection

Name Value Description
Begin 0  
End 1  

LayoutPreset

Name Value Description
TopLeft 0 Snap all 4 anchors to the top-left of the parent container’s bounds. Use with [method set_anchors_preset].
TopRight 1 Snap all 4 anchors to the top-right of the parent container’s bounds. Use with [method set_anchors_preset].
BottomLeft 2 Snap all 4 anchors to the bottom-left of the parent container’s bounds. Use with [method set_anchors_preset].
BottomRight 3 Snap all 4 anchors to the bottom-right of the parent container’s bounds. Use with [method set_anchors_preset].
CenterLeft 4 Snap all 4 anchors to the center of the left edge of the parent container’s bounds. Use with [method set_anchors_preset].
CenterTop 5 Snap all 4 anchors to the center of the top edge of the parent container’s bounds. Use with [method set_anchors_preset].
CenterRight 6 Snap all 4 anchors to the center of the right edge of the parent container’s bounds. Use with [method set_anchors_preset].
CenterBottom 7 Snap all 4 anchors to the center of the bottom edge of the parent container’s bounds. Use with [method set_anchors_preset].
Center 8 Snap all 4 anchors to the center of the parent container’s bounds. Use with [method set_anchors_preset].
LeftWide 9 Snap all 4 anchors to the left edge of the parent container. The left margin becomes relative to the left edge and the top margin relative to the top left corner of the node’s parent. Use with [method set_anchors_preset].
TopWide 10 Snap all 4 anchors to the top edge of the parent container. The left margin becomes relative to the top left corner, the top margin relative to the top edge, and the right margin relative to the top right corner of the node’s parent. Use with [method set_anchors_preset].
RightWide 11 Snap all 4 anchors to the right edge of the parent container. The right margin becomes relative to the right edge and the top margin relative to the top right corner of the node’s parent. Use with [method set_anchors_preset].
BottomWide 12 Snap all 4 anchors to the bottom edge of the parent container. The left margin becomes relative to the bottom left corner, the bottom margin relative to the bottom edge, and the right margin relative to the bottom right corner of the node’s parent. Use with [method set_anchors_preset].
VcenterWide 13 Snap all 4 anchors to a vertical line that cuts the parent container in half. Use with [method set_anchors_preset].
HcenterWide 14 Snap all 4 anchors to a horizontal line that cuts the parent container in half. Use with [method set_anchors_preset].
Wide 15 Snap all 4 anchors to the respective corners of the parent container. Set all 4 margins to 0 after you applied this preset and the [code]Control[/code] will fit its parent container. Use with [method set_anchors_preset].

LayoutPresetMode

Name Value Description
Minsize 0  
KeepWidth 1  
KeepHeight 2  
KeepSize 3  

MouseFilterEnum

Name Value Description
Stop 0 The control will receive mouse button input events through [method _gui_input] if clicked on. These events are automatically marked as handled and they will not propagate further to other controls.
Pass 1 The control will receive mouse button input events through [method _gui_input] if clicked on. If this control does not handle the event, the parent control (if any) will be considered for a mouse click, and so on until there is no more parent control to potentially handle it. Even if no control handled it at all, the event will still be handled automatically.
Ignore 2 The control will not receive mouse button input events through [method _gui_input] and will not block other controls from receiving these events. These events will also not be handled automatically.

SizeFlags

Name Value Description
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 [member size_flags_horizontal] and [member size_flags_vertical].
Expand 2 Tells the parent [Container] to let this node take all the available space on the axis you flag. If multiple neighboring nodes are set to expand, they’ll share the space based on their stretch ratio. See [member size_flags_stretch_ratio]. Use with [member size_flags_horizontal] and [member size_flags_vertical].
ExpandFill 3 Sets the node’s size flags to both fill and expand. See the 2 constants above for more information.
ShrinkCenter 4 Tells the parent [Container] to center the node in itself. It centers the [code]Control[/code] based on its bounding box, so it doesn’t work with the fill or expand size flags. Use with [member size_flags_horizontal] and [member size_flags_vertical].
ShrinkEnd 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 [member size_flags_horizontal] and [member size_flags_vertical].
Tags: