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

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(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 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(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 NotificationScrollBegin = 47

    public const Int32 NotificationScrollEnd = 48

    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" (InputEvent event)

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

    public float AnchorLeft { get; set; }

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

    public float AnchorRight { get; set; }

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

    public float AnchorTop { get; set; }

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

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

    public NodePath FocusNeighbourLeft { get; set; }

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

    public NodePath FocusNeighbourRight { get; set; }

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

    public NodePath FocusNeighbourTop { get; set; }

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

    public NodePath FocusNext { get; set; }

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

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

    public NodePath FocusPrevious { get; set; }

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

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

    public GrowDirection GrowHorizontal { get; set; }

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

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

    public float MarginBottom { get; set; }

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

    public float MarginLeft { get; set; }

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

    public float MarginRight { get; set; }

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

    public float MarginTop { get; set; }

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

    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.

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

    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. Also controls whether the control can receive the mouse_entered, and mouse_exited signals. See the constants to learn what each does.

    public bool RectClipContent { get; set; }

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

    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 SizeFlags 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 [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.

    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 SizeFlags 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 bool _ClipsInput()

Virtual method to be implemented by the user. Returns whether _GuiInput(Godot.InputEvent) 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.

    public virtual Vector2 _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].

    public virtual void _GuiInput(InputEvent @event)

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

Example: clicking a control.

[codeblock]

func _gui_input(event):

if event is InputEventMouseButton:

if event.button_index == BUTTON_LEFT and event.pressed:

print(“I’ve been clicked D:”)

[/codeblock]

The event won’t trigger if:

  • clicking outside the control (see HasPoint(Godot.Vector2));

  • control has MouseFilter set to [constant MOUSE_FILTER_IGNORE];

  • control is obstructed by another Control on top of it, which doesn’t have MouseFilter set to [constant MOUSE_FILTER_IGNORE];

  • control’s parent has MouseFilter set to [constant MOUSE_FILTER_STOP] or has accepted the event;

  • it happens outside parent’s rectangle and the parent has either RectClipContent or _ClipsInput() enabled.

    public virtual Object _MakeCustomTooltip(string forText)

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 forText 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:

[codeblock]

func _make_custom_tooltip(for_text):

var label = Label.new()

label.text = for_text

return label

[/codeblock]

Example of usage with custom scene instance:

[codeblock]

func _make_custom_tooltip(for_text):

var tooltip = preload(“SomeTooltipScene.tscn”).instance()

tooltip.get_node(“Label”).text = for_text

return tooltip

[/codeblock]

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

    public void AddConstantOverride(string name, int constant)

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.

    public void AddFontOverride(string name, Font font)

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.

    public void AddIconOverride(string name, Texture texture)

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.

    public void AddShaderOverride(string name, Shader shader)

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.

    public void AddStyleboxOverride(string name, StyleBox stylebox)

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.

    public virtual bool CanDropData(Vector2 position, object data)

Godot calls this method to test if data from a control’s GetDragData(Godot.Vector2) 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(Godot.Vector2, object).

[codeblock]

func can_drop_data(position, data):

Check position if it is relevant to you

Otherwise, just check data

return typeof(data) == TYPE_DICTIONARY and data.has(“expected”)

[/codeblock]

    public virtual void DropData(Vector2 position, object data)

Godot calls this method to pass you the data from a control’s GetDragData(Godot.Vector2) result. Godot first calls CanDropData(Godot.Vector2, object) to test if data is allowed to drop at position where position is local to this control.

[codeblock]

func can_drop_data(position, data):

return typeof(data) == TYPE_DICTIONARY and data.has(“color”)

func drop_data(position, data):

color = data[“color”]

[/codeblock]

    public void ForceDrag(object data, Control preview)

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

The methods CanDropData(Godot.Vector2, object) and DropData(Godot.Vector2, object) must be implemented on controls that want to receive drop data.

    [Obsolete("GetAnchor is deprecated. Use the AnchorBottom property instead.")]
    public float GetAnchor(Margin margin)

Returns the anchor identified by margin constant from [enum Margin] enum. A getter method for AnchorBottom, AnchorLeft, AnchorRight and AnchorTop.

    public Vector2 GetBegin()

Returns MarginLeft and MarginTop. See also RectPosition.

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

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

[codeblock]

func _ready():

modulate = get_color(“font_color”, “Button”) #get the color defined for button fonts

[/codeblock]

    public Vector2 GetCombinedMinimumSize()

Returns combined minimum size from RectMinSize and _GetMinimumSize().

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

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

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

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

    [Obsolete("GetCustomMinimumSize is deprecated. Use the RectMinSize property instead.")]
    public Vector2 GetCustomMinimumSize()

Getter for RectMinSize

    [Obsolete("GetDefaultCursorShape is deprecated. Use the MouseDefaultCursorShape property instead.")]
    public CursorShape GetDefaultCursorShape()

Getter for MouseDefaultCursorShape

    public virtual object GetDragData(Vector2 position)

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(Godot.Vector2, object) and DropData(Godot.Vector2, object). position is local to this control. Drag may be forced with ForceDrag(object, Godot.Control).

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

[codeblock]

func get_drag_data(position):

var mydata = make_data()

set_drag_preview(make_preview(mydata))

return mydata

[/codeblock]

    public Vector2 GetEnd()

Returns MarginRight and MarginBottom.

    [Obsolete("GetFocusMode is deprecated. Use the FocusMode property instead.")]
    public FocusModeEnum GetFocusMode()

Getter for FocusMode

    [Obsolete("GetFocusNeighbour is deprecated. Use the FocusNeighbourBottom property instead.")]
    public NodePath GetFocusNeighbour(Margin margin)

Returns the focus neighbour identified by margin constant from [enum Margin] enum. A getter method for FocusNeighbourBottom, FocusNeighbourLeft, FocusNeighbourRight and FocusNeighbourTop.

    [Obsolete("GetFocusNext is deprecated. Use the FocusNext property instead.")]
    public NodePath GetFocusNext()

Getter for FocusNext

    public Control GetFocusOwner()

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

    [Obsolete("GetFocusPrevious is deprecated. Use the FocusPrevious property instead.")]
    public NodePath GetFocusPrevious()

Getter for FocusPrevious

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

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

    [Obsolete("GetGlobalPosition is deprecated. Use the RectGlobalPosition property instead.")]
    public Vector2 GetGlobalPosition()

Getter for RectGlobalPosition

    public Rect2 GetGlobalRect()

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

    [Obsolete("GetHGrowDirection is deprecated. Use the GrowHorizontal property instead.")]
    public GrowDirection GetHGrowDirection()

Getter for GrowHorizontal

    [Obsolete("GetHSizeFlags is deprecated. Use the SizeFlagsHorizontal property instead.")]
    public int GetHSizeFlags()

Getter for SizeFlagsHorizontal

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

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

    [Obsolete("GetMargin is deprecated. Use the MarginBottom property instead.")]
    public float GetMargin(Margin margin)

Returns the anchor identified by margin constant from [enum Margin] enum. A getter method for MarginBottom, MarginLeft, MarginRight and MarginTop.

    public Vector2 GetMinimumSize()

Returns the minimum size for this control. See RectMinSize.

    [Obsolete("GetMouseFilter is deprecated. Use the MouseFilter property instead.")]
    public MouseFilterEnum GetMouseFilter()

Getter for MouseFilter

    public Vector2 GetParentAreaSize()

Returns the width/height occupied in the parent control.

    public Control GetParentControl()

Returns the parent control node.

    [Obsolete("GetPivotOffset is deprecated. Use the RectPivotOffset property instead.")]
    public Vector2 GetPivotOffset()

Getter for RectPivotOffset

    [Obsolete("GetPosition is deprecated. Use the RectPosition property instead.")]
    public Vector2 GetPosition()

Getter for RectPosition

    public Rect2 GetRect()

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

    public float GetRotation()

Returns the rotation (in radians).

    [Obsolete("GetRotationDegrees is deprecated. Use the RectRotation property instead.")]
    public float GetRotationDegrees()

Getter for RectRotation

    [Obsolete("GetScale is deprecated. Use the RectScale property instead.")]
    public Vector2 GetScale()

Getter for RectScale

    [Obsolete("GetSize is deprecated. Use the RectSize property instead.")]
    public Vector2 GetSize()

Getter for RectSize

    [Obsolete("GetStretchRatio is deprecated. Use the SizeFlagsStretchRatio property instead.")]
    public float GetStretchRatio()

Getter for SizeFlagsStretchRatio

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

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

    [Obsolete("GetTheme is deprecated. Use the Theme property instead.")]
    public Theme GetTheme()

Getter for Theme

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

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

    [Obsolete("GetVGrowDirection is deprecated. Use the GrowVertical property instead.")]
    public GrowDirection GetVGrowDirection()

Getter for GrowVertical

    [Obsolete("GetVSizeFlags is deprecated. Use the SizeFlagsVertical property instead.")]
    public int GetVSizeFlags()

Getter for SizeFlagsVertical

    public void GrabClickFocus()

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

[codeblock]

func _process(delta):

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

[/codeblock]

    public void GrabFocus()

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

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

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

    public bool HasColorOverride(string name)

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

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

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

    public bool HasConstantOverride(string name)

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

    public bool HasFocus()

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

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

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

    public bool HasFontOverride(string name)

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

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

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

    public bool HasIconOverride(string name)

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

    public virtual bool HasPoint(Vector2 point)

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.

Node: If you want to check if a point is inside the control, you can use get_rect().has_point(point).

    public bool HasShaderOverride(string name)

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

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

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

    public bool HasStyleboxOverride(string name)

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

    [Obsolete("IsClippingContents is deprecated. Use the RectClipContent property instead.")]
    public bool IsClippingContents()

Getter for RectClipContent

    public void 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.

    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)

Sets the anchor identified by margin constant from [enum Margin] enum to value anchor. A setter method for AnchorBottom, AnchorLeft, AnchorRight and AnchorTop.

If keepMargin is true, margins 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 SetAnchorAndMargin(Margin margin, float anchor, float offset, bool pushOppositeAnchor = false)

Works the same as SetAnchor(Godot.Margin, float, bool, bool), but instead of keep_margin argument and automatic update of margin, it allows to set the margin offset yourself (see SetMargin(Godot.Margin, float)).

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

Sets both anchor preset and margin preset. See SetAnchorsPreset(Godot.Control.LayoutPreset, bool) and SetMarginsPreset(Godot.Control.LayoutPreset, Godot.Control.LayoutPresetMode, int).

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

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

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

    public void SetBegin(Vector2 position)

Sets MarginLeft and MarginTop at the same time. Equivalent of changing RectPosition.

    [Obsolete("SetClipContents is deprecated. Use the RectClipContent property instead.")]
    public void SetClipContents(bool enable)

Setter for RectClipContent

    [Obsolete("SetCustomMinimumSize is deprecated. Use the RectMinSize property instead.")]
    public void SetCustomMinimumSize(Vector2 size)

Setter for RectMinSize

    [Obsolete("SetDefaultCursorShape is deprecated. Use the MouseDefaultCursorShape property instead.")]
    public void SetDefaultCursorShape(CursorShape shape)

Setter for MouseDefaultCursorShape

    public void SetDragForwarding(Control target)

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

Forwarding can be implemented in the target control similar to the methods GetDragData(Godot.Vector2), CanDropData(Godot.Vector2, object), and DropData(Godot.Vector2, object) 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

[codeblock]

ThisControl.gd

extends Control

func _ready():

set_drag_forwarding(target_control)

TargetControl.gd

extends Control

func can_drop_data_fw(position, data, from_control):

return true

func drop_data_fw(position, data, from_control):

my_handle_data(data)

func get_drag_data_fw(position, from_control):

set_drag_preview(my_preview)

return my_data()

[/codeblock]

    public void SetDragPreview(Control control)

Shows the given control at the mouse pointer. A good time to call this method is in GetDragData(Godot.Vector2).

    public void SetEnd(Vector2 position)

Sets MarginRight and MarginBottom at the same time.

    [Obsolete("SetFocusMode is deprecated. Use the FocusMode property instead.")]
    public void SetFocusMode(FocusModeEnum mode)

Setter for FocusMode

    [Obsolete("SetFocusNeighbour is deprecated. Use the FocusNeighbourBottom property instead.")]
    public void SetFocusNeighbour(Margin margin, NodePath neighbour)

Sets the anchor identified by margin constant from [enum Margin] enum to Control at neighbor node path. A setter method for FocusNeighbourBottom, FocusNeighbourLeft, FocusNeighbourRight and FocusNeighbourTop.

    [Obsolete("SetFocusNext is deprecated. Use the FocusNext property instead.")]
    public void SetFocusNext(NodePath next)

Setter for FocusNext

    [Obsolete("SetFocusPrevious is deprecated. Use the FocusPrevious property instead.")]
    public void SetFocusPrevious(NodePath previous)

Setter for FocusPrevious

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

Sets the RectGlobalPosition to given position.

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

    [Obsolete("SetHGrowDirection is deprecated. Use the GrowHorizontal property instead.")]
    public void SetHGrowDirection(GrowDirection direction)

Setter for GrowHorizontal

    [Obsolete("SetHSizeFlags is deprecated. Use the SizeFlagsHorizontal property instead.")]
    public void SetHSizeFlags(int flags)

Setter for SizeFlagsHorizontal

    [Obsolete("SetMargin is deprecated. Use the MarginBottom property instead.")]
    public void SetMargin(Margin margin, float offset)

Sets the margin identified by margin constant from [enum Margin] enum to given offset. A setter method for MarginBottom, MarginLeft, MarginRight and MarginTop.

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

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

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

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

    [Obsolete("SetMouseFilter is deprecated. Use the MouseFilter property instead.")]
    public void SetMouseFilter(MouseFilterEnum filter)

Setter for MouseFilter

    [Obsolete("SetPivotOffset is deprecated. Use the RectPivotOffset property instead.")]
    public void SetPivotOffset(Vector2 pivotOffset)

Setter for RectPivotOffset

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

Sets the RectPosition to given position.

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

    public void SetRotation(float radians)

Sets the rotation (in radians).

    [Obsolete("SetRotationDegrees is deprecated. Use the RectRotation property instead.")]
    public void SetRotationDegrees(float degrees)

Setter for RectRotation

    [Obsolete("SetScale is deprecated. Use the RectScale property instead.")]
    public void SetScale(Vector2 scale)

Setter for RectScale

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

Sets the size (see RectSize).

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

    [Obsolete("SetStretchRatio is deprecated. Use the SizeFlagsStretchRatio property instead.")]
    public void SetStretchRatio(float ratio)

Setter for SizeFlagsStretchRatio

    [Obsolete("SetTheme is deprecated. Use the Theme property instead.")]
    public void SetTheme(Theme theme)

Setter for Theme

    [Obsolete("SetTooltip is deprecated. Use the HintTooltip property instead.")]
    public void SetTooltip(string tooltip)

Setter for HintTooltip

    [Obsolete("SetVGrowDirection is deprecated. Use the GrowVertical property instead.")]
    public void SetVGrowDirection(GrowDirection direction)

Setter for GrowVertical

    [Obsolete("SetVSizeFlags is deprecated. Use the SizeFlagsVertical property instead.")]
    public void SetVSizeFlags(int flags)

Setter for SizeFlagsVertical

    public void ShowModal(bool exclusive = false)

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

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

    public void WarpMouse(Vector2 toPosition)

Moves the mouse cursor to toPosition, relative to RectPosition of this Control.

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 [member mouse_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 [constant CURSOR_BDIAGSIZE]. 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 [constant CURSOR_VSIZE].
Hsplit 15 Show the system’s horizontal split mouse cursor when the user hovers the node. On Windows, it’s the same as [constant CURSOR_HSIZE].
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 focus_mode].
Click 1 The node can only grab focus on mouse clicks. Use with [member 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 focus_mode].

GrowDirection

Name Value Description
Begin 0 The control will grow to the left or top to make up if its minimum size is changed to be greater than its current size on the respective axis.
End 1 The control will grow to the right or bottom to make up if its minimum size is changed to be greater than its current size on the respective axis.
Both 2 The control will grow in both directions equally to make up if its minimum size is changed to be greater than its current size.

LayoutPreset

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

LayoutPresetMode

Name Value Description
Minsize 0 The control will be resized to its minimum size.
KeepWidth 1 The control’s width will not change.
KeepHeight 2 The control’s height will not change.
KeepSize 3 The control’s size will not change.

MouseFilterEnum

Name Value Description
Stop 0 The control will receive mouse button input events through [method _gui_input] if clicked on. And the control will receive the [signal mouse_entered] and [signal mouse_exited] signals. These events are automatically marked as handled, and they will not propagate further to other controls. This also results in blocking signals in other controls.
Pass 1 The control will receive mouse button input events through [method _gui_input] if clicked on. And the control will receive the [signal mouse_entered] and [signal mouse_exited] signals. If this control does not handle the event, the parent control (if any) will be considered, and so on until there is no more parent control to potentially handle it. This also allows signals to fire in other controls. Even if no control handled it at all, the event will still be handled automatically, so unhandled input will not be fired.
Ignore 2 The control will not receive mouse button input events through [method _gui_input]. The control will also not receive the [signal mouse_entered] nor [signal mouse_exited] signals. This will not block other controls from receiving these events or firing the signals. Ignored events will 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 control 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: