Table of Contents

Class Control

Namespace
Godot
Assembly
GodotSharp.dll

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

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

User Interface nodes and input

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

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

Call AcceptEvent() so no other node receives the event. Once you accept an input, it becomes handled so _UnhandledInput(InputEvent) will not process it.

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

Sets MouseFilter to 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_theme_*_override methods, like AddThemeFontOverride(StringName, Font). You can override the theme with the Inspector.

Note: Theme items are notGodotObject properties. This means you can't access their values using Get(StringName) and Set(StringName, Variant). Instead, use the get_theme_* and add_theme_*_override methods provided by this class.

public class Control : CanvasItem, IDisposable
Inheritance
Control
Implements
Derived
Inherited Members

Constructors

Control()

public Control()

Fields

NotificationFocusEnter

Sent when the node grabs focus.

public const long NotificationFocusEnter = 43

Field Value

long

NotificationFocusExit

Sent when the node loses focus.

public const long NotificationFocusExit = 44

Field Value

long

NotificationLayoutDirectionChanged

Sent when control layout direction is changed.

public const long NotificationLayoutDirectionChanged = 49

Field Value

long

NotificationMouseEnter

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

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

See also NotificationMouseEnterSelf.

public const long NotificationMouseEnter = 41

Field Value

long

NotificationMouseEnterSelf

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

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

See also NotificationMouseEnter.

public const long NotificationMouseEnterSelf = 60

Field Value

long

NotificationMouseExit

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

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

See also NotificationMouseExitSelf.

public const long NotificationMouseExit = 42

Field Value

long

NotificationMouseExitSelf

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

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

See also NotificationMouseExit.

public const long NotificationMouseExitSelf = 61

Field Value

long

NotificationResized

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

public const long NotificationResized = 40

Field Value

long

NotificationScrollBegin

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

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

public const long NotificationScrollBegin = 47

Field Value

long

NotificationScrollEnd

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

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

public const long NotificationScrollEnd = 48

Field Value

long

NotificationThemeChanged

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

- The Theme property is changed on this node or any of its ancestors.

- The ThemeTypeVariation property is changed on this node.

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

- The node enters the scene tree.

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

public const long NotificationThemeChanged = 45

Field Value

long

Properties

AnchorBottom

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

public float AnchorBottom { get; set; }

Property Value

float

AnchorLeft

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

public float AnchorLeft { get; set; }

Property Value

float

AnchorRight

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

public float AnchorRight { get; set; }

Property Value

float

AnchorTop

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

public float AnchorTop { get; set; }

Property Value

float

AnchorsPreset

public int AnchorsPreset { get; set; }

Property Value

int

AutoTranslate

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

Also decides if the node's strings should be parsed for POT generation.

public bool AutoTranslate { get; set; }

Property Value

bool

ClipContents

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

public bool ClipContents { get; set; }

Property Value

bool

CustomMinimumSize

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 CustomMinimumSize { get; set; }

Property Value

Vector2

FocusMode

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

public Control.FocusModeEnum FocusMode { get; set; }

Property Value

Control.FocusModeEnum

FocusNeighborBottom

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

public NodePath FocusNeighborBottom { get; set; }

Property Value

NodePath

FocusNeighborLeft

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

public NodePath FocusNeighborLeft { get; set; }

Property Value

NodePath

FocusNeighborRight

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

public NodePath FocusNeighborRight { get; set; }

Property Value

NodePath

FocusNeighborTop

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

public NodePath FocusNeighborTop { get; set; }

Property Value

NodePath

FocusNext

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

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

public NodePath FocusNext { get; set; }

Property Value

NodePath

FocusPrevious

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

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

public NodePath FocusPrevious { get; set; }

Property Value

NodePath

GlobalPosition

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

public Vector2 GlobalPosition { get; set; }

Property Value

Vector2

GrowHorizontal

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.

public Control.GrowDirection GrowHorizontal { get; set; }

Property Value

Control.GrowDirection

GrowVertical

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.

public Control.GrowDirection GrowVertical { get; set; }

Property Value

Control.GrowDirection

LayoutDirection

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

public Control.LayoutDirectionEnum LayoutDirection { get; set; }

Property Value

Control.LayoutDirectionEnum

LayoutMode

public int LayoutMode { get; set; }

Property Value

int

LocalizeNumeralSystem

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

Note: Numbers within the text are not automatically converted, it can be done manually, using FormatNumber(string, string).

public bool LocalizeNumeralSystem { get; set; }

Property Value

bool

MouseDefaultCursorShape

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.

public Control.CursorShape MouseDefaultCursorShape { get; set; }

Property Value

Control.CursorShape

MouseFilter

Controls whether the control will be able to receive mouse button input events through _GuiInput(InputEvent) 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.

public Control.MouseFilterEnum MouseFilter { get; set; }

Property Value

Control.MouseFilterEnum

MouseForcePassScrollEvents

When enabled, scroll wheel events processed by _GuiInput(InputEvent) will be passed to the parent control even if MouseFilter is set to Stop. As it defaults to true, this allows nested scrollable containers to work out of the box.

You should disable it on the root of your UI if you do not want scroll events to go to the _UnhandledInput(InputEvent) processing.

public bool MouseForcePassScrollEvents { get; set; }

Property Value

bool

OffsetBottom

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

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

public float OffsetBottom { get; set; }

Property Value

float

OffsetLeft

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

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

public float OffsetLeft { get; set; }

Property Value

float

OffsetRight

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

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

public float OffsetRight { get; set; }

Property Value

float

OffsetTop

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

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

public float OffsetTop { get; set; }

Property Value

float

PivotOffset

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

public Vector2 PivotOffset { get; set; }

Property Value

Vector2

Position

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

public Vector2 Position { get; set; }

Property Value

Vector2

Rotation

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

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

public float Rotation { get; set; }

Property Value

float

RotationDegrees

Helper property to access Rotation in degrees instead of radians.

public float RotationDegrees { get; set; }

Property Value

float

Scale

The node's scale, relative to its Size. Change this property to scale the node around its PivotOffset. The Control's TooltipText will also scale according to this value.

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

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

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

public Vector2 Scale { get; set; }

Property Value

Vector2

ShortcutContext

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

public Node ShortcutContext { get; set; }

Property Value

Node

Size

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

public Vector2 Size { get; set; }

Property Value

Vector2

SizeFlagsHorizontal

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

public Control.SizeFlags SizeFlagsHorizontal { get; set; }

Property Value

Control.SizeFlags

SizeFlagsStretchRatio

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

public float SizeFlagsStretchRatio { get; set; }

Property Value

float

SizeFlagsVertical

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

public Control.SizeFlags SizeFlagsVertical { get; set; }

Property Value

Control.SizeFlags

Theme

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

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

public Theme Theme { get; set; }

Property Value

Theme

ThemeTypeVariation

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

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

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

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

public StringName ThemeTypeVariation { get; set; }

Property Value

StringName

TooltipText

The default tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that the MouseFilter property is not Ignore. The time required for the tooltip to appear can be changed with the ProjectSettings.gui/timers/tooltip_delay_sec option. See also GetTooltip(Vector2?).

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

var styleBox = new StyleBoxFlat();
  styleBox.SetBgColor(new Color(1, 1, 0));
  styleBox.SetBorderWidthAll(2);
  // We assume here that the `Theme` property has been assigned a custom Theme beforehand.
  Theme.SetStyleBox("panel", "TooltipPanel", styleBox);
  Theme.SetColor("font_color", "TooltipLabel", new Color(0, 1, 1));
public string TooltipText { get; set; }

Property Value

string

Methods

AcceptEvent()

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

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

public void AcceptEvent()

AddThemeColorOverride(StringName, Color)

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

See also GetThemeColor(StringName, StringName).

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

// Given the child Label node "MyLabel", override its font color with a custom value.
  GetNode<Label>("MyLabel").AddThemeColorOverride("font_color", new Color(1, 0.5f, 0));
  // Reset the font color of the child label.
  GetNode<Label>("MyLabel").RemoveThemeColorOverride("font_color");
  // Alternatively it can be overridden with the default value from the Label type.
  GetNode<Label>("MyLabel").AddThemeColorOverride("font_color", GetThemeColor("font_color", "Label"));
public void AddThemeColorOverride(StringName name, Color color)

Parameters

name StringName
color Color

AddThemeConstantOverride(StringName, int)

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

See also GetThemeConstant(StringName, StringName).

public void AddThemeConstantOverride(StringName name, int constant)

Parameters

name StringName
constant int

AddThemeFontOverride(StringName, Font)

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

See also GetThemeFont(StringName, StringName).

public void AddThemeFontOverride(StringName name, Font font)

Parameters

name StringName
font Font

AddThemeFontSizeOverride(StringName, int)

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

See also GetThemeFontSize(StringName, StringName).

public void AddThemeFontSizeOverride(StringName name, int fontSize)

Parameters

name StringName
fontSize int

AddThemeIconOverride(StringName, Texture2D)

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

See also GetThemeIcon(StringName, StringName).

public void AddThemeIconOverride(StringName name, Texture2D texture)

Parameters

name StringName
texture Texture2D

AddThemeStyleboxOverride(StringName, StyleBox)

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

See also GetThemeStylebox(StringName, StringName).

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

// The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.
  // Resources are shared across instances, so we need to duplicate it
  // to avoid modifying the appearance of all other buttons.
  StyleBoxFlat newStyleboxNormal = GetNode<Button>("MyButton").GetThemeStylebox("normal").Duplicate() as StyleBoxFlat;
  newStyleboxNormal.BorderWidthTop = 3;
  newStyleboxNormal.BorderColor = new Color(0, 1, 0.5f);
  GetNode<Button>("MyButton").AddThemeStyleboxOverride("normal", newStyleboxNormal);
  // Remove the stylebox override.
  GetNode<Button>("MyButton").RemoveThemeStyleboxOverride("normal");
public void AddThemeStyleboxOverride(StringName name, StyleBox stylebox)

Parameters

name StringName
stylebox StyleBox

BeginBulkThemeOverride()

Prevents *_theme_*_override methods from emitting NotificationThemeChanged until EndBulkThemeOverride() is called.

public void BeginBulkThemeOverride()

EndBulkThemeOverride()

Ends a bulk theme override update. See BeginBulkThemeOverride().

public void EndBulkThemeOverride()

FindNextValidFocus()

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

public Control FindNextValidFocus()

Returns

Control

FindPrevValidFocus()

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

public Control FindPrevValidFocus()

Returns

Control

FindValidFocusNeighbor(Side)

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

Note: This is different from Godot.Control.GetFocusNeighbor(Godot.Side), which returns the path of a specified focus neighbor.

public Control FindValidFocusNeighbor(Side side)

Parameters

side Side

Returns

Control

ForceDrag(Variant, Control)

Forces drag and bypasses _GetDragData(Vector2) and SetDragPreview(Control) by passing data and preview. Drag will start even if the mouse is neither over nor pressed on this control.

The methods _CanDropData(Vector2, Variant) and _DropData(Vector2, Variant) must be implemented on controls that want to receive drop data.

public void ForceDrag(Variant data, Control preview)

Parameters

data Variant
preview Control

GetBegin()

Returns OffsetLeft and OffsetTop. See also Position.

public Vector2 GetBegin()

Returns

Vector2

GetCombinedMinimumSize()

Returns combined minimum size from CustomMinimumSize and GetMinimumSize().

public Vector2 GetCombinedMinimumSize()

Returns

Vector2

GetCursorShape(Vector2?)

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

public Control.CursorShape GetCursorShape(Vector2? position = null)

Parameters

position Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

Returns

Control.CursorShape

GetEnd()

public Vector2 GetEnd()

Returns

Vector2

GetGlobalRect()

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

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

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

public Rect2 GetGlobalRect()

Returns

Rect2

GetMinimumSize()

Returns the minimum size for this control. See CustomMinimumSize.

public Vector2 GetMinimumSize()

Returns

Vector2

GetParentAreaSize()

Returns the width/height occupied in the parent control.

public Vector2 GetParentAreaSize()

Returns

Vector2

GetParentControl()

Returns the parent control node.

public Control GetParentControl()

Returns

Control

GetRect()

Returns the position and size of the control in the coordinate system of the containing node. See Position, Scale and Size.

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

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

public Rect2 GetRect()

Returns

Rect2

GetScreenPosition()

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

Equals to GlobalPosition if the window is embedded (see GuiEmbedSubwindows).

Example usage for showing a popup:

popup_menu.position = get_screen_position() + get_local_mouse_position()
  popup_menu.reset_size()
  popup_menu.popup()
public Vector2 GetScreenPosition()

Returns

Vector2

GetThemeColor(StringName, StringName)

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

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

public override void _Ready()
  {
      // Get the font color defined for the current Control's class, if it exists.
      Modulate = GetThemeColor("font_color");
      // Get the font color defined for the Button class.
      Modulate = GetThemeColor("font_color", "Button");
  }
public Color GetThemeColor(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

Color

GetThemeConstant(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public int GetThemeConstant(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

int

GetThemeDefaultBaseScale()

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

See GetThemeColor(StringName, StringName) for details.

public float GetThemeDefaultBaseScale()

Returns

float

GetThemeDefaultFont()

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

See GetThemeColor(StringName, StringName) for details.

public Font GetThemeDefaultFont()

Returns

Font

GetThemeDefaultFontSize()

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

See GetThemeColor(StringName, StringName) for details.

public int GetThemeDefaultFontSize()

Returns

int

GetThemeFont(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public Font GetThemeFont(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

Font

GetThemeFontSize(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public int GetThemeFontSize(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

int

GetThemeIcon(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public Texture2D GetThemeIcon(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

Texture2D

GetThemeStylebox(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public StyleBox GetThemeStylebox(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

StyleBox

GetTooltip(Vector2?)

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

This method can be overridden to customize its behavior. See _GetTooltip(Vector2).

Note: If this method returns an empty string, no tooltip is displayed.

public string GetTooltip(Vector2? atPosition = null)

Parameters

atPosition Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

Returns

string

GrabClickFocus()

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

public override void _Process(double delta)
  {
      GrabClickFocus(); // When clicking another Control node, this node will be clicked instead.
  }
public void GrabClickFocus()

GrabFocus()

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

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

public void GrabFocus()

HasFocus()

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

public bool HasFocus()

Returns

bool

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasThemeColor(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeColor(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeColorOverride(StringName)

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

See AddThemeColorOverride(StringName, Color).

public bool HasThemeColorOverride(StringName name)

Parameters

name StringName

Returns

bool

HasThemeConstant(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeConstant(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeConstantOverride(StringName)

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

See AddThemeConstantOverride(StringName, int).

public bool HasThemeConstantOverride(StringName name)

Parameters

name StringName

Returns

bool

HasThemeFont(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeFont(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeFontOverride(StringName)

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

See AddThemeFontOverride(StringName, Font).

public bool HasThemeFontOverride(StringName name)

Parameters

name StringName

Returns

bool

HasThemeFontSize(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeFontSize(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeFontSizeOverride(StringName)

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

See AddThemeFontSizeOverride(StringName, int).

public bool HasThemeFontSizeOverride(StringName name)

Parameters

name StringName

Returns

bool

HasThemeIcon(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeIcon(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeIconOverride(StringName)

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

See AddThemeIconOverride(StringName, Texture2D).

public bool HasThemeIconOverride(StringName name)

Parameters

name StringName

Returns

bool

HasThemeStylebox(StringName, StringName)

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

See GetThemeColor(StringName, StringName) for details.

public bool HasThemeStylebox(StringName name, StringName themeType = null)

Parameters

name StringName
themeType StringName

Returns

bool

HasThemeStyleboxOverride(StringName)

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

See AddThemeStyleboxOverride(StringName, StyleBox).

public bool HasThemeStyleboxOverride(StringName name)

Parameters

name StringName

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsDragSuccessful()

Returns true if a drag operation is successful. Alternative to GuiIsDragSuccessful().

Best used with NotificationDragEnd.

public bool IsDragSuccessful()

Returns

bool

IsLayoutRtl()

Returns true if layout is right-to-left.

public bool IsLayoutRtl()

Returns

bool

ReleaseFocus()

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

public void ReleaseFocus()

RemoveThemeColorOverride(StringName)

Removes a local override for a theme Color with the specified name previously added by AddThemeColorOverride(StringName, Color) or via the Inspector dock.

public void RemoveThemeColorOverride(StringName name)

Parameters

name StringName

RemoveThemeConstantOverride(StringName)

Removes a local override for a theme constant with the specified name previously added by AddThemeConstantOverride(StringName, int) or via the Inspector dock.

public void RemoveThemeConstantOverride(StringName name)

Parameters

name StringName

RemoveThemeFontOverride(StringName)

Removes a local override for a theme Font with the specified name previously added by AddThemeFontOverride(StringName, Font) or via the Inspector dock.

public void RemoveThemeFontOverride(StringName name)

Parameters

name StringName

RemoveThemeFontSizeOverride(StringName)

Removes a local override for a theme font size with the specified name previously added by AddThemeFontSizeOverride(StringName, int) or via the Inspector dock.

public void RemoveThemeFontSizeOverride(StringName name)

Parameters

name StringName

RemoveThemeIconOverride(StringName)

Removes a local override for a theme icon with the specified name previously added by AddThemeIconOverride(StringName, Texture2D) or via the Inspector dock.

public void RemoveThemeIconOverride(StringName name)

Parameters

name StringName

RemoveThemeStyleboxOverride(StringName)

Removes a local override for a theme StyleBox with the specified name previously added by AddThemeStyleboxOverride(StringName, StyleBox) or via the Inspector dock.

public void RemoveThemeStyleboxOverride(StringName name)

Parameters

name StringName

ResetSize()

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

public void ResetSize()

SetAnchor(Side, float, bool, bool)

Sets the anchor for the specified Side to anchor. A setter method for AnchorBottom, AnchorLeft, AnchorRight and AnchorTop.

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

If pushOppositeAnchor 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 pushOppositeAnchor was false, the left anchor would get value 0.5.

public void SetAnchor(Side side, float anchor, bool keepOffset = false, bool pushOppositeAnchor = true)

Parameters

side Side
anchor float
keepOffset bool
pushOppositeAnchor bool

SetAnchorAndOffset(Side, float, float, bool)

Works the same as SetAnchor(Side, float, bool, bool), but instead of keep_offset argument and automatic update of offset, it allows to set the offset yourself (see Godot.Control.SetOffset(Godot.Side,System.Single)).

public void SetAnchorAndOffset(Side side, float anchor, float offset, bool pushOppositeAnchor = false)

Parameters

side Side
anchor float
offset float
pushOppositeAnchor bool

SetAnchorsAndOffsetsPreset(LayoutPreset, LayoutPresetMode, int)

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

Parameters

preset Control.LayoutPreset
resizeMode Control.LayoutPresetMode
margin int

SetAnchorsPreset(LayoutPreset, bool)

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

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

public void SetAnchorsPreset(Control.LayoutPreset preset, bool keepOffsets = false)

Parameters

preset Control.LayoutPreset
keepOffsets bool

SetBegin(Vector2)

Sets OffsetLeft and OffsetTop at the same time. Equivalent of changing Position.

public void SetBegin(Vector2 position)

Parameters

position Vector2

SetDragForwarding(Callable, Callable, Callable)

Forwards the handling of this control's _GetDragData(Vector2), _CanDropData(Vector2, Variant) and _DropData(Vector2, Variant) virtual functions to delegate callables.

For each argument, if not empty, the delegate callable is used, otherwise the local (virtual) function is used.

The function format for each callable should be exactly the same as the virtual functions described above.

public void SetDragForwarding(Callable dragFunc, Callable canDropFunc, Callable dropFunc)

Parameters

dragFunc Callable
canDropFunc Callable
dropFunc Callable

SetDragPreview(Control)

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

[Export]
  private Color _color = new Color(1, 0, 0, 1);

public override Variant _GetDragData(Vector2 atPosition) { // Use a control that is not in the tree var cpb = new ColorPickerButton(); cpb.Color = _color; cpb.Size = new Vector2(50, 50); SetDragPreview(cpb); return _color; }

public void SetDragPreview(Control control)

Parameters

control Control

SetEnd(Vector2)

Sets OffsetRight and OffsetBottom at the same time.

public void SetEnd(Vector2 position)

Parameters

position Vector2

SetGlobalPosition(Vector2, bool)

Sets the GlobalPosition to given position.

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

public void SetGlobalPosition(Vector2 position, bool keepOffsets = false)

Parameters

position Vector2
keepOffsets bool

SetOffsetsPreset(LayoutPreset, LayoutPresetMode, int)

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

Use parameter resizeMode 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. LeftWide.

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

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

Parameters

preset Control.LayoutPreset
resizeMode Control.LayoutPresetMode
margin int

SetPosition(Vector2, bool)

Sets the Position to given position.

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

public void SetPosition(Vector2 position, bool keepOffsets = false)

Parameters

position Vector2
keepOffsets bool

SetSize(Vector2, bool)

Sets the size (see Size).

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

public void SetSize(Vector2 size, bool keepOffsets = false)

Parameters

size Vector2
keepOffsets bool

UpdateMinimumSize()

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

public void UpdateMinimumSize()

WarpMouse(Vector2)

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

Note: WarpMouse(Vector2) is only supported on Windows, macOS and Linux. It has no effect on Android, iOS and Web.

public void WarpMouse(Vector2 position)

Parameters

position Vector2

_CanDropData(Vector2, Variant)

Godot calls this method to test if data from a control's _GetDragData(Vector2) can be dropped at atPosition. atPosition is local to this control.

This method should only be used to test the data. Process the data in _DropData(Vector2, Variant).

public override bool _CanDropData(Vector2 atPosition, Variant data)
  {
      // Check position if it is relevant to you
      // Otherwise, just check data
      return data.VariantType == Variant.Type.Dictionary && data.AsGodotDictionary().ContainsKey("expected");
  }
public virtual bool _CanDropData(Vector2 atPosition, Variant data)

Parameters

atPosition Vector2
data Variant

Returns

bool

_DropData(Vector2, Variant)

Godot calls this method to pass you the data from a control's _GetDragData(Vector2) result. Godot first calls _CanDropData(Vector2, Variant) to test if data is allowed to drop at atPosition where atPosition is local to this control.

public override bool _CanDropData(Vector2 atPosition, Variant data)
  {
      return data.VariantType == Variant.Type.Dictionary && dict.AsGodotDictionary().ContainsKey("color");
  }

public override void _DropData(Vector2 atPosition, Variant data) { Color color = data.AsGodotDictionary()["color"].AsColor(); }

public virtual void _DropData(Vector2 atPosition, Variant data)

Parameters

atPosition Vector2
data Variant

_GetDragData(Vector2)

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(Vector2, Variant) and _DropData(Vector2, Variant). atPosition is local to this control. Drag may be forced with ForceDrag(Variant, Control).

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

public override Variant _GetDragData(Vector2 atPosition)
  {
      var myData = MakeData(); // This is your custom method generating the drag data.
      SetDragPreview(MakePreview(myData)); // This is your custom method generating the preview of the drag data.
      return myData;
  }
public virtual Variant _GetDragData(Vector2 atPosition)

Parameters

atPosition Vector2

Returns

Variant

_GetMinimumSize()

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

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

public virtual Vector2 _GetMinimumSize()

Returns

Vector2

_GetTooltip(Vector2)

Virtual method to be implemented by the user. Returns the tooltip text for the position atPosition in control's local coordinates, which will typically appear when the cursor is resting over this control. See GetTooltip(Vector2?).

Note: If this method returns an empty string, no tooltip is displayed.

public virtual string _GetTooltip(Vector2 atPosition)

Parameters

atPosition Vector2

Returns

string

_GuiInput(InputEvent)

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

Example usage for clicking a control:

public override void _GuiInput(InputEvent @event)
  {
      if (@event is InputEventMouseButton mb)
      {
          if (mb.ButtonIndex == MouseButton.Left && mb.Pressed)
          {
              GD.Print("I've been clicked D:");
          }
      }
  }

The event won't trigger if:

* clicking outside the control (see _HasPoint(Vector2));

* control has MouseFilter set to Ignore;

* control is obstructed by another Control on top of it, which doesn't have MouseFilter set to Ignore;

* control's parent has MouseFilter set to Stop or has accepted the event;

* it happens outside the parent's rectangle and the parent has either ClipContents enabled.

Note: Event position is relative to the control origin.

public virtual void _GuiInput(InputEvent @event)

Parameters

event InputEvent

_HasPoint(Vector2)

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

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

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

public virtual bool _HasPoint(Vector2 point)

Parameters

point Vector2

Returns

bool

_MakeCustomTooltip(string)

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 forText includes the contents of the TooltipText 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 PopupPanel can be themed using SetStylebox(StringName, StringName, StyleBox) for the type "TooltipPanel" (see TooltipText 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 CustomMinimumSize to some non-zero value.

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

Example of usage with a custom-constructed node:

public override Control _MakeCustomTooltip(string forText)
  {
      var label = new Label();
      label.Text = forText;
      return label;
  }

Example of usage with a custom scene instance:

public override Control _MakeCustomTooltip(string forText)
  {
      Node tooltip = ResourceLoader.Load<PackedScene>("res://some_tooltip_scene.tscn").Instantiate();
      tooltip.GetNode<Label>("Label").Text = forText;
      return tooltip;
  }
public virtual GodotObject _MakeCustomTooltip(string forText)

Parameters

forText string

Returns

GodotObject

_StructuredTextParser(Array, string)

User defined BiDi algorithm override function.

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

public virtual Array<Vector3I> _StructuredTextParser(Array args, string text)

Parameters

args Array
text string

Returns

Array<Vector3I>

Events

FocusEntered

Emitted when the node gains focus.

public event Action FocusEntered

Event Type

Action

FocusExited

Emitted when the node loses focus.

public event Action FocusExited

Event Type

Action

GuiInput

Emitted when the node receives an InputEvent.

public event Control.GuiInputEventHandler GuiInput

Event Type

Control.GuiInputEventHandler

MinimumSizeChanged

Emitted when the node's minimum size changes.

public event Action MinimumSizeChanged

Event Type

Action

MouseEntered

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

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

public event Action MouseEntered

Event Type

Action

MouseExited

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

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

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

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

Event Type

Action

Resized

Emitted when the control changes size.

public event Action Resized

Event Type

Action

SizeFlagsChanged

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

public event Action SizeFlagsChanged

Event Type

Action

ThemeChanged

Emitted when the NotificationThemeChanged notification is sent.

public event Action ThemeChanged

Event Type

Action