Control
Inherits: CanvasItem < Node < Object Inherited By: BaseButton, ColorRect, Container, GraphEdit, ItemList, Label, LineEdit, NinePatchRect, Panel, Popup, Range, ReferenceRect, RichTextLabel, Separator, Tabs, TextEdit, TextureRect, Tree, VideoPlayer All user interface nodes inherit from Control. A control’s anchors and margins adapt its position and size relative to its parent.
Description
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.
Control and Container nodes.
User Interface nodes and input
Node.input. Node._input forwards the event down the node tree to the nodes under the mouse cursor, or on keyboard focus. To do so, it calls MainLoop._input_event. Call accept_event so no other node receives the event. Once you accept an input, it becomes handled so Node._unhandled_input will not process it.
Control node can be in keyboard focus. Only the node in focus will receive keyboard events. To get the focus, call grab_focus. Control nodes lose focus when another node grabs it, or if you hide the node in focus.
mouse_filter to 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 add_font_override. You can override the theme with the inspector.
Note: Theme items are not Object properties. This means you can’t access their values using Object.get and Object.set. Instead, use getcolor, get_constant, get_font, get_icon, get_stylebox, and the `add_override` methods provided by this class.
Tutorials
- GUI tutorial index
- Custom drawing in 2D
- Control node gallery
- All GUI Demos
Properties
Methods
Signals
- focus_entered ( ) Emitted when the node gains keyboard focus.
- focus_exited ( ) Emitted when the node loses keyboard focus.
- gui_input ( InputEvent event ) InputEvent.
- minimum_size_changed ( ) Emitted when the node’s minimum size changes.
- modal_closed ( )
Controlis closed. See show_modal.
- mouse_entered ( )
Rectarea, provided its mouse_filter lets the event reach it. Note: mouse_entered will not be emitted if the mouse enters a childControlnode before entering the parent’sRectarea, at least until the mouse is moved to reach the parent’sRectarea.
- mouse_exited ( )
Rectarea, provided its mouse_filter lets the event reach it. Note: mouse_exited will be emitted if the mouse enters a childControlnode, even if the mouse cursor is still inside the parent’sRectarea. If you want to check whether the mouse truly left the area, ignoring any top nodes, you can use code like this:func _on_mouse_exited(): if not Rect2(Vector2(), rect_size).has_point(get_local_mouse_position()): # Not hovering over area.
- resized ( ) Emitted when the control changes size.
- size_flags_changed ( )
size_flags_horizontal and size_flags_vertical.
Enumerations
FocusMode: - FOCUS_NONE = 0 —- The node cannot grab focus. Use with focus_mode.
- FOCUS_CLICK = 1 —- The node can only grab focus on mouse clicks. Use with focus_mode.
- FOCUS_ALL = 2 —- The node can grab focus on mouse click or using the arrows and the Tab keys on the keyboard. Use with focus_mode.
CursorShape:
- CURSOR_ARROW = 0 —- Show the system’s arrow mouse cursor when the user hovers the node. Use with mouse_default_cursor_shape.
- CURSOR_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.
- CURSOR_POINTING_HAND = 2 —- Show the system’s pointing hand mouse cursor when the user hovers the node.
- CURSOR_CROSS = 3 —- Show the system’s cross mouse cursor when the user hovers the node.
- CURSOR_WAIT = 4 —- Show the system’s wait mouse cursor when the user hovers the node. Often an hourglass.
- CURSOR_BUSY = 5 —- Show the system’s busy mouse cursor when the user hovers the node. Often an arrow with a small hourglass.
- CURSOR_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.
- CURSOR_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.
- CURSOR_FORBIDDEN = 8 —- Show the system’s forbidden mouse cursor when the user hovers the node. Often a crossed circle.
- CURSOR_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.
- CURSOR_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.
- CURSOR_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.
- CURSOR_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 CURSOR_BDIAGSIZE. It tells the user they can resize the window or the panel both horizontally and vertically.
- CURSOR_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.
- CURSOR_VSPLIT = 14 —- Show the system’s vertical split mouse cursor when the user hovers the node. On Windows, it’s the same as CURSOR_VSIZE.
- CURSOR_HSPLIT = 15 —- Show the system’s horizontal split mouse cursor when the user hovers the node. On Windows, it’s the same as CURSOR_HSIZE.
- CURSOR_HELP = 16 —- Show the system’s help mouse cursor when the user hovers the node, a question mark.
LayoutPreset:
- PRESET_TOP_LEFT = 0 —- Snap all 4 anchors to the top-left of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_TOP_RIGHT = 1 —- Snap all 4 anchors to the top-right of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_BOTTOM_LEFT = 2 —- Snap all 4 anchors to the bottom-left of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_BOTTOM_RIGHT = 3 —- Snap all 4 anchors to the bottom-right of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_CENTER_LEFT = 4 —- Snap all 4 anchors to the center of the left edge of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_CENTER_TOP = 5 —- Snap all 4 anchors to the center of the top edge of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_CENTER_RIGHT = 6 —- Snap all 4 anchors to the center of the right edge of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_CENTER_BOTTOM = 7 —- Snap all 4 anchors to the center of the bottom edge of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_CENTER = 8 —- Snap all 4 anchors to the center of the parent control’s bounds. Use with set_anchors_preset.
- PRESET_LEFT_WIDE = 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 set_anchors_preset.
- PRESET_TOP_WIDE = 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 set_anchors_preset.
- PRESET_RIGHT_WIDE = 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 set_anchors_preset.
- PRESET_BOTTOM_WIDE = 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 set_anchors_preset.
- PRESET_VCENTER_WIDE = 13 —- Snap all 4 anchors to a vertical line that cuts the parent control in half. Use with set_anchors_preset.
- PRESET_HCENTER_WIDE = 14 —- Snap all 4 anchors to a horizontal line that cuts the parent control in half. Use with set_anchors_preset.
- 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
Controlwill fit its parent control. This is equivalent to the “Full Rect” layout option in the editor. Use with set_anchors_preset.
LayoutPresetMode:
- PRESET_MODE_MINSIZE = 0 —- The control will be resized to its minimum size.
- PRESET_MODE_KEEP_WIDTH = 1 —- The control’s width will not change.
- PRESET_MODE_KEEP_HEIGHT = 2 —- The control’s height will not change.
- PRESET_MODE_KEEP_SIZE = 3 —- The control’s size will not change.
SizeFlags:
- SIZE_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 size_flags_horizontal and size_flags_vertical.
- SIZE_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 size_flags_stretch_ratio. Use with size_flags_horizontal and size_flags_vertical.
- SIZE_EXPAND_FILL = 3 —- Sets the node’s size flags to both fill and expand. See the 2 constants above for more information.
- SIZE_SHRINK_CENTER = 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 size_flags_horizontal and size_flags_vertical.
- SIZE_SHRINK_END = 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 size_flags_horizontal and size_flags_vertical.
MouseFilter:
- MOUSE_FILTER_STOP = 0 —- The control will receive mouse button input events through _gui_input if clicked on. And the control will receive the mouse_entered and 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.
- MOUSE_FILTER_PASS = 1 —- The control will receive mouse button input events through _gui_input if clicked on. And the control will receive the mouse_entered and 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.
- MOUSE_FILTER_IGNORE = 2 —- The control will not receive mouse button input events through _gui_input. The control will also not receive the mouse_entered nor mouse_exited signals. This will not block other controls from receiving these events or firing the signals. Ignored events will not be handled automatically.
GrowDirection:
- GROW_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.
- GROW_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.
- GROW_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.
Anchor:
- ANCHOR_BEGIN = 0 —- Snaps one of the 4 anchor’s sides to the origin of the node’s
Rect, in the top left. Use it with one of theanchor_*member variables, like anchor_left. To change all 4 anchors at once, use set_anchors_preset. - ANCHOR_END = 1 —- Snaps one of the 4 anchor’s sides to the end of the node’s
Rect, in the bottom right. Use it with one of theanchor_*member variables, like anchor_left. To change all 4 anchors at once, use set_anchors_preset.Constants
- NOTIFICATION_RESIZED = 40 —- Sent when the node changes size. Use rect_size to get the new size.
- NOTIFICATION_MOUSE_ENTER = 41 —- Sent when the mouse pointer enters the node.
- NOTIFICATION_MOUSE_EXIT = 42 —- Sent when the mouse pointer exits the node.
- 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’s theme changes, right before Godot redraws the control. Happens when you call one of the
add_*_overridemethods. - NOTIFICATION_MODAL_CLOSE = 46 —- Sent when an open modal dialog closes. See show_modal.
- NOTIFICATION_SCROLL_BEGIN = 47 —- Sent when this node is inside a ScrollContainer which has begun being scrolled.
- NOTIFICATION_SCROLL_END = 48 —- Sent when this node is inside a ScrollContainer which has stopped being scrolled.
Property Descriptions
- float anchor_bottom Anchor constants for convenience.
- float anchor_left Anchor constants for convenience.
- float anchor_right Anchor constants for convenience.
- float anchor_top Anchor constants for convenience.
- FocusMode 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 signals.
- NodePath focus_neighbour_bottom
ui_downinput action. The node must be aControl. If this property is not set, Godot will give focus to the closestControlto the bottom of this one.
- NodePath focus_neighbour_left
ui_leftinput action. The node must be aControl. If this property is not set, Godot will give focus to the closestControlto the left of this one.
- NodePath focus_neighbour_right
ui_rightinput action. The node must be aControl. If this property is not set, Godot will give focus to the closestControlto the bottom of this one.
- NodePath focus_neighbour_top
ui_topinput action. The node must be aControl. If this property is not set, Godot will give focus to the closestControlto the bottom of this one.
- NodePath focus_next
ui_focus_nextinput action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
- NodePath focus_previous
ui_focus_previnput action. If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
- GrowDirection grow_horizontal 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.
- GrowDirection grow_vertical 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.
- String hint_tooltip
mouse_filter property is not MOUSE_FILTER_IGNORE. You can change the time required for the tooltip to appear with
gui/timers/tooltip_delay_secoption in Project Settings. _make_custom_tooltip. The default tooltip includes a PopupPanel and Label whose theme properties can be customized using Theme methods with the"TooltipPanel"and"TooltipLabel"respectively. For example:var style_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))
- bool input_pass_on_modal_close_click
Enables whether input should propagate when you close the control as modal.
false, stops event handling at the viewport input event handling. The viewport first hides the modal and after marks the input as handled.
- float margin_bottom anchor_bottom. 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.
- float margin_left anchor_left. 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.
- float margin_right anchor_right. 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.
- float margin_top anchor_top. 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.
- CursorShape mouse_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.
- MouseFilter mouse_filter _gui_input 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.
- bool rect_clip_content
CanvasItem based children should be clipped to this control’s rectangle. If
true, parts of a child which would be visibly outside of this control’s rectangle will not be rendered.
- Vector2 rect_global_position The node’s global position, relative to the world (usually to the top-left corner of the window).
- Vector2 rect_min_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, 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.
- Vector2 rect_pivot_offset rect_rotation or rect_scale, it will rotate or scale around this pivot. Set this property to rect_size / 2 to pivot around the Control’s center.
- Vector2 rect_position rect_pivot_offset.
- float rect_rotation rect_pivot_offset to change the pivot’s position.
- Vector2 rect_scale
rect_size. Change this property to scale the node around its rect_pivot_offset. The Control’s hint_tooltip will also scale according to this value.
Note: This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the documentation instead of scaling Controls individually.
Note: If the Control node is a child of a Container node, the scale will be reset to
Vector2(1, 1)when the scene is instanced. To set the Control’s scale when it’s instanced, wait for one frame usingyield(get_tree(), "idle_frame")then set its rect_scale property.
- Vector2 rect_size Container nodes update this property automatically.
- int size_flags_horizontal 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.
- float size_flags_stretch_ratio 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.
- int size_flags_vertical Container nodes how they should resize and place the node on the Y axis. Use one of the SizeFlags constants to change the flags. See the constants to learn what each does.
- Theme theme
Theme resource this node and all its
Controlchildren use.
- String theme_type_variation
Controlto look up its own theme items. When empty, the class name of the node is used (e.g.Buttonfor the Button control), as well as the class names of all parent classes (in order of inheritance). Theme.settype_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 various `getmethods without specifyingtheme_type`. *Note: Theme items are looked for in the tree order, from branch to root, where eachControlnode is checked for its theme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.Method Descriptions
- bool _clips_input ( ) virtual
_gui_input should not be called for children controls outside this control’s rectangle. Input will be clipped to the Rect of this
Control. Similar to rect_clip_content, but doesn’t affect visibility.false.
- Vector2 _get_minimum_size ( ) virtual
rect_min_size for controlling minimum size via code. The actual minimum size will be the max value of these two (in each axis separately).
Vector2.ZERO.
Note: This method will not be called when the script is attached to a
Controlnode 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.
- _gui_input ( InputEvent event ) virtual
accept_event.
Example: clicking a control.
The event won’t trigger if: has_point); mouse_filter set to MOUSE_FILTER_IGNORE;func _gui_input(event): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT and event.pressed: print("I've been clicked D:")
Controlon top of it, which doesn’t have mouse_filter set to MOUSE_FILTER_IGNORE; mouse_filter set to MOUSE_FILTER_STOP or has accepted the event; rect_clip_content or _clips_input enabled. Note: Event position is relative to the control origin.
- Control _make_custom_tooltip ( String for_text ) virtual
Controlnode that should be used as a tooltip instead of the default one. Thefor_textincludes the contents of the hint_tooltip property.Controlor 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). Whennullor a non-Control node is returned, the default tooltip will be used instead. PopupPanel, so you should only provide the contents of that panel. That PopupPanel can be themed using Theme.set_stylebox for the type"TooltipPanel"(see hint_tooltip for an example). Note: The tooltip is shrunk to minimal size. If you want to ensure it’s fully visible, you might want to set its rect_min_size to some non-zero value. Example of usage with a custom-constructed node:
Example of usage with a custom scene instance:func _make_custom_tooltip(for_text): var label = Label.new() label.text = for_text return label
func _make_custom_tooltip(for_text): var tooltip = preload("res://SomeTooltipScene.tscn").instance() tooltip.get_node("Label").text = for_text return tooltip
- accept_event ( ) Node._unhandled_input or Node._unhandled_key_input.
- add_color_override ( String name, Color color )
Color with the specified
name. Local overrides always take precedence when fetching theme items for the control. get_color, remove_color_override. Example of overriding a label’s color and resetting it later:# Given the child Label node "MyLabel", override its font color with a custom value.$MyLabel.add_color_override("font_color", Color(1, 0.5, 0))# Reset the font color of the child label.$MyLabel.add_color_override("font_color", get_color("font_color", "Label"))
- add_constant_override ( String name, int constant )
name. Local overrides always take precedence when fetching theme items for the control. get_constant, remove_constant_override.
- add_font_override ( String name, Font font )
Font with the specified
name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it anullvalue. This behavior is deprecated and will be removed in 4.0, use remove_font_override instead. get_font.
- add_icon_override ( String name, Texture texture )
name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it anullvalue. This behavior is deprecated and will be removed in 4.0, use remove_icon_override instead. get_icon.
- add_shader_override ( String name, Shader shader )
name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it anullvalue. This behavior is deprecated and will be removed in 4.0, use remove_shader_override instead.
- add_stylebox_override ( String name, StyleBox stylebox )
StyleBox with the specified
name. Local overrides always take precedence when fetching theme items for the control. Note: An override can be removed by assigning it anullvalue. This behavior is deprecated and will be removed in 4.0, use remove_stylebox_override instead. get_stylebox. Example of modifying a property in a StyleBox by duplicating it:# The snippet below assumes the child node MyButton has a StyleBoxFlat assigned.# Resources are shared across instances, so we need to duplicate it# to avoid modifying the appearance of all other buttons.var new_stylebox_normal = $MyButton.get_stylebox("normal").duplicate()new_stylebox_normal.border_width_top = 3new_stylebox_normal.border_color = Color(0, 1, 0.5)$MyButton.add_stylebox_override("normal", new_stylebox_normal)# Remove the stylebox override.$MyButton.add_stylebox_override("normal", null)
- bool can_drop_data ( Vector2 position, Variant data ) virtual
datafrom a control’s get_drag_data can be dropped atposition.positionis local to this control. drop_data.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")
- drop_data ( Vector2 position, Variant data ) virtual
datafrom a control’s get_drag_data result. Godot first calls can_drop_data to test ifdatais allowed to drop atpositionwherepositionis local to this control.func can_drop_data(position, data): return typeof(data) == TYPE_DICTIONARY and data.has("color")func drop_data(position, data): color = data["color"]
- Control find_next_valid_focus ( ) const
Controlthat can receive the focus.
- Control find_prev_valid_focus ( ) const
Controlthat can receive the focus.
- force_drag ( Variant data, Control preview )
get_drag_data and set_drag_preview by passing
dataandpreview. Drag will start even if the mouse is neither over nor pressed on this control. can_drop_data and drop_data must be implemented on controls that want to receive drop data.
- float get_anchor ( Margin margin ) const
marginconstant from Margin enum. A getter method for anchor_bottom, anchor_left, anchor_right and anchor_top.
- Vector2 get_begin ( ) const margin_left and margin_top. See also rect_position.
- Color get_color ( String name, String theme_type=”” ) const
Color from the first matching Theme in the tree if that Theme has a color item with the specified
nameandtheme_type. Iftheme_typeis omitted the class name of the current control is used as the type, or theme_type_variation if it is defined. If the type is a class name its parent classes are also checked, in order of inheritance. add_color_override), then its assigned theme. After the current control, each parent control and its assigned theme are considered; controls without a theme assigned are skipped. If no matching Theme is found in the tree, a custom project Theme (see ProjectSettings.gui/theme/custom) and the default Theme are used.func _ready(): # Get the font color defined for the current Control's class, if it exists. modulate = get_color("font_color") # Get the font color defined for the Button class. modulate = get_color("font_color", "Button")
- Vector2 get_combined_minimum_size ( ) const rect_min_size and get_minimum_size.
- int get_constant ( String name, String theme_type=”” ) const
Theme in the tree if that Theme has a constant item with the specified
nameandtheme_type. get_color for details.
- CursorShape get_cursor_shape ( Vector2 position=Vector2( 0, 0 ) ) const CursorShape.
- Variant get_drag_data ( Vector2 position ) virtual
nullif there is no data to drag. Controls that want to receive drop data should implement can_drop_data and drop_data.positionis local to this control. Drag may be forced with force_drag. set_drag_preview. A good time to set the preview is in this method.func get_drag_data(position): var mydata = make_data() set_drag_preview(make_preview(mydata)) return mydata
- Vector2 get_end ( ) const margin_right and margin_bottom.
- NodePath get_focus_neighbour ( Margin margin ) const
marginconstant from Margin enum. A getter method for focus_neighbour_bottom, focus_neighbour_left, focus_neighbour_right and focus_neighbour_top.
- Control get_focus_owner ( ) const
nullif none.
- Font get_font ( String name, String theme_type=”” ) const
Font from the first matching Theme in the tree if that Theme has a font item with the specified
nameandtheme_type. get_color for details.
- Rect2 get_global_rect ( ) const rect_position and rect_size.
- Texture get_icon ( String name, String theme_type=”” ) const
Theme in the tree if that Theme has an icon item with the specified
nameandtheme_type. get_color for details.
- float get_margin ( Margin margin ) const
marginconstant from Margin enum. A getter method for margin_bottom, margin_left, margin_right and margin_top.
- Vector2 get_minimum_size ( ) const rect_min_size.
- Vector2 get_parent_area_size ( ) const Returns the width/height occupied in the parent control.
- Control get_parent_control ( ) const Returns the parent control node.
- Rect2 get_rect ( ) const rect_position and rect_size.
- float get_rotation ( ) const Returns the rotation (in radians).
- StyleBox get_stylebox ( String name, String theme_type=”” ) const
StyleBox from the first matching Theme in the tree if that Theme has a stylebox item with the specified
nameandtheme_type. get_color for details.
- Font get_theme_default_font ( ) const Theme in the tree if that Theme has a valid Theme.default_font value. get_color for details.
- String get_tooltip ( Vector2 at_position=Vector2( 0, 0 ) ) const hint_tooltip.
- grab_click_focus ( )
InputEventMouseButton that attempts to click the control. If the event is received, the control acquires focus.
func _process(delta): grab_click_focus() #when clicking another Control node, this node will be clicked instead
- grab_focus ( ) focus_mode).
- bool has_color ( String name, String theme_type=”” ) const
trueif there is a matching Theme in the tree that has a color item with the specifiednameandtheme_type. get_color for details.
- bool has_color_override ( String name ) const
trueif there is a local override for a theme Color with the specifiednamein thisControlnode. add_color_override.
- bool has_constant ( String name, String theme_type=”” ) const
trueif there is a matching Theme in the tree that has a constant item with the specifiednameandtheme_type. get_color for details.
- bool has_constant_override ( String name ) const
trueif there is a local override for a theme constant with the specifiednamein thisControlnode. add_constant_override.
- bool has_focus ( ) const
trueif this is the current focused control. See focus_mode.
- bool has_font ( String name, String theme_type=”” ) const
trueif there is a matching Theme in the tree that has a font item with the specifiednameandtheme_type. get_color for details.
- bool has_font_override ( String name ) const
trueif there is a local override for a theme Font with the specifiednamein thisControlnode. add_font_override.
- bool has_icon ( String name, String theme_type=”” ) const
trueif there is a matching Theme in the tree that has an icon item with the specifiednameandtheme_type. get_color for details.
- bool has_icon_override ( String name ) const
trueif there is a local override for a theme icon with the specifiednamein thisControlnode. add_icon_override.
- bool has_point ( Vector2 point ) virtual
pointis 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 useget_rect().has_point(point).
- bool has_shader_override ( String name ) const
trueif there is a local override for a theme shader with the specifiednamein thisControlnode. add_shader_override.
- bool has_stylebox ( String name, String theme_type=”” ) const
trueif there is a matching Theme in the tree that has a stylebox item with the specifiednameandtheme_type. get_color for details.
- bool has_stylebox_override ( String name ) const
trueif there is a local override for a theme StyleBox with the specifiednamein thisControlnode. add_stylebox_override.
- bool is_drag_successful ( ) const
trueif a drag operation is successful. Alternative to Viewport.gui_is_drag_successful. Node.NOTIFICATION_DRAG_END.
- minimum_size_changed ( ) get_minimum_size when the return value is changed. Setting rect_min_size directly calls this method automatically.
- release_focus ( ) Give up the focus. No other control will be able to receive keyboard input.
- remove_color_override ( String name )
Color with the given
name.
- remove_constant_override ( String name )
name.
- remove_font_override ( String name )
Font with the given
name.
- remove_icon_override ( String name )
name.
- remove_shader_override ( String name )
name.
- remove_stylebox_override ( String name )
StyleBox with the given
name.
- set_anchor ( Margin margin, float anchor, bool keep_margin=false, bool push_opposite_anchor=true )
marginconstant from Margin enum to valueanchor. A setter method for anchor_bottom, anchor_left, anchor_right and anchor_top.keep_marginistrue, margins aren’t updated after this operation.push_opposite_anchoristrueand 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_anchorwasfalse, the left anchor would get value 0.5.
- set_anchor_and_margin ( Margin margin, float anchor, float offset, bool push_opposite_anchor=false )
set_anchor, but instead of
keep_marginargument and automatic update of margin, it allows to set the margin offset yourself (see set_margin).
- set_anchors_and_margins_preset ( LayoutPreset preset, LayoutPresetMode resize_mode=0, int margin=0 ) set_anchors_preset and set_margins_preset.
- set_anchors_preset ( LayoutPreset preset, bool keep_margins=false )
presetfrom LayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.keep_marginsistrue, control’s position will also be updated.
- set_begin ( Vector2 position ) margin_left and margin_top at the same time. Equivalent of changing rect_position.
- set_drag_forwarding ( Control target )
targetcontrol. get_drag_data, can_drop_data, and drop_data but with two differences:
- _fw
- The function must take an extra argument that is the control doing the forwarding
# ThisControl.gdextends Controlfunc _ready(): set_drag_forwarding(target_control)# TargetControl.gdextends Controlfunc can_drop_data_fw(position, data, from_control): return truefunc 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()
- set_drag_preview ( Control control )
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.
export (Color, RGBA) var color = Color(1, 0, 0, 1)func get_drag_data(position): # Use a control that is not in the tree var cpb = ColorPickerButton.new() cpb.color = color cpb.rect_size = Vector2(50, 50) set_drag_preview(cpb) return color
- set_end ( Vector2 position ) margin_right and margin_bottom at the same time.
- set_focus_neighbour ( Margin margin, NodePath neighbour )
marginconstant from Margin enum toControlatneighbornode path. A setter method for focus_neighbour_bottom, focus_neighbour_left, focus_neighbour_right and focus_neighbour_top.
- set_global_position ( Vector2 position, bool keep_margins=false )
rect_global_position to given
position.keep_marginsistrue, control’s anchors will be updated instead of margins.
- set_margin ( Margin margin, float offset )
marginconstant from Margin enum to givenoffset. A setter method for margin_bottom, margin_left, margin_right and margin_top.
- set_margins_preset ( LayoutPreset preset, LayoutPresetMode resize_mode=0, int margin=0 )
presetfrom LayoutPreset enum. This is the code equivalent to using the Layout menu in the 2D editor.resize_modewith constants from LayoutPresetMode 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.marginto determine the gap between theControland the edges.
- set_position ( Vector2 position, bool keep_margins=false )
rect_position to given
position.keep_marginsistrue, control’s anchors will be updated instead of margins.
- set_rotation ( float radians ) Sets the rotation (in radians).
- set_size ( Vector2 size, bool keep_margins=false )
rect_size).
keep_marginsistrue, control’s anchors will be updated instead of margins.
- show_modal ( 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.
exclusiveistrue, other controls will not receive input and clicking outside this control will not close it.
- warp_mouse ( Vector2 to_position )
to_position, relative to rect_position of thisControl.
