Control
Inherits:CanvasItem<Node<Object
Inherited By:BaseButton,ColorRect,Container,GraphEdit,ItemList,Label,LineEdit,MenuBar,NinePatchRect,Panel,Range,ReferenceRect,RichTextLabel,Separator,TabBar,TextEdit,TextureRect,Tree,VideoStreamPlayer
Base class for all GUI controls. Adapts its position and size based on its parent control.
Description
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 fromControl andContainer nodes.
Note: Since bothNode2D andControl inherit fromCanvasItem, they share several concepts from the class such as theCanvasItem.z_index andCanvasItem.visible properties.
User Interface nodes and input
Godot propagates input events via viewports. EachViewport is responsible for propagatingInputEvents to their child nodes. As theSceneTree.root is aWindow, this already happens automatically for all UI elements in your game.
Input events are propagated through theSceneTree from the root node to all child nodes by callingNode._input(). For UI elements specifically, it makes more sense to override the virtual method_gui_input(), which filters out unrelated input events, such as by checking z-order,mouse_filter, focus, or if the event was inside of the control's bounding box.
Callaccept_event() so no other node receives the event. Once you accept an input, it becomes handled soNode._unhandled_input() will not process it.
Only oneControl node can be in focus. Only the node in focus will receive events. To get the focus, callgrab_focus().Control nodes lose focus when another node grabs it, or if you hide the node in focus.
Setsmouse_filter toMOUSE_FILTER_IGNORE to tell aControl 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. Thetheme of aControl node affects all of its direct and indirect children (as long as a chain of controls is uninterrupted). To override some of the theme items, call one of theadd_theme_*_override
methods, likeadd_theme_font_override(). You can also override theme items in the Inspector.
Note: Theme items arenotObject properties. This means you can't access their values usingObject.get() andObject.set(). Instead, use theget_theme_*
andadd_theme_*_override
methods provided by this class.
Tutorials
Properties
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
physics_interpolation_mode |
| |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
Methods
Signals
focus_entered()🔗
Emitted when the node gains focus.
focus_exited()🔗
Emitted when the node loses focus.
gui_input(event:InputEvent)🔗
Emitted when the node receives anInputEvent.
minimum_size_changed()🔗
Emitted when the node's minimum size changes.
mouse_entered()🔗
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 itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index doesn't affect, which Control receives the signal.
mouse_exited()🔗
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 itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index 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():ifnotRect2(Vector2(),size).has_point(get_local_mouse_position()):# Not hovering over area.
resized()🔗
Emitted when the control changes size.
size_flags_changed()🔗
Emitted when one of the size flags changes. Seesize_flags_horizontal andsize_flags_vertical.
theme_changed()🔗
Emitted when theNOTIFICATION_THEME_CHANGED notification is sent.
Enumerations
enumFocusMode:🔗
FocusModeFOCUS_NONE =0
The node cannot grab focus. Use withfocus_mode.
FocusModeFOCUS_CLICK =1
The node can only grab focus on mouse clicks. Use withfocus_mode.
FocusModeFOCUS_ALL =2
The node can grab focus on mouse click, using the arrows and the Tab keys on the keyboard, or using the D-pad buttons on a gamepad. Use withfocus_mode.
enumCursorShape:🔗
CursorShapeCURSOR_ARROW =0
Show the system's arrow mouse cursor when the user hovers the node. Use withmouse_default_cursor_shape.
CursorShapeCURSOR_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.
CursorShapeCURSOR_POINTING_HAND =2
Show the system's pointing hand mouse cursor when the user hovers the node.
CursorShapeCURSOR_CROSS =3
Show the system's cross mouse cursor when the user hovers the node.
CursorShapeCURSOR_WAIT =4
Show the system's wait mouse cursor when the user hovers the node. Often an hourglass.
CursorShapeCURSOR_BUSY =5
Show the system's busy mouse cursor when the user hovers the node. Often an arrow with a small hourglass.
CursorShapeCURSOR_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.
CursorShapeCURSOR_CAN_DROP =7
Show the system's drop mouse cursor when the user hovers the node. It can be an open hand. It tells the user they can drop an item they're currently grabbing, like a node in the Scene dock.
CursorShapeCURSOR_FORBIDDEN =8
Show the system's forbidden mouse cursor when the user hovers the node. Often a crossed circle.
CursorShapeCURSOR_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.
CursorShapeCURSOR_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.
CursorShapeCURSOR_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.
CursorShapeCURSOR_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 ofCURSOR_BDIAGSIZE. It tells the user they can resize the window or the panel both horizontally and vertically.
CursorShapeCURSOR_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.
CursorShapeCURSOR_VSPLIT =14
Show the system's vertical split mouse cursor when the user hovers the node. On Windows, it's the same asCURSOR_VSIZE.
CursorShapeCURSOR_HSPLIT =15
Show the system's horizontal split mouse cursor when the user hovers the node. On Windows, it's the same asCURSOR_HSIZE.
CursorShapeCURSOR_HELP =16
Show the system's help mouse cursor when the user hovers the node, a question mark.
enumLayoutPreset:🔗
LayoutPresetPRESET_TOP_LEFT =0
Snap all 4 anchors to the top-left of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_TOP_RIGHT =1
Snap all 4 anchors to the top-right of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_BOTTOM_LEFT =2
Snap all 4 anchors to the bottom-left of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_BOTTOM_RIGHT =3
Snap all 4 anchors to the bottom-right of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_CENTER_LEFT =4
Snap all 4 anchors to the center of the left edge of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_CENTER_TOP =5
Snap all 4 anchors to the center of the top edge of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_CENTER_RIGHT =6
Snap all 4 anchors to the center of the right edge of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_CENTER_BOTTOM =7
Snap all 4 anchors to the center of the bottom edge of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_CENTER =8
Snap all 4 anchors to the center of the parent control's bounds. Use withset_anchors_preset().
LayoutPresetPRESET_LEFT_WIDE =9
Snap all 4 anchors to the left edge of the parent control. The left offset becomes relative to the left edge and the top offset relative to the top left corner of the node's parent. Use withset_anchors_preset().
LayoutPresetPRESET_TOP_WIDE =10
Snap all 4 anchors to the top edge of the parent control. The left offset becomes relative to the top left corner, the top offset relative to the top edge, and the right offset relative to the top right corner of the node's parent. Use withset_anchors_preset().
LayoutPresetPRESET_RIGHT_WIDE =11
Snap all 4 anchors to the right edge of the parent control. The right offset becomes relative to the right edge and the top offset relative to the top right corner of the node's parent. Use withset_anchors_preset().
LayoutPresetPRESET_BOTTOM_WIDE =12
Snap all 4 anchors to the bottom edge of the parent control. The left offset becomes relative to the bottom left corner, the bottom offset relative to the bottom edge, and the right offset relative to the bottom right corner of the node's parent. Use withset_anchors_preset().
LayoutPresetPRESET_VCENTER_WIDE =13
Snap all 4 anchors to a vertical line that cuts the parent control in half. Use withset_anchors_preset().
LayoutPresetPRESET_HCENTER_WIDE =14
Snap all 4 anchors to a horizontal line that cuts the parent control in half. Use withset_anchors_preset().
LayoutPresetPRESET_FULL_RECT =15
Snap all 4 anchors to the respective corners of the parent control. Set all 4 offsets to 0 after you applied this preset and theControl will fit its parent control. Use withset_anchors_preset().
enumLayoutPresetMode:🔗
LayoutPresetModePRESET_MODE_MINSIZE =0
The control will be resized to its minimum size.
LayoutPresetModePRESET_MODE_KEEP_WIDTH =1
The control's width will not change.
LayoutPresetModePRESET_MODE_KEEP_HEIGHT =2
The control's height will not change.
LayoutPresetModePRESET_MODE_KEEP_SIZE =3
The control's size will not change.
flagsSizeFlags:🔗
SizeFlagsSIZE_SHRINK_BEGIN =0
Tells the parentContainer to align the node with its start, either the top or the left edge. It is mutually exclusive withSIZE_FILL and other shrink size flags, but can be used withSIZE_EXPAND in some containers. Use withsize_flags_horizontal andsize_flags_vertical.
Note: Setting this flag is equal to not having any size flags.
SizeFlagsSIZE_FILL =1
Tells the parentContainer to expand the bounds of this node to fill all the available space without pushing any other node. It is mutually exclusive with shrink size flags. Use withsize_flags_horizontal andsize_flags_vertical.
SizeFlagsSIZE_EXPAND =2
Tells the parentContainer 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. Seesize_flags_stretch_ratio. Use withsize_flags_horizontal andsize_flags_vertical.
SizeFlagsSIZE_EXPAND_FILL =3
Sets the node's size flags to both fill and expand. SeeSIZE_FILL andSIZE_EXPAND for more information.
SizeFlagsSIZE_SHRINK_CENTER =4
Tells the parentContainer to center the node in the available space. It is mutually exclusive withSIZE_FILL and other shrink size flags, but can be used withSIZE_EXPAND in some containers. Use withsize_flags_horizontal andsize_flags_vertical.
SizeFlagsSIZE_SHRINK_END =8
Tells the parentContainer to align the node with its end, either the bottom or the right edge. It is mutually exclusive withSIZE_FILL and other shrink size flags, but can be used withSIZE_EXPAND in some containers. Use withsize_flags_horizontal andsize_flags_vertical.
enumMouseFilter:🔗
MouseFilterMOUSE_FILTER_STOP =0
The control will receive mouse movement input events and mouse button input events if clicked on through_gui_input(). The control will also receive themouse_entered andmouse_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.
MouseFilterMOUSE_FILTER_PASS =1
The control will receive mouse movement input events and mouse button input events if clicked on through_gui_input(). The control will also receive themouse_entered andmouse_exited signals.
If this control does not handle the event, the event will propagate up to its parent control if it has one. The event is bubbled up the node hierarchy until it reaches a non-CanvasItem, a control withMOUSE_FILTER_STOP, or aCanvasItem withCanvasItem.top_level enabled. This will allow signals to fire in all controls it reaches. If no control handled it, the event will be passed toNode._shortcut_input() for further processing.
MouseFilterMOUSE_FILTER_IGNORE =2
The control will not receive any mouse movement input events nor mouse button input events through_gui_input(). The control will also not receive themouse_entered normouse_exited signals. This will not block other controls from receiving these events or firing the signals. Ignored events will not be handled automatically. If a child hasMOUSE_FILTER_PASS and an event was passed to this control, the event will further propagate up to the control's parent.
Note: If the control has receivedmouse_entered but notmouse_exited, changing themouse_filter toMOUSE_FILTER_IGNORE will causemouse_exited to be emitted.
enumGrowDirection:🔗
GrowDirectionGROW_DIRECTION_BEGIN =0
The control will grow to the left or top to make up if its minimum size is changed to be greater than its current size on the respective axis.
GrowDirectionGROW_DIRECTION_END =1
The control will grow to the right or bottom to make up if its minimum size is changed to be greater than its current size on the respective axis.
GrowDirectionGROW_DIRECTION_BOTH =2
The control will grow in both directions equally to make up if its minimum size is changed to be greater than its current size.
enumAnchor:🔗
AnchorANCHOR_BEGIN =0
Snaps one of the 4 anchor's sides to the origin of the node'sRect
, in the top left. Use it with one of theanchor_*
member variables, likeanchor_left. To change all 4 anchors at once, useset_anchors_preset().
AnchorANCHOR_END =1
Snaps one of the 4 anchor's sides to the end of the node'sRect
, in the bottom right. Use it with one of theanchor_*
member variables, likeanchor_left. To change all 4 anchors at once, useset_anchors_preset().
enumLayoutDirection:🔗
LayoutDirectionLAYOUT_DIRECTION_INHERITED =0
Automatic layout direction, determined from the parent control layout direction.
LayoutDirectionLAYOUT_DIRECTION_APPLICATION_LOCALE =1
Automatic layout direction, determined from the current locale. Right-to-left layout direction is automatically used for languages that require it such as Arabic and Hebrew, but only if a valid translation file is loaded for the given language (unless said language is configured as a fallback inProjectSettings.internationalization/locale/fallback). For all other languages (or if no valid translation file is found by Godot), left-to-right layout direction is used. If usingTextServerFallback (ProjectSettings.internationalization/rendering/text_driver), left-to-right layout direction is always used regardless of the language. Right-to-left layout direction can also be forced usingProjectSettings.internationalization/rendering/force_right_to_left_layout_direction.
LayoutDirectionLAYOUT_DIRECTION_LTR =2
Left-to-right layout direction.
LayoutDirectionLAYOUT_DIRECTION_RTL =3
Right-to-left layout direction.
LayoutDirectionLAYOUT_DIRECTION_SYSTEM_LOCALE =4
Automatic layout direction, determined from the system locale. Right-to-left layout direction is automatically used for languages that require it such as Arabic and Hebrew, but only if a valid translation file is loaded for the given language.. For all other languages (or if no valid translation file is found by Godot), left-to-right layout direction is used. If usingTextServerFallback (ProjectSettings.internationalization/rendering/text_driver), left-to-right layout direction is always used regardless of the language.
LayoutDirectionLAYOUT_DIRECTION_MAX =5
Represents the size of theLayoutDirection enum.
LayoutDirectionLAYOUT_DIRECTION_LOCALE =1
Deprecated: UseLAYOUT_DIRECTION_APPLICATION_LOCALE instead.
enumTextDirection:🔗
TextDirectionTEXT_DIRECTION_INHERITED =3
Text writing direction is the same as layout direction.
TextDirectionTEXT_DIRECTION_AUTO =0
Automatic text writing direction, determined from the current locale and text content.
TextDirectionTEXT_DIRECTION_LTR =1
Left-to-right text writing direction.
TextDirectionTEXT_DIRECTION_RTL =2
Right-to-left text writing direction.
Constants
NOTIFICATION_RESIZED =40
🔗
Sent when the node changes size. Usesize to get the new size.
NOTIFICATION_MOUSE_ENTER =41
🔗
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 itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index doesn't affect which Control receives the notification.
See alsoNOTIFICATION_MOUSE_ENTER_SELF.
NOTIFICATION_MOUSE_EXIT =42
🔗
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 itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index doesn't affect which Control receives the notification.
See alsoNOTIFICATION_MOUSE_EXIT_SELF.
NOTIFICATION_MOUSE_ENTER_SELF =60
🔗
Experimental: The reason this notification is sent may change in the future.
Sent when the mouse cursor enters the control's visible area, that is not occluded behind other Controls or Windows, provided itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index doesn't affect which Control receives the notification.
See alsoNOTIFICATION_MOUSE_ENTER.
NOTIFICATION_MOUSE_EXIT_SELF =61
🔗
Experimental: The reason this notification is sent may change in the future.
Sent when the mouse cursor leaves the control's visible area, that is not occluded behind other Controls or Windows, provided itsmouse_filter lets the event reach it and regardless if it's currently focused or not.
Note:CanvasItem.z_index doesn't affect which Control receives the notification.
See alsoNOTIFICATION_MOUSE_EXIT.
NOTIFICATION_FOCUS_ENTER =43
🔗
Sent when the node grabs focus.
NOTIFICATION_FOCUS_EXIT =44
🔗
Sent when the node loses focus.
NOTIFICATION_THEME_CHANGED =45
🔗
Sent when the node needs to refresh its theme items. This happens in one of the following cases:
Thetheme property is changed on this node or any of its ancestors.
Thetheme_type_variation 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.
Note: This notification is received alongsideNode.NOTIFICATION_ENTER_TREE, so if you are instantiating a scene, the child nodes will not be initialized yet. You can use it to setup theming for this node, child nodes created from script, or if you want to access child nodes added in the editor, make sure the node is ready usingNode.is_node_ready().
func_notification(what):ifwhat==NOTIFICATION_THEME_CHANGED:ifnotis_node_ready():awaitready# Wait until ready signal.$Label.add_theme_color_override("font_color",Color.YELLOW)
NOTIFICATION_SCROLL_BEGIN =47
🔗
Sent when this node is inside aScrollContainer which has begun being scrolled when dragging the scrollable areawith a touch event. This notification isnot 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 whenProjectSettings.input_devices/pointing/emulate_touch_from_mouse is enabled.
NOTIFICATION_SCROLL_END =48
🔗
Sent when this node is inside aScrollContainer which has stopped being scrolled when dragging the scrollable areawith a touch event. This notification isnot 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 whenProjectSettings.input_devices/pointing/emulate_touch_from_mouse is enabled.
NOTIFICATION_LAYOUT_DIRECTION_CHANGED =49
🔗
Sent when the control layout direction is changed from LTR or RTL or vice versa. This notification is propagated to child Control nodes as result of a change tolayout_direction.
Property Descriptions
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 theAnchor constants for convenience.
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 theAnchor constants for convenience.
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 theAnchor constants for convenience.
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 theAnchor constants for convenience.
boolis_auto_translating()
Deprecated: UseNode.auto_translate_mode instead.
Toggles if any text should automatically change to its translated version depending on the current locale.
boolis_clipping_contents()
Enables whether rendering ofCanvasItem based children should be clipped to this control's rectangle. Iftrue
, parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input.
Vector2custom_minimum_size =Vector2(0,0)
🔗
Vector2get_custom_minimum_size()
The minimum size of the node's bounding rectangle. If you set it to a value greater than(0,0)
, the node's bounding rectangle will always have at least this size. Note thatControl nodes have their internal minimum size returned byget_minimum_size(). It depends on the control's contents, like text, textures, or style boxes. The actual minimum size is the maximum value of this property and the internal minimum size (seeget_combined_minimum_size()).
FocusModeget_focus_mode()
The focus access mode for the control (None, Click or All). Only one Control can be focused at the same time, and it will receive keyboard, gamepad, and mouse signals.
NodePathfocus_neighbor_bottom =NodePath("")
🔗
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 theProjectSettings.input/ui_down input action. The node must be aControl. If this property is not set, Godot will give focus to the closestControl to the bottom of this one.
NodePathfocus_neighbor_left =NodePath("")
🔗
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 theProjectSettings.input/ui_left input action. The node must be aControl. If this property is not set, Godot will give focus to the closestControl to the left of this one.
NodePathfocus_neighbor_right =NodePath("")
🔗
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 theProjectSettings.input/ui_right input action. The node must be aControl. If this property is not set, Godot will give focus to the closestControl to the right of this one.
NodePathfocus_neighbor_top =NodePath("")
🔗
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 theProjectSettings.input/ui_up input action. The node must be aControl. If this property is not set, Godot will give focus to the closestControl to the top of this one.
NodePathfocus_next =NodePath("")
🔗
NodePathget_focus_next()
Tells Godot which node it should give focus to if the user pressesTab on a keyboard by default. You can change the key by editing theProjectSettings.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.
NodePathfocus_previous =NodePath("")
🔗
NodePathget_focus_previous()
Tells Godot which node it should give focus to if the user pressesShift+Tab on a keyboard by default. You can change the key by editing theProjectSettings.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.
Vector2get_global_position()
The node's global position, relative to the world (usually to theCanvasLayer).
GrowDirectiongrow_horizontal =1
🔗
GrowDirectionget_h_grow_direction()
Controls the direction on the horizontal axis in which the control should grow if its horizontal minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.
GrowDirectiongrow_vertical =1
🔗
GrowDirectionget_v_grow_direction()
Controls the direction on the vertical axis in which the control should grow if its vertical minimum size is changed to be greater than its current size, as the control always has to be at least the minimum size.
LayoutDirectionlayout_direction =0
🔗
LayoutDirectionget_layout_direction()
Controls layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew). See alsois_layout_rtl().
boollocalize_numeral_system =true
🔗
boolis_localizing_numeral_system()
Iftrue
, automatically converts code line numbers, list indices,SpinBox andProgressBar 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, usingTextServer.format_number().
CursorShapemouse_default_cursor_shape =0
🔗
CursorShapeget_default_cursor_shape()
The default cursor shape for this control. Useful for Godot plugins and applications or games that use the system's mouse cursors.
Note: On Linux, shapes may vary depending on the cursor theme of the system.
MouseFiltermouse_filter =0
🔗
MouseFilterget_mouse_filter()
Controls whether the control will be able to receive mouse button input events through_gui_input() and how these events should be handled. Also controls whether the control can receive themouse_entered, andmouse_exited signals. See the constants to learn what each does.
boolmouse_force_pass_scroll_events =true
🔗
boolis_force_pass_scroll_events()
When enabled, scroll wheel events processed by_gui_input() will be passed to the parent control even ifmouse_filter is set toMOUSE_FILTER_STOP.
You should disable it on the root of your UI if you do not want scroll events to go to theNode._unhandled_input() processing.
Note: Because this property defaults totrue
, this allows nested scrollable containers to work out of the box.
Distance between the node's bottom edge and its parent control, based onanchor_bottom.
Offsets are often controlled by one or multiple parentContainer nodes, so you should not modify them manually if your node is a direct child of aContainer. Offsets update automatically when you move or resize the node.
Distance between the node's left edge and its parent control, based onanchor_left.
Offsets are often controlled by one or multiple parentContainer nodes, so you should not modify them manually if your node is a direct child of aContainer. Offsets update automatically when you move or resize the node.
Distance between the node's right edge and its parent control, based onanchor_right.
Offsets are often controlled by one or multiple parentContainer nodes, so you should not modify them manually if your node is a direct child of aContainer. Offsets update automatically when you move or resize the node.
Distance between the node's top edge and its parent control, based onanchor_top.
Offsets are often controlled by one or multiple parentContainer nodes, so you should not modify them manually if your node is a direct child of aContainer. Offsets update automatically when you move or resize the node.
Vector2pivot_offset =Vector2(0,0)
🔗
Vector2get_pivot_offset()
By default, the node's pivot is its top-left corner. When you change itsrotation orscale, it will rotate or scale around this pivot. Set this property tosize / 2 to pivot around the Control's center.
Vector2position =Vector2(0,0)
🔗
Vector2get_position()
The node's position, relative to its containing node. It corresponds to the rectangle's top-left corner. The property is not affected bypivot_offset.
floatget_rotation()
The node's rotation around its pivot, in radians. Seepivot_offset 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, userotation_degrees.
floatget_rotation_degrees()
Helper property to accessrotation in degrees instead of radians.
Vector2get_scale()
The node's scale, relative to itssize. Change this property to scale the node around itspivot_offset. The Control'stooltip_text 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 thedocumentation instead of scaling Controls individually.
Note:FontFile.oversampling doesnot takeControlscale 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 enablingProjectSettings.gui/theme/default_font_multichannel_signed_distance_field (applies to the default project font only), or enablingMultichannel Signed Distance Field in the import options of a DynamicFont for custom fonts. On system fonts,SystemFont.multichannel_signed_distance_field can be enabled in the inspector.
Note: If the Control node is a child of aContainer node, the scale will be reset toVector2(1,1)
when the scene is instantiated. To set the Control's scale when it's instantiated, wait for one frame usingawaitget_tree().process_frame
then set itsscale property.
Nodeget_shortcut_context()
TheNode which must be a parent of the focusedControl for the shortcut to be activated. Ifnull
, 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.
Vector2get_size()
The size of the node's bounding rectangle, in the node's coordinate system.Container nodes update this property automatically.
BitField[SizeFlags]size_flags_horizontal =1
🔗
Tells the parentContainer nodes how they should resize and place the node on the X axis. Use a combination of theSizeFlags constants to change the flags. See the constants to learn what each does.
floatsize_flags_stretch_ratio =1.0
🔗
floatget_stretch_ratio()
If the node and at least one of its neighbors uses theSIZE_EXPAND size flag, the parentContainer 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.
BitField[SizeFlags]size_flags_vertical =1
🔗
Tells the parentContainer nodes how they should resize and place the node on the Y axis. Use a combination of theSizeFlags constants to change the flags. See the constants to learn what each does.
Themeget_theme()
TheTheme resource this node and all itsControl andWindow children use. If a child node has its ownTheme 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.
StringNametheme_type_variation =&""
🔗
StringNameget_theme_type_variation()
The name of a theme type variation used by thisControl to look up its own theme items. When empty, the class name of the node is used (e.g.Button
for theButton 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. SeeTheme.set_type_variation(). If the theme item cannot be found using this type or its base types, lookup falls back on the class names.
Note: To look upControl's own items use variousget_theme_*
methods without specifyingtheme_type
.
Note: Theme items are looked for in the tree order, from branch to root, where eachControl node is checked for itstheme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.
AutoTranslateModetooltip_auto_translate_mode =0
🔗
voidset_tooltip_auto_translate_mode(value:AutoTranslateMode)
AutoTranslateModeget_tooltip_auto_translate_mode()
Defines if tooltip text should automatically change to its translated version depending on the current locale. Uses the same auto translate mode as this control when set toNode.AUTO_TRANSLATE_MODE_INHERIT.
Note: Tooltips customized using_make_custom_tooltip() do not use this auto translate mode automatically.
Stringget_tooltip_text()
The default tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that themouse_filter property is notMOUSE_FILTER_IGNORE. The time required for the tooltip to appear can be changed with theProjectSettings.gui/timers/tooltip_delay_sec setting.
This string is the default return value ofget_tooltip(). Override_get_tooltip() to generate tooltip text dynamically. Override_make_custom_tooltip() to customize the tooltip interface and behavior.
The tooltip popup will use either a default implementation, or a custom one that you can provide by overriding_make_custom_tooltip(). The default tooltip includes aPopupPanel andLabel whose theme properties can be customized usingTheme methods with the"TooltipPanel"
and"TooltipLabel"
respectively. For example:
varstyle_box=StyleBoxFlat.new()style_box.set_bg_color(Color(1,1,0))style_box.set_border_width_all(2)# We assume here that the `theme` property has been assigned a custom Theme beforehand.theme.set_stylebox("panel","TooltipPanel",style_box)theme.set_color("font_color","TooltipLabel",Color(0,1,1))
varstyleBox=newStyleBoxFlat();styleBox.SetBgColor(newColor(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",newColor(0,1,1));
Method Descriptions
bool_can_drop_data(at_position:Vector2, data:Variant)virtualconst🔗
Godot calls this method to test ifdata
from a control's_get_drag_data() can be dropped atat_position
.at_position
is local to this control.
This method should only be used to test the data. Process the data in_drop_data().
func_can_drop_data(position,data):# Check position if it is relevant to you# Otherwise, just check datareturntypeof(data)==TYPE_DICTIONARYanddata.has("expected")
publicoverridebool_CanDropData(Vector2atPosition,Variantdata){// Check position if it is relevant to you// Otherwise, just check datareturndata.VariantType==Variant.Type.Dictionary&&data.AsGodotDictionary().ContainsKey("expected");}
void_drop_data(at_position:Vector2, data:Variant)virtual🔗
Godot calls this method to pass you thedata
from a control's_get_drag_data() result. Godot first calls_can_drop_data() to test ifdata
is allowed to drop atat_position
whereat_position
is local to this control.
func_can_drop_data(position,data):returntypeof(data)==TYPE_DICTIONARYanddata.has("color")func_drop_data(position,data):varcolor=data["color"]
publicoverridebool_CanDropData(Vector2atPosition,Variantdata){returndata.VariantType==Variant.Type.Dictionary&&data.AsGodotDictionary().ContainsKey("color");}publicoverridevoid_DropData(Vector2atPosition,Variantdata){Colorcolor=data.AsGodotDictionary()["color"].AsColor();}
Variant_get_drag_data(at_position:Vector2)virtual🔗
Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data. Returnsnull
if there is no data to drag. Controls that want to receive drop data should implement_can_drop_data() and_drop_data().at_position
is local to this control. Drag may be forced withforce_drag().
A preview that will follow the mouse that should represent the data can be set withset_drag_preview(). A good time to set the preview is in this method.
func_get_drag_data(position):varmydata=make_data()# This is your custom method generating the drag data.set_drag_preview(make_preview(mydata))# This is your custom method generating the preview of the drag data.returnmydata
publicoverrideVariant_GetDragData(Vector2atPosition){varmyData=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.returnmyData;}
Vector2_get_minimum_size()virtualconst🔗
Virtual method to be implemented by the user. Returns the minimum size for this control. Alternative tocustom_minimum_size for controlling minimum size via code. The actual minimum size will be the max value of these two (in each axis separately).
If not overridden, defaults toVector2.ZERO.
Note: This method will not be called when the script is attached to aControl node that already overrides its minimum size (e.g.Label,Button,PanelContainer etc.). It can only be used with most basic GUI nodes, likeControl,Container,Panel etc.
String_get_tooltip(at_position:Vector2)virtualconst🔗
Virtual method to be implemented by the user. Returns the tooltip text for the positionat_position
in control's local coordinates, which will typically appear when the cursor is resting over this control. Seeget_tooltip().
Note: If this method returns an emptyString and_make_custom_tooltip() is not overridden, no tooltip is displayed.
void_gui_input(event:InputEvent)virtual🔗
Virtual method to be implemented by the user. Override this method to handle and accept inputs on UI elements. See alsoaccept_event().
Example: Click on the control to print a message:
func_gui_input(event):ifeventisInputEventMouseButton:ifevent.button_index==MOUSE_BUTTON_LEFTandevent.pressed:print("I've been clicked D:")
publicoverridevoid_GuiInput(InputEvent@event){if(@eventisInputEventMouseButtonmb){if(mb.ButtonIndex==MouseButton.Left&&mb.Pressed){GD.Print("I've been clicked D:");}}}
If theevent
inheritsInputEventMouse, this method willnot be called when:
the control'smouse_filter is set toMOUSE_FILTER_IGNORE;
the control is obstructed by another control on top, that doesn't havemouse_filter set toMOUSE_FILTER_IGNORE;
the control's parent hasmouse_filter set toMOUSE_FILTER_STOP or has accepted the event;
the control's parent hasclip_contents enabled and the
event
's position is outside the parent's rectangle;the
event
's position is outside the control (see_has_point()).
Note: Theevent
's position is relative to this control's origin.
bool_has_point(point:Vector2)virtualconst🔗
Virtual method to be implemented by the user. Returns whether the givenpoint
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 useRect2(Vector2.ZERO,size).has_point(point)
.
Object_make_custom_tooltip(for_text:String)virtualconst🔗
Virtual method to be implemented by the user. Returns aControl node that should be used as a tooltip instead of the default one.for_text
is the return value ofget_tooltip().
The returned node must be of typeControl 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). Whennull
or a non-Control node is returned, the default tooltip will be used instead.
The returned node will be added as child to aPopupPanel, so you should only provide the contents of that panel. ThatPopupPanel can be themed usingTheme.set_stylebox() for the type"TooltipPanel"
(seetooltip_text 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 itscustom_minimum_size to some non-zero value.
Note: The node (and any relevant children) should have theirCanvasItem.visible set totrue
when returned, otherwise, the viewport that instantiates it will not be able to calculate its minimum size reliably.
Note: If overridden, this method is called even ifget_tooltip() returns an empty string. When this happens with the default tooltip, it is not displayed. To copy this behavior, returnnull
in this method whenfor_text
is empty.
Example: Use a constructed node as a tooltip:
func_make_custom_tooltip(for_text):varlabel=Label.new()label.text=for_textreturnlabel
publicoverrideControl_MakeCustomTooltip(stringforText){varlabel=newLabel();label.Text=forText;returnlabel;}
Example: Usa a scene instance as a tooltip:
func_make_custom_tooltip(for_text):vartooltip=preload("res://some_tooltip_scene.tscn").instantiate()tooltip.get_node("Label").text=for_textreturntooltip
publicoverrideControl_MakeCustomTooltip(stringforText){Nodetooltip=ResourceLoader.Load<PackedScene>("res://some_tooltip_scene.tscn").Instantiate();tooltip.GetNode<Label>("Label").Text=forText;returntooltip;}
Array[Vector3i]_structured_text_parser(args:Array, text:String)virtualconst🔗
User defined BiDi algorithm override function.
Returns anArray ofVector3i text ranges and text base directions, in the left-to-right order. Ranges should cover full sourcetext
without overlaps. BiDi algorithm will be used on each range separately.
Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening toNode._unhandled_input() orNode._unhandled_key_input().
Note: This does not affect the methods inInput, only the way events are propagated.
voidadd_theme_color_override(name:StringName, color:Color)🔗
Creates a local override for a themeColor with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_color_override().
See alsoget_theme_color().
Example: Override aLabel's color and reset it later:
# Given the child Label node "MyLabel", override its font color with a custom value.$MyLabel.add_theme_color_override("font_color",Color(1,0.5,0))# Reset the font color of the child label.$MyLabel.remove_theme_color_override("font_color")# Alternatively it can be overridden with the default value from the Label type.$MyLabel.add_theme_color_override("font_color",get_theme_color("font_color","Label"))
// Given the child Label node "MyLabel", override its font color with a custom value.GetNode<Label>("MyLabel").AddThemeColorOverride("font_color",newColor(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"));
voidadd_theme_constant_override(name:StringName, constant:int)🔗
Creates a local override for a theme constant with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_constant_override().
See alsoget_theme_constant().
voidadd_theme_font_override(name:StringName, font:Font)🔗
Creates a local override for a themeFont with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_font_override().
See alsoget_theme_font().
voidadd_theme_font_size_override(name:StringName, font_size:int)🔗
Creates a local override for a theme font size with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_font_size_override().
See alsoget_theme_font_size().
voidadd_theme_icon_override(name:StringName, texture:Texture2D)🔗
Creates a local override for a theme icon with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_icon_override().
See alsoget_theme_icon().
voidadd_theme_stylebox_override(name:StringName, stylebox:StyleBox)🔗
Creates a local override for a themeStyleBox with the specifiedname
. Local overrides always take precedence when fetching theme items for the control. An override can be removed withremove_theme_stylebox_override().
See alsoget_theme_stylebox().
Example: Modify a property in aStyleBox 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.varnew_stylebox_normal=$MyButton.get_theme_stylebox("normal").duplicate()new_stylebox_normal.border_width_top=3new_stylebox_normal.border_color=Color(0,1,0.5)$MyButton.add_theme_stylebox_override("normal",new_stylebox_normal)# Remove the stylebox override.$MyButton.remove_theme_stylebox_override("normal")
// 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.StyleBoxFlatnewStyleboxNormal=GetNode<Button>("MyButton").GetThemeStylebox("normal").Duplicate()asStyleBoxFlat;newStyleboxNormal.BorderWidthTop=3;newStyleboxNormal.BorderColor=newColor(0,1,0.5f);GetNode<Button>("MyButton").AddThemeStyleboxOverride("normal",newStyleboxNormal);// Remove the stylebox override.GetNode<Button>("MyButton").RemoveThemeStyleboxOverride("normal");
voidbegin_bulk_theme_override()🔗
Prevents*_theme_*_override
methods from emittingNOTIFICATION_THEME_CHANGED untilend_bulk_theme_override() is called.
voidend_bulk_theme_override()🔗
Ends a bulk theme override update. Seebegin_bulk_theme_override().
Controlfind_next_valid_focus()const🔗
Finds the next (below in the tree)Control that can receive the focus.
Controlfind_prev_valid_focus()const🔗
Finds the previous (above in the tree)Control that can receive the focus.
Controlfind_valid_focus_neighbor(side:Side)const🔗
Finds the nextControl that can receive the focus on the specifiedSide.
Note: This is different fromget_focus_neighbor(), which returns the path of a specified focus neighbor.
voidforce_drag(data:Variant, preview:Control)🔗
Forces drag and bypasses_get_drag_data() andset_drag_preview() by passingdata
andpreview
. Drag will start even if the mouse is neither over nor pressed on this control.
The methods_can_drop_data() and_drop_data() must be implemented on controls that want to receive drop data.
floatget_anchor(side:Side)const🔗
Returns the anchor for the specifiedSide. A getter method foranchor_bottom,anchor_left,anchor_right andanchor_top.
Returnsoffset_left andoffset_top. See alsoposition.
Vector2get_combined_minimum_size()const🔗
Returns combined minimum size fromcustom_minimum_size andget_minimum_size().
CursorShapeget_cursor_shape(position:Vector2 = Vector2(0, 0))const🔗
Returns the mouse cursor shape the control displays on mouse hover. SeeCursorShape.
Returnsoffset_right andoffset_bottom.
NodePathget_focus_neighbor(side:Side)const🔗
Returns the focus neighbor for the specifiedSide. A getter method forfocus_neighbor_bottom,focus_neighbor_left,focus_neighbor_right andfocus_neighbor_top.
Note: To find the nextControl on the specificSide, even if a neighbor is not assigned, usefind_valid_focus_neighbor().
Returns the position and size of the control relative to the containing canvas. Seeglobal_position andsize.
Note: If the node itself or any parentCanvasItem between the node and the canvas have a non default rotation or skew, the resulting size is likely not meaningful.
Note: SettingViewport.gui_snap_controls_to_pixels totrue
can lead to rounding inaccuracies between the displayed control and the returnedRect2.
Vector2get_minimum_size()const🔗
Returns the minimum size for this control. Seecustom_minimum_size.
floatget_offset(offset:Side)const🔗
Returns the offset for the specifiedSide. A getter method foroffset_bottom,offset_left,offset_right andoffset_top.
Vector2get_parent_area_size()const🔗
Returns the width/height occupied in the parent control.
Controlget_parent_control()const🔗
Returns the parent control node.
Returns the position and size of the control in the coordinate system of the containing node. Seeposition,scale andsize.
Note: Ifrotation is not the default rotation, the resulting size is not meaningful.
Note: SettingViewport.gui_snap_controls_to_pixels totrue
can lead to rounding inaccuracies between the displayed control and the returnedRect2.
Vector2get_screen_position()const🔗
Returns the position of thisControl in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
Equals toglobal_position if the window is embedded (seeViewport.gui_embed_subwindows).
Example: Show a popup at the mouse position:
popup_menu.position=get_screen_position()+get_local_mouse_position()popup_menu.reset_size()popup_menu.popup()
Colorget_theme_color(name:StringName, theme_type:StringName = &"")const🔗
Returns aColor from the first matchingTheme in the tree if thatTheme has a color item with the specifiedname
andtheme_type
. Iftheme_type
is omitted the class name of the current control is used as the type, ortheme_type_variation 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 (seeadd_theme_color_override()), then its assignedtheme. After the current control, each parent control and its assignedtheme are considered; controls without atheme assigned are skipped. If no matchingTheme is found in the tree, the custom projectTheme (seeProjectSettings.gui/theme/custom) and the defaultTheme are used (seeThemeDB).
func_ready():# Get the font color defined for the current Control's class, if it exists.modulate=get_theme_color("font_color")# Get the font color defined for the Button class.modulate=get_theme_color("font_color","Button")
publicoverridevoid_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");}
intget_theme_constant(name:StringName, theme_type:StringName = &"")const🔗
Returns a constant from the first matchingTheme in the tree if thatTheme has a constant item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
floatget_theme_default_base_scale()const🔗
Returns the default base scale value from the first matchingTheme in the tree if thatTheme has a validTheme.default_base_scale value.
Seeget_theme_color() for details.
Fontget_theme_default_font()const🔗
Returns the default font from the first matchingTheme in the tree if thatTheme has a validTheme.default_font value.
Seeget_theme_color() for details.
intget_theme_default_font_size()const🔗
Returns the default font size value from the first matchingTheme in the tree if thatTheme has a validTheme.default_font_size value.
Seeget_theme_color() for details.
Fontget_theme_font(name:StringName, theme_type:StringName = &"")const🔗
Returns aFont from the first matchingTheme in the tree if thatTheme has a font item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
intget_theme_font_size(name:StringName, theme_type:StringName = &"")const🔗
Returns a font size from the first matchingTheme in the tree if thatTheme has a font size item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
Texture2Dget_theme_icon(name:StringName, theme_type:StringName = &"")const🔗
Returns an icon from the first matchingTheme in the tree if thatTheme has an icon item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
StyleBoxget_theme_stylebox(name:StringName, theme_type:StringName = &"")const🔗
Returns aStyleBox from the first matchingTheme in the tree if thatTheme has a stylebox item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
Stringget_tooltip(at_position:Vector2 = Vector2(0, 0))const🔗
Returns the tooltip text for the positionat_position
in control's local coordinates, which will typically appear when the cursor is resting over this control. By default, it returnstooltip_text.
This method can be overridden to customize its behavior. See_get_tooltip().
Note: If this method returns an emptyString and_make_custom_tooltip() is not overridden, no tooltip is displayed.
Creates anInputEventMouseButton that attempts to click the control. If the event is received, the control gains focus.
func_process(delta):grab_click_focus()# When clicking another Control node, this node will be clicked instead.
publicoverridevoid_Process(doubledelta){GrabClickFocus();// When clicking another Control node, this node will be clicked instead.}
Steal the focus from another control and become the focused control (seefocus_mode).
Note: Using this method together withCallable.call_deferred() makes it more reliable, especially when called insideNode._ready().
Returnstrue
if this is the current focused control. Seefocus_mode.
boolhas_theme_color(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has a color item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_color_override(name:StringName)const🔗
Returnstrue
if there is a local override for a themeColor with the specifiedname
in thisControl node.
Seeadd_theme_color_override().
boolhas_theme_constant(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has a constant item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_constant_override(name:StringName)const🔗
Returnstrue
if there is a local override for a theme constant with the specifiedname
in thisControl node.
Seeadd_theme_constant_override().
boolhas_theme_font(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has a font item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_font_override(name:StringName)const🔗
Returnstrue
if there is a local override for a themeFont with the specifiedname
in thisControl node.
boolhas_theme_font_size(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has a font size item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_font_size_override(name:StringName)const🔗
Returnstrue
if there is a local override for a theme font size with the specifiedname
in thisControl node.
Seeadd_theme_font_size_override().
boolhas_theme_icon(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has an icon item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_icon_override(name:StringName)const🔗
Returnstrue
if there is a local override for a theme icon with the specifiedname
in thisControl node.
boolhas_theme_stylebox(name:StringName, theme_type:StringName = &"")const🔗
Returnstrue
if there is a matchingTheme in the tree that has a stylebox item with the specifiedname
andtheme_type
.
Seeget_theme_color() for details.
boolhas_theme_stylebox_override(name:StringName)const🔗
Returnstrue
if there is a local override for a themeStyleBox with the specifiedname
in thisControl node.
Seeadd_theme_stylebox_override().
boolis_drag_successful()const🔗
Returnstrue
if a drag operation is successful. Alternative toViewport.gui_is_drag_successful().
Best used withNode.NOTIFICATION_DRAG_END.
Returnstrue
if layout is right-to-left. See alsolayout_direction.
Give up the focus. No other control will be able to receive input.
voidremove_theme_color_override(name:StringName)🔗
Removes a local override for a themeColor with the specifiedname
previously added byadd_theme_color_override() or via the Inspector dock.
voidremove_theme_constant_override(name:StringName)🔗
Removes a local override for a theme constant with the specifiedname
previously added byadd_theme_constant_override() or via the Inspector dock.
voidremove_theme_font_override(name:StringName)🔗
Removes a local override for a themeFont with the specifiedname
previously added byadd_theme_font_override() or via the Inspector dock.
voidremove_theme_font_size_override(name:StringName)🔗
Removes a local override for a theme font size with the specifiedname
previously added byadd_theme_font_size_override() or via the Inspector dock.
voidremove_theme_icon_override(name:StringName)🔗
Removes a local override for a theme icon with the specifiedname
previously added byadd_theme_icon_override() or via the Inspector dock.
voidremove_theme_stylebox_override(name:StringName)🔗
Removes a local override for a themeStyleBox with the specifiedname
previously added byadd_theme_stylebox_override() or via the Inspector dock.
Resets the size toget_combined_minimum_size(). This is equivalent to callingset_size(Vector2())
(or any size below the minimum).
voidset_anchor(side:Side, anchor:float, keep_offset:bool = false, push_opposite_anchor:bool = true)🔗
Sets the anchor for the specifiedSide toanchor
. A setter method foranchor_bottom,anchor_left,anchor_right andanchor_top.
Ifkeep_offset
istrue
, offsets aren't updated after this operation.
Ifpush_opposite_anchor
istrue
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. Ifpush_opposite_anchor
wasfalse
, the left anchor would get value 0.5.
voidset_anchor_and_offset(side:Side, anchor:float, offset:float, push_opposite_anchor:bool = false)🔗
Works the same asset_anchor(), but instead ofkeep_offset
argument and automatic update of offset, it allows to set the offset yourself (seeset_offset()).
voidset_anchors_and_offsets_preset(preset:LayoutPreset, resize_mode:LayoutPresetMode = 0, margin:int = 0)🔗
Sets both anchor preset and offset preset. Seeset_anchors_preset() andset_offsets_preset().
voidset_anchors_preset(preset:LayoutPreset, keep_offsets:bool = false)🔗
Sets the anchors to apreset
fromLayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.
Ifkeep_offsets
istrue
, control's position will also be updated.
voidset_begin(position:Vector2)🔗
Setsoffset_left andoffset_top at the same time. Equivalent of changingposition.
voidset_drag_forwarding(drag_func:Callable, can_drop_func:Callable, drop_func:Callable)🔗
Sets the given callables to be used instead of the control's own drag-and-drop virtual methods. If a callable is empty, its respective virtual method is used as normal.
The arguments for each callable should be exactly the same as their respective virtual methods, which would be:
drag_func
corresponds to_get_drag_data() and requires aVector2;can_drop_func
corresponds to_can_drop_data() and requires both aVector2 and aVariant;drop_func
corresponds to_drop_data() and requires both aVector2 and aVariant.
voidset_drag_preview(control:Control)🔗
Shows the given control at the mouse pointer. A good time to call this method is in_get_drag_data(). 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.
@exportvarcolor=Color(1,0,0,1)func_get_drag_data(position):# Use a control that is not in the treevarcpb=ColorPickerButton.new()cpb.color=colorcpb.size=Vector2(50,50)set_drag_preview(cpb)returncolor
[Export]privateColor_color=newColor(1,0,0,1);publicoverrideVariant_GetDragData(Vector2atPosition){// Use a control that is not in the treevarcpb=newColorPickerButton();cpb.Color=_color;cpb.Size=newVector2(50,50);SetDragPreview(cpb);return_color;}
voidset_end(position:Vector2)🔗
Setsoffset_right andoffset_bottom at the same time.
voidset_focus_neighbor(side:Side, neighbor:NodePath)🔗
Sets the focus neighbor for the specifiedSide to theControl atneighbor
node path. A setter method forfocus_neighbor_bottom,focus_neighbor_left,focus_neighbor_right andfocus_neighbor_top.
voidset_global_position(position:Vector2, keep_offsets:bool = false)🔗
Sets theglobal_position to givenposition
.
Ifkeep_offsets
istrue
, control's anchors will be updated instead of offsets.
voidset_offset(side:Side, offset:float)🔗
Sets the offset for the specifiedSide tooffset
. A setter method foroffset_bottom,offset_left,offset_right andoffset_top.
voidset_offsets_preset(preset:LayoutPreset, resize_mode:LayoutPresetMode = 0, margin:int = 0)🔗
Sets the offsets to apreset
fromLayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.
Use parameterresize_mode
with constants fromLayoutPresetMode to better determine the resulting size of theControl. Constant size will be ignored if used with presets that change size, e.g.PRESET_LEFT_WIDE.
Use parametermargin
to determine the gap between theControl and the edges.
voidset_position(position:Vector2, keep_offsets:bool = false)🔗
Sets theposition to givenposition
.
Ifkeep_offsets
istrue
, control's anchors will be updated instead of offsets.
voidset_size(size:Vector2, keep_offsets:bool = false)🔗
Sets the size (seesize).
Ifkeep_offsets
istrue
, control's anchors will be updated instead of offsets.
Invalidates the size cache in this node and in parent nodes up to top level. Intended to be used withget_minimum_size() when the return value is changed. Settingcustom_minimum_size directly calls this method automatically.
voidwarp_mouse(position:Vector2)🔗
Moves the mouse cursor toposition
, relative toposition of thisControl.
Note:warp_mouse() is only supported on Windows, macOS and Linux. It has no effect on Android, iOS and Web.