Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Control
繼承: CanvasItem < Node < Object
被繼承: BaseButton, ColorRect, Container, GraphEdit, ItemList, Label, LineEdit, MenuBar, NinePatchRect, Panel, Range, ReferenceRect, RichTextLabel, Separator, TabBar, TextEdit, TextureRect, Tree, VideoStreamPlayer, VirtualJoystick
所有 GUI 控制項的基底類別。根據其父控制項調整其位置和大小。
說明
Base class for all UI-related nodes. Control features a bounding rectangle that defines its extents, an anchor position relative to its parent control or the current viewport, and offsets relative to the anchor. The offsets update automatically when the node, any of its parents, or the screen size change.
For more information on Godot's UI system, anchors, offsets, and containers, see the related tutorials in the manual. To build flexible UIs, you'll need a mix of UI elements that inherit from Control and Container nodes.
Note: Since both Node2D and Control inherit from CanvasItem, they share several concepts from the class such as the CanvasItem.z_index and CanvasItem.visible properties.
User Interface nodes and input
Godot propagates input events via viewports. Each Viewport is responsible for propagating InputEvents to their child nodes. As the SceneTree.root is a Window, this already happens automatically for all UI elements in your game.
Input events are propagated through the SceneTree from the root node to all child nodes by calling Node._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.
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.
Only one Control node can be in focus. Only the node in focus will receive 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. Focus will not be represented visually if gained via mouse/touch input, only appearing with keyboard/gamepad input (for accessibility), or via grab_focus().
Set 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. The theme of a Control 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 the add_theme_*_override methods, like add_theme_font_override(). You can also override theme items in 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 the get_theme_* and add_theme_*_override methods provided by this class.
教學
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
physics_interpolation_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField[SizeFlags] |
|
|
|
||
BitField[SizeFlags] |
|
|
|
||
|
||
|
||
|
方法
訊號
focus_entered() 🔗
當該節點獲得焦點時發出。
focus_exited() 🔗
當該節點失去焦點時發出。
gui_input(event: InputEvent) 🔗
當節點收到 InputEvent 時發出。
maximum_size_changed() 🔗
Emitted when the node's maximum size changes.
minimum_size_changed() 🔗
當節點的最小大小更改時發出。
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 its mouse_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 its mouse_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():
if not Rect2(Vector2(), size).has_point(get_local_mouse_position()):
# Not hovering over area.
resized() 🔗
當控制項更改大小時發出。
size_flags_changed() 🔗
當大小旗標之一更改時發出。見 size_flags_horizontal 和 size_flags_vertical。
theme_changed() 🔗
發送 NOTIFICATION_THEME_CHANGED 通知時發出。
列舉
enum FocusMode: 🔗
FocusMode FOCUS_NONE = 0
該節點無法獲取焦點。在 focus_mode 中使用。
FocusMode FOCUS_CLICK = 1
該節點只能通過滑鼠點擊獲取焦點。在 focus_mode 中使用。
FocusMode FOCUS_ALL = 2
該節點可以通過滑鼠按一下、使用鍵盤上的箭頭和 Tab 鍵、或使用遊戲手柄上的方向鍵來獲取焦點。用於 focus_mode。
FocusMode FOCUS_ACCESSIBILITY = 3
The node can grab focus only when screen reader is active. Use with focus_mode.
enum FocusBehaviorRecursive: 🔗
FocusBehaviorRecursive FOCUS_BEHAVIOR_INHERITED = 0
Inherits the focus_behavior_recursive from the parent control. If there is no parent control, this is the same as FOCUS_BEHAVIOR_ENABLED.
FocusBehaviorRecursive FOCUS_BEHAVIOR_DISABLED = 1
Prevents the control from getting focused. get_focus_mode_with_override() will return FOCUS_NONE.
FocusBehaviorRecursive FOCUS_BEHAVIOR_ENABLED = 2
Allows the control to be focused, depending on the focus_mode. This can be used to ignore the parent's focus_behavior_recursive. get_focus_mode_with_override() will return the focus_mode.
enum MouseBehaviorRecursive: 🔗
MouseBehaviorRecursive MOUSE_BEHAVIOR_INHERITED = 0
Inherits the mouse_behavior_recursive from the parent control. If there is no parent control, this is the same as MOUSE_BEHAVIOR_ENABLED.
MouseBehaviorRecursive MOUSE_BEHAVIOR_DISABLED = 1
Prevents the control from receiving mouse input. get_mouse_filter_with_override() will return MOUSE_FILTER_IGNORE.
MouseBehaviorRecursive MOUSE_BEHAVIOR_ENABLED = 2
Allows the control to receive mouse input, depending on the mouse_filter. This can be used to ignore the parent's mouse_behavior_recursive. get_mouse_filter_with_override() will return the mouse_filter.
enum CursorShape: 🔗
CursorShape CURSOR_ARROW = 0
當使用者將節點懸停時,顯示系統的箭頭滑鼠游標。與 mouse_default_cursor_shape 成員一起使用。
CursorShape CURSOR_IBEAM = 1
當使用者將節點懸停時,顯示系統的 I 型光束滑鼠游標。工字梁指針的形狀類似於“I”。它告訴使用者他們可以突出顯示或插入文字。
CursorShape CURSOR_POINTING_HAND = 2
當使用者將節點懸停時,顯示系統的手形滑鼠游標。
CursorShape CURSOR_CROSS = 3
當使用者將滑鼠懸停在節點上時,顯示系統的交叉滑鼠游標。
CursorShape CURSOR_WAIT = 4
當使用者懸停節點時,顯示系統等待的滑鼠游標。通常是一個沙漏。
CursorShape CURSOR_BUSY = 5
當使用者懸停節點時,顯示系統繁忙的滑鼠游標。通常是箭頭加一個小沙漏。
CursorShape CURSOR_DRAG = 6
當使用者懸停在節點上時,顯示系統的拖動滑鼠游標,通常是一個閉合的拳頭或十字元號。它告訴使用者他們目前正在拖動一個專案,例如場景面板中的節點。
CursorShape CURSOR_CAN_DROP = 7
當使用者懸停節點時,顯示系統的落地滑鼠游標。它可以是一個張開的手。它告訴使用者可以放下一個他們目前正在抓取的物品,比如場景面板中的一個節點。
CursorShape CURSOR_FORBIDDEN = 8
當使用者懸停節點時,顯示系統禁止的滑鼠游標。通常是一個交叉的圓圈。
CursorShape CURSOR_VSIZE = 9
當使用者懸停節點時,顯示系統的垂直調整滑鼠游標。一個雙頭的垂直箭頭。它告訴使用者可以垂直調整視窗或面板的大小。
CursorShape CURSOR_HSIZE = 10
當使用者懸停節點時,顯示系統的水平調整滑鼠游標。一個雙頭的水平箭頭。它告訴使用者可以水平調整視窗或面板的大小。
CursorShape CURSOR_BDIAGSIZE = 11
當使用者將節點懸停時,顯示系統視窗調整大小的滑鼠游標。游標是從左下角到右上角的雙向箭頭。它告訴使用者可以水平和垂直調整視窗或面板的大小。
CursorShape CURSOR_FDIAGSIZE = 12
當使用者將節點懸停時,顯示系統視窗調整大小的滑鼠游標。游標是一個雙向箭頭,從左上角到右下角,與 CURSOR_BDIAGSIZE 相反。它告訴使用者可以水平和垂直調整視窗或面板的大小。
CursorShape CURSOR_MOVE = 13
當使用者將節點懸停時,顯示系統的移動滑鼠游標。它以 90 度角顯示 2 個雙向箭頭。它告訴使用者他們可以自由移動 UI 元素。
CursorShape CURSOR_VSPLIT = 14
當使用者將節點懸停時,顯示系統的垂直拆分滑鼠游標。在 Windows 上與 CURSOR_VSIZE 相同。
CursorShape CURSOR_HSPLIT = 15
當使用者將節點懸停時,顯示系統的水平拆分滑鼠游標。在 Windows 上與 CURSOR_HSIZE 相同。
CursorShape CURSOR_HELP = 16
當使用者將節點懸停在一個節點上時,顯示系統的説明滑鼠游標,一個問號。
enum LayoutPreset: 🔗
LayoutPreset PRESET_TOP_LEFT = 0
將所有 4 個錨點對齊到父控制項邊界的左上角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_TOP_RIGHT = 1
將所有 4 個錨點對齊到父控制項邊界的右上角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_BOTTOM_LEFT = 2
將所有 4 個錨點對齊到父控制項邊界的左下角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_BOTTOM_RIGHT = 3
將所有 4 個錨點對齊到父控制項邊界的右下角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_CENTER_LEFT = 4
將所有 4 個錨點對齊到父控制項邊界的左邊緣的中點。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_CENTER_TOP = 5
將所有 4 個錨點對齊到父控制項邊界的頂邊緣的中點。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_CENTER_RIGHT = 6
將所有 4 個錨點對齊到父控制項邊界的右邊緣的中點。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_CENTER_BOTTOM = 7
將所有 4 個錨點對齊到父控制項邊界的底邊緣的中點。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_CENTER = 8
將所有 4 個錨點對齊到父控制項邊界的中心。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_LEFT_WIDE = 9
將所有 4 個錨點對齊到父控制項的左邊緣。左偏移量相對於父節點的左邊緣,上偏移量相對於父節點的左上角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_TOP_WIDE = 10
將所有 4 個錨點對齊到父控制項的上邊緣。左偏移量相對於父節點的左上角,上偏移量相對於父節點的上邊緣,右偏移相對於父節點的右上角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_RIGHT_WIDE = 11
將所有 4 個錨點對齊到父控制項的右邊緣。右偏移量相對於父節點的右邊緣,上偏移量相對於父節點的右上角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_BOTTOM_WIDE = 12
將所有 4 個錨點對齊到父控制項的下邊緣。左偏移量相對於父節點的左下角,下偏移量相對於父節點的下邊緣,右偏移相對於父節點的右下角。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_VCENTER_WIDE = 13
將所有 4 個錨點對齊到一條垂直線,該垂直線將父控制項切成兩半。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_HCENTER_WIDE = 14
將所有 4 個錨點對齊到一條水平線,該水平線將父控制項切成兩半。與 set_anchors_preset() 一起使用。
LayoutPreset PRESET_FULL_RECT = 15
將所有 4 個錨點對齊到父控制項對應的角。套用此預設後,會將所有 4 個偏移都設定為 0,該 Control 將適合其父控制項。與 set_anchors_preset() 一起使用。
enum LayoutPresetMode: 🔗
LayoutPresetMode PRESET_MODE_MINSIZE = 0
控制項將被調整為最小尺寸。
LayoutPresetMode PRESET_MODE_KEEP_WIDTH = 1
控制項的寬度不會改變。
LayoutPresetMode PRESET_MODE_KEEP_HEIGHT = 2
控制項的高度不會改變。
LayoutPresetMode PRESET_MODE_KEEP_SIZE = 3
控制項的大小不會改變。
flags SizeFlags: 🔗
SizeFlags SIZE_SHRINK_BEGIN = 0
告訴父級 Container 將該節點與其起點對齊,即頂部或左側。它與 SIZE_FILL 以及其他收縮大小旗標互斥,但可以在某些容器中與 SIZE_EXPAND 一起使用。與 size_flags_horizontal 和 size_flags_vertical 一起使用。
注意:設定這個旗標相當於沒有任何大小旗標。
SizeFlags SIZE_FILL = 1
告訴父級 Container 擴充該節點的邊界以填充所有可用空間,而無需推動任何其他節點。它與收縮大小旗標互斥。與 size_flags_horizontal 和 size_flags_vertical 一起使用。
SizeFlags SIZE_EXPAND = 2
告訴父級 Container 讓該節點佔用你標記的軸上的所有可用空間。如果將多個相鄰節點設定為擴充,它們將根據其拉伸比共用空間。見 size_flags_stretch_ratio。用於 size_flags_horizontal 和 size_flags_vertical。
SizeFlags SIZE_EXPAND_FILL = 3
將該節點的大小旗標設定為填充和擴充。有關詳細資訊,請參閱 SIZE_FILL 和 SIZE_EXPAND。
SizeFlags SIZE_SHRINK_CENTER = 4
告訴父級 Container 將節點置於可用空間的中心。它與 SIZE_FILL 以及其他收縮大小旗標互斥,但可以在某些容器中與 SIZE_EXPAND 一起使用。與 size_flags_horizontal 和 size_flags_vertical 一起使用。
SizeFlags SIZE_SHRINK_END = 8
告訴父級 Container 將節點與其末端對齊,即底部或右側。它與 SIZE_FILL 以及其他收縮大小旗標互斥,但可以在某些容器中與 SIZE_EXPAND 一起使用。與 size_flags_horizontal 和 size_flags_vertical 一起使用。
enum MouseFilter: 🔗
MouseFilter MOUSE_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 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.
MouseFilter MOUSE_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 the mouse_entered and mouse_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 with MOUSE_FILTER_STOP, or a CanvasItem with CanvasItem.top_level enabled. This will allow signals to fire in all controls it reaches. If no control handled it, the event will be passed to Node._shortcut_input() for further processing.
MouseFilter MOUSE_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 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. If a child has MOUSE_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 received mouse_entered but not mouse_exited, changing the mouse_filter to MOUSE_FILTER_IGNORE will cause mouse_exited to be emitted.
enum GrowDirection: 🔗
GrowDirection GROW_DIRECTION_BEGIN = 0
如果控制項的最小尺寸更改為大於其相應軸上的目前尺寸,則控制項將向左或頂部增大以進行組合。
GrowDirection GROW_DIRECTION_END = 1
如果控制項的最小尺寸更改為大於其相應軸上的目前尺寸,則控制項將向右或向下增大以進行補償。
GrowDirection GROW_DIRECTION_BOTH = 2
如果控制項的最小大小更改為大於其目前大小,則控制項將在兩個方向上均等地增長以組成該控制項。
enum Anchor: 🔗
Anchor ANCHOR_BEGIN = 0
將 4 個錨點的某一側吸附到節點的 Rect 的左上角。在 anchor_* 成員變數中使用,例如 anchor_left。要一次更改全部 4 個錨點,請使用 set_anchors_preset()。
Anchor ANCHOR_END = 1
將 4 個錨點的某一側吸附到節點的 Rect 的右下角。在 anchor_* 成員變數中使用,例如 anchor_left。要一次更改全部 4 個錨點,請使用 set_anchors_preset()。
enum LayoutDirection: 🔗
LayoutDirection LAYOUT_DIRECTION_INHERITED = 0
自動佈局方向,由父控制項佈局方向決定。
LayoutDirection LAYOUT_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 in ProjectSettings.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 using TextServerFallback (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 using ProjectSettings.internationalization/rendering/force_right_to_left_layout_direction.
LayoutDirection LAYOUT_DIRECTION_LTR = 2
從左至右的佈局方向。
LayoutDirection LAYOUT_DIRECTION_RTL = 3
從右至左的佈局方向。
LayoutDirection LAYOUT_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 using TextServerFallback (ProjectSettings.internationalization/rendering/text_driver), left-to-right layout direction is always used regardless of the language.
LayoutDirection LAYOUT_DIRECTION_MAX = 5
Represents the size of the LayoutDirection enum.
LayoutDirection LAYOUT_DIRECTION_LOCALE = 1
已棄用: Use LAYOUT_DIRECTION_APPLICATION_LOCALE instead.
enum TextDirection: 🔗
TextDirection TEXT_DIRECTION_INHERITED = 3
文字書寫方向與佈局方向相同。
TextDirection TEXT_DIRECTION_AUTO = 0
自動文字書寫方向,根據目前區域設定和文字內容確定。
TextDirection TEXT_DIRECTION_LTR = 1
從左至右的文字書寫方向。
TextDirection TEXT_DIRECTION_RTL = 2
從右至左的文字書寫方向。
常數
NOTIFICATION_RESIZED = 40 🔗
當節點改變大小時發送。請使用 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 its mouse_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 also NOTIFICATION_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 its mouse_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 also NOTIFICATION_MOUSE_EXIT_SELF.
NOTIFICATION_MOUSE_ENTER_SELF = 60 🔗
實驗性: 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 its mouse_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 also NOTIFICATION_MOUSE_ENTER.
NOTIFICATION_MOUSE_EXIT_SELF = 61 🔗
實驗性: 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 its mouse_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 also NOTIFICATION_MOUSE_EXIT.
NOTIFICATION_FOCUS_ENTER = 43 🔗
當節點獲得焦點時發送。
NOTIFICATION_FOCUS_EXIT = 44 🔗
Sent when the node loses focus.
This notification is sent in reversed order.
NOTIFICATION_THEME_CHANGED = 45 🔗
Sent when the node needs to refresh its theme items. This happens in one of the following cases:
The theme property is changed on this node or any of its ancestors.
The theme_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 alongside Node.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 using Node.is_node_ready().
func _notification(what):
if what == NOTIFICATION_THEME_CHANGED:
if not is_node_ready():
await ready # Wait until ready signal.
$Label.add_theme_color_override("font_color", Color.YELLOW)
NOTIFICATION_SCROLL_BEGIN = 47 🔗
Sent when this node is inside a ScrollContainer which has begun being scrolled when dragging the scrollable area with a touch event. This notification is not sent when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.
Note: This signal is only emitted on Android or iOS, or on desktop/web platforms when ProjectSettings.input_devices/pointing/emulate_touch_from_mouse is enabled.
NOTIFICATION_SCROLL_END = 48 🔗
Sent when this node is inside a ScrollContainer which has stopped being scrolled when dragging the scrollable area with a touch event. This notification is not sent when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.
Note: This signal is only emitted on Android or iOS, or on desktop/web platforms when ProjectSettings.input_devices/pointing/emulate_touch_from_mouse is enabled.
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 to layout_direction.
屬性說明
Array[NodePath] accessibility_controls_nodes = [] 🔗
The paths to the nodes which are controlled by this node.
Array[NodePath] accessibility_described_by_nodes = [] 🔗
The paths to the nodes which are describing this node.
String accessibility_description = "" 🔗
The human-readable node description that is reported to assistive apps.
Array[NodePath] accessibility_flow_to_nodes = [] 🔗
The paths to the nodes which this node flows into.
Array[NodePath] accessibility_labeled_by_nodes = [] 🔗
The paths to the nodes which label this node.
AccessibilityLiveMode accessibility_live = 0 🔗
void set_accessibility_live(value: AccessibilityLiveMode)
AccessibilityLiveMode get_accessibility_live()
The mode with which a live region updates. A live region is a Node that is updated as a result of an external event when the user's focus may be elsewhere.
String accessibility_name = "" 🔗
The human-readable node name that is reported to assistive apps.
將節點的底部邊緣錨定到父控制項的原點、中心或末端。會改變該節點發生移動或改變大小時底部偏移量的更新方式。方便起見,你可以使用 Anchor 常數。
將節點的左側邊緣錨定到父控制項的原點、中心或末端。會改變該節點發生移動或改變大小時左側偏移量的更新方式。方便起見,你可以使用 Anchor 常數。
將節點的右側邊緣錨定到父控制項的原點、中心或末端。會改變該節點發生移動或改變大小時右側偏移量的更新方式。方便起見,你可以使用 Anchor 常數。
將節點的頂部邊緣錨定到父控制項的原點、中心或末端。會改變該節點發生移動或改變大小時頂部偏移量的更新方式。方便起見,你可以使用 Anchor 常數。
已棄用: Use Node.auto_translate_mode and Node.can_auto_translate() instead.
切換是否所有文字都應該根據目前區域設定自動變為翻譯後的版本。
算繪基於 CanvasItem 的子節點時,是否應剪裁到該控制項的矩形中。如果為 true,則子節點顯示在該控制項的矩形範圍之外的部分,不會算繪,也不會接收輸入。
Vector2 custom_maximum_size = Vector2(-1, -1) 🔗
The maximum size of this Control's bounding rectangle. If set to a value greater than or equal to (0, 0), the node's bounding rectangle will never exceed this size. A value below (0, 0) means there is no maximum size.
Note: The final effective maximum size may be subject to parent Container sizing and propagated maximum sizes. See also: get_combined_maximum_size().
Note: Not all Control subtypes handle a custom maximum size gracefully, which may lead to unexpected behavior if the control's contents exceed this size.
Note: This value has priority over custom_minimum_size. For example, if you set custom_maximum_size to (100, 100) and custom_minimum_size to (200, 200), the resulting size will be (100, 100).
Note: It is recommended to use get_bound_minimum_size() instead of get_combined_minimum_size() when using this property, as the former respects maximum size limits when calculating the minimum size, while the latter does not.
Vector2 custom_minimum_size = Vector2(0, 0) 🔗
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 that Control nodes have their internal minimum size returned by get_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 (see get_combined_minimum_size()).
Note: custom_maximum_size has priority over this property. For example, if you set custom_minimum_size to (200, 200) and custom_maximum_size to (100, 100), the resulting size will be (100, 100).
FocusBehaviorRecursive focus_behavior_recursive = 0 🔗
void set_focus_behavior_recursive(value: FocusBehaviorRecursive)
FocusBehaviorRecursive get_focus_behavior_recursive()
Determines which controls can be focused together with focus_mode. See get_focus_mode_with_override(). Since the default behavior is FOCUS_BEHAVIOR_INHERITED, this can be used to prevent all children controls from getting focused.
Determines which controls can be focused. Only one control can be focused at a time, and the focused control will receive keyboard, gamepad, and mouse events in _gui_input(). Use get_focus_mode_with_override() to determine if a control can grab focus, since focus_behavior_recursive also affects it. See also grab_focus().
NodePath focus_neighbor_bottom = NodePath("") 🔗
告訴 Godot 當使用者按下鍵盤上的下方向鍵或遊戲手柄上的下方向鍵時,預設應該將焦點移交給哪個節點。你可以通過編輯輸入動作 ProjectSettings.input/ui_down 來修改具體的按鍵。該節點必須為 Control。如果未設定這個屬性,Godot 會將焦點移交給該節點下方距離最近的 Control。
NodePath focus_neighbor_left = NodePath("") 🔗
告訴 Godot 當使用者按下鍵盤上的左方向鍵或遊戲手柄上的左方向鍵時,預設應該將焦點移交給哪個節點。你可以通過編輯輸入動作 ProjectSettings.input/ui_left 來修改具體的按鍵。該節點必須為 Control。如果未設定這個屬性,Godot 會將焦點移交給該節點左側距離最近的 Control。
NodePath focus_neighbor_right = NodePath("") 🔗
告訴 Godot 當使用者按下鍵盤上的右方向鍵或遊戲手柄上的右方向鍵時,預設應該將焦點移交給哪個節點。你可以通過編輯輸入動作 ProjectSettings.input/ui_right 來修改具體的按鍵。該節點必須為 Control。如果未設定這個屬性,Godot 會將焦點移交給該節點右側距離最近的 Control。
NodePath focus_neighbor_top = NodePath("") 🔗
告訴 Godot 當使用者按下鍵盤上的下方向鍵或遊戲手柄上的下方向鍵時,預設應該將焦點移交給哪個節點。你可以通過編輯輸入動作 ProjectSettings.input/ui_up 來修改具體的按鍵。該節點必須為 Control。如果未設定這個屬性,Godot 會將焦點移交給該節點上方距離最近的 Control。
NodePath focus_next = NodePath("") 🔗
告訴 Godot 在預設情況下,當使用者按下鍵盤上的 Tab 時,應將焦點交給哪個節點。你可以通過編輯 ProjectSettings.input/ui_focus_next 的輸入動作來更改按鍵。
如果未設定此屬性,則 Godot 會將根據場景樹中的附近節點選擇一個“最佳猜測”。
NodePath focus_previous = NodePath("") 🔗
告訴 Godot 在預設情況下,當使用者按下鍵盤上的 Shift + Tab 時,應將焦點交給哪個節點。你可以通過編輯 ProjectSettings.input/ui_focus_prev 的輸入動作來更改按鍵。
如果未設定此屬性,則 Godot 會將根據場景樹中的附近節點選擇一個“最佳猜測”。
Vector2 get_global_position()
該節點的全域位置,相對於世界(通常為 CanvasLayer)。
GrowDirection grow_horizontal = 1 🔗
void set_h_grow_direction(value: GrowDirection)
GrowDirection get_h_grow_direction()
控制水平軸的方向,如果控制項的水平最小尺寸更改為大於其目前尺寸,則控制項應沿水平軸增長,因為控制項始終必須至少為最小尺寸。
GrowDirection grow_vertical = 1 🔗
void set_v_grow_direction(value: GrowDirection)
GrowDirection get_v_grow_direction()
控制控制項在垂直軸上的方向,如果控制項的垂直最小尺寸更改為大於目前尺寸,則控制項應沿該方向增大,因為控制項始終必須至少為最小尺寸。
LayoutDirection layout_direction = 0 🔗
void set_layout_direction(value: LayoutDirection)
LayoutDirection get_layout_direction()
Controls layout direction and text writing direction. Right-to-left layouts are necessary for certain languages (e.g. Arabic and Hebrew). See also is_layout_rtl().
bool localize_numeral_system = true 🔗
如果為 true,則會自動將程式碼行號、列表索引號、SpinBox 和 ProgressBar 的值,從阿拉伯數字(0..9)轉換為目前區域設定所使用的記數系統。
注意:不會自動轉換文字中的數位,可以使用 TextServer.format_number() 手動轉換。
MouseBehaviorRecursive mouse_behavior_recursive = 0 🔗
void set_mouse_behavior_recursive(value: MouseBehaviorRecursive)
MouseBehaviorRecursive get_mouse_behavior_recursive()
Determines which controls can receive mouse input together with mouse_filter. See get_mouse_filter_with_override(). Since the default behavior is MOUSE_BEHAVIOR_INHERITED, this can be used to prevent all children controls from receiving mouse input.
CursorShape mouse_default_cursor_shape = 0 🔗
void set_default_cursor_shape(value: CursorShape)
CursorShape get_default_cursor_shape()
此控制項的預設游標形狀。對於 Godot 外掛程式和使用系統滑鼠游標的套用程式或遊戲很有用。
注意:在 Linux 上,形狀可能會有所不同,具體取決於系統的游標主題。
MouseFilter mouse_filter = 0 🔗
void set_mouse_filter(value: MouseFilter)
MouseFilter get_mouse_filter()
Determines which controls will be able to receive mouse button input events through _gui_input() and the mouse_entered, and mouse_exited signals. Also determines how these events should be propagated. See the constants to learn what each does. Use get_mouse_filter_with_override() to determine if a control can receive mouse input, since mouse_behavior_recursive also affects it.
bool mouse_force_pass_scroll_events = true 🔗
When enabled, scroll wheel events processed by _gui_input() will be passed to the parent control even if mouse_filter is set to MOUSE_FILTER_STOP.
You should disable it on the root of your UI if you do not want scroll events to go to the Node._unhandled_input() processing.
Note: Because this property defaults to true, this allows nested scrollable containers to work out of the box.
該節點底部邊緣與其父控制項之間的距離,基於 anchor_bottom。
偏移量通常由一個或多個父 Container 節點控制,因此如果你的節點是 Container 的直接子節點,則不應進行手動修改。移動節點或調整節點大小時,偏移量會自動更新。
該節點左側邊緣與其父控制項之間的距離,基於 anchor_left。
偏移量通常由一個或多個父 Container 節點控制,因此如果你的節點是 Container 的直接子節點,則不應進行手動修改。移動節點或調整節點大小時,偏移量會自動更新。
該節點右側邊緣與其父控制項之間的距離,基於 anchor_right。
偏移量通常由一個或多個父 Container 節點控制,因此如果你的節點是 Container 的直接子節點,則不應進行手動修改。移動節點或調整節點大小時,偏移量會自動更新。
該節點頂部邊緣與其父控制項之間的距離,基於 anchor_top。
偏移量通常由一個或多個父 Container 節點控制,因此如果你的節點是 Container 的直接子節點,則不應進行手動修改。移動節點或調整節點大小時,偏移量會自動更新。
bool offset_transform_enabled = false 🔗
If true, applies all offset transform properties. Otherwise, no offset transform is applied and the properties have no effect.
Vector2 offset_transform_pivot = Vector2(0, 0) 🔗
Pivot used by offset_transform_rotation and offset_transform_scale in absolute units.
The final pivot position is the combined value of this property and offset_transform_pivot_ratio.
Has no effect unless offset_transform_enabled is true.
Vector2 offset_transform_pivot_ratio = Vector2(0.5, 0.5) 🔗
Same as offset_transform_pivot but expressed in units relative to the Control size where Vector2(0, 0) is the top-left corner of this control, and Vector2(1, 1) is its bottom-right corner.
The final pivot position is the combined value of this property and offset_transform_pivot.
Has no effect unless offset_transform_enabled is true.
Vector2 offset_transform_position = Vector2(0, 0) 🔗
Position offset in absolute units. The final offset is the combined value of this property and offset_transform_position_ratio.
Has no effect unless offset_transform_enabled is true.
Vector2 offset_transform_position_ratio = Vector2(0, 0) 🔗
void set_offset_transform_position_ratio(value: Vector2)
Vector2 get_offset_transform_position_ratio()
Same as offset_transform_position but expressed in units relative to the Control size where Vector2(0, 0) is the top-left corner of this control, and Vector2(1, 1) is its bottom-right corner.
The final offset is the combined value of this property and offset_transform_position.
Has no effect unless offset_transform_enabled is true.
float offset_transform_rotation = 0.0 🔗
Rotation offset. The rotation pivot is defined by offset_transform_pivot and offset_transform_pivot_ratio.
Has no effect unless offset_transform_enabled is true.
Vector2 offset_transform_scale = Vector2(1, 1) 🔗
Scale offset. The scale pivot is defined by offset_transform_pivot and offset_transform_pivot_ratio.
Has no effect unless offset_transform_enabled is true.
bool offset_transform_visual_only = true 🔗
If true, the offset transforms is only applied visually and does not affect input. In other words, this Control will still receive input events at its original location before the offset transform is applied.
If false, the entire transform of this Control is affected and input events will register where the Control is visually.
Has no effect unless offset_transform_enabled is true.
Vector2 pivot_offset = Vector2(0, 0) 🔗
By default, the node's pivot is its top-left corner. When you change its rotation or scale, it will rotate or scale around this pivot.
The actual offset is the combined value of this property and pivot_offset_ratio.
Vector2 pivot_offset_ratio = Vector2(0, 0) 🔗
Same as pivot_offset, but expressed as uniform vector, where Vector2(0, 0) is the top-left corner of this control, and Vector2(1, 1) is its bottom-right corner. Set this property to Vector2(0.5, 0.5) to pivot around this control's center.
The actual offset is the combined value of this property and pivot_offset.
Vector2 position = Vector2(0, 0) 🔗
Vector2 get_position()
該節點的位置,相對於父節點。對應的是矩形的左上角。該屬性不受 pivot_offset 的影響。
bool propagate_maximum_size = false 🔗
If true, this Control's children will use the value returned by get_combined_maximum_size() in their own size calculations.
節點圍繞其樞紐點的旋轉角度,以弧度為單位。請參閱 pivot_offset 來變更樞紐點的位置。
注意: 這個屬性在屬性檢視器中是以角度編輯的。如果您想在腳本中使用角度,請使用 rotation_degrees。
協助以度數(而非弧度)存取 rotation 的屬性。
Vector2 scale = Vector2(1, 1) 🔗
The node's scale, relative to its size. Change this property to scale the node around its pivot_offset. The Control's tooltip will also scale according to this value.
Note: This property is mainly intended to be used for animation purposes. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the documentation instead of scaling Controls individually.
Note: FontFile.oversampling does not take Control scale into account. This means that scaling up/down will cause bitmap fonts and rasterized (non-MSDF) dynamic fonts to appear blurry or pixelated. To ensure text remains crisp regardless of scale, you can enable MSDF font rendering by enabling ProjectSettings.gui/theme/default_font_multichannel_signed_distance_field (applies to the default project font only), or enabling Multichannel Signed Distance Field in the import options of a DynamicFont for custom fonts. On system fonts, SystemFont.multichannel_signed_distance_field can be enabled in the inspector.
Note: If the Control node is a child of a Container node, the scale will be reset to Vector2(1, 1) when the scene is instantiated. To set the Control's scale when it's instantiated, wait for one frame using await get_tree().process_frame then set its scale property.
該 Node 必須是被聚焦 Control 的父節點,才能啟動快捷方式。如果為 null,則可以在任何控制項獲得焦點時啟動該快捷方式(全域快捷方式)。這允許快捷方式只在使用者聚焦 GUI 的特定區域時才被接受。
Vector2 size = Vector2(0, 0) 🔗
Vector2 get_size()
該節點的邊界矩形的大小,使用該節點的坐標系。Container 節點會自動更新此屬性。
BitField[SizeFlags] size_flags_horizontal = 1 🔗
告訴父 Container 節點應如何調整尺寸並將其放置在 X 軸上。請使用 SizeFlags 常數的組合來更改旗標。查看常數以瞭解每個常數的作用。
float size_flags_stretch_ratio = 1.0 🔗
如果該節點及其至少一個鄰居節點使用 SIZE_EXPAND 大小旗標,則父 Container 將根據該屬性讓它佔用更多或更少的空間。如果該節點的拉伸比為 2,其鄰居節點的拉伸比為 1,則該節點將佔用三分之二的可用空間。
BitField[SizeFlags] size_flags_vertical = 1 🔗
告訴父 Container 節點應如何調整尺寸並將其放置在 Y 軸上。請使用 SizeFlags 常數的組合來更改旗標。查看常數以瞭解每個常數的作用。
該節點及其子 Control 和 Window 所使用的 Theme 資源。如果子節點也設定了 Theme 資源,則會合並主題項,子節點的定義優先順序更高。
注意:除非 Window 為嵌入式,否則視窗樣式無效。
StringName theme_type_variation = &"" 🔗
void set_theme_type_variation(value: StringName)
StringName get_theme_type_variation()
The name of a theme type variation used by this Control to look up its own theme items. When empty, the class name of the node is used (e.g. Button for the Button control), as well as the class names of all parent classes (in order of inheritance).
When set, this property gives the highest priority to the type of the specified name. This type can in turn extend another type, forming a dependency chain. See Theme.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 up Control's own items use various get_theme_* methods without specifying theme_type.
Note: Theme items are looked for in the tree order, from branch to root, where each Control node is checked for its theme property. The earliest match against any type/class name is returned. The project-level Theme and the default Theme are checked last.
AutoTranslateMode tooltip_auto_translate_mode = 0 🔗
void set_tooltip_auto_translate_mode(value: AutoTranslateMode)
AutoTranslateMode get_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 to Node.AUTO_TRANSLATE_MODE_INHERIT.
Note: Tooltips customized using _make_custom_tooltip() do not use this auto translate mode automatically.
The default tooltip text. The tooltip appears when the user's mouse cursor stays idle over this control for a few moments, provided that the mouse_filter property is not MOUSE_FILTER_IGNORE. The time required for the tooltip to appear can be changed with the ProjectSettings.gui/timers/tooltip_delay_sec setting.
This string is the default return value of get_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 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))
var styleBox = new StyleBoxFlat();
styleBox.SetBgColor(new Color(1, 1, 0));
styleBox.SetBorderWidthAll(2);
// We assume here that the `Theme` property has been assigned a custom Theme beforehand.
Theme.SetStyleBox("panel", "TooltipPanel", styleBox);
Theme.SetColor("font_color", "TooltipLabel", new Color(0, 1, 1));
StringName translation_context = &"" 🔗
void set_translation_context(value: StringName)
StringName get_translation_context()
The translation context used when translating this control's displayed text, if it has any. Also used when generating translation templates.
方法說明
String _accessibility_get_contextual_info() virtual const 🔗
Return the description of the keyboard shortcuts and other contextual help for this control.
bool _can_drop_data(at_position: Vector2, data: Variant) virtual const 🔗
Godot calls this method to test if data from a control's _get_drag_data() can be dropped at at_position. at_position is local to this control.
This method should only be used to test the data. Process the data in _drop_data().
Note: If the drag was initiated by a keyboard shortcut or accessibility_drag(), at_position is set to Vector2.INF, and the currently selected item/text position should be used as the drop position.
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")
public override bool _CanDropData(Vector2 atPosition, Variant data)
{
// Check position if it is relevant to you
// Otherwise, just check data
return data.VariantType == Variant.Type.Dictionary && data.AsGodotDictionary().ContainsKey("expected");
}
void _drop_data(at_position: Vector2, data: Variant) virtual 🔗
Godot calls this method to pass you the data from a control's _get_drag_data() result. Godot first calls _can_drop_data() to test if data is allowed to drop at at_position where at_position is local to this control.
Note: If the drag was initiated by a keyboard shortcut or accessibility_drag(), at_position is set to Vector2.INF, and the currently selected item/text position should be used as the drop position.
func _can_drop_data(position, data):
return typeof(data) == TYPE_DICTIONARY and data.has("color")
func _drop_data(position, data):
var color = data["color"]
public override bool _CanDropData(Vector2 atPosition, Variant data)
{
return data.VariantType == Variant.Type.Dictionary && data.AsGodotDictionary().ContainsKey("color");
}
public override void _DropData(Vector2 atPosition, Variant data)
{
Color color = data.AsGodotDictionary()["color"].AsColor();
}
String _get_accessibility_container_name(node: Node) virtual const 🔗
Override this method to return a human-readable description of the position of the child node in the custom container, added to the accessibility_name.
int _get_cursor_shape(at_position: Vector2) virtual const 🔗
Virtual method to be implemented by the user. Returns the cursor shape for the position at_position in the control's local coordinates, which will typically be used while hovering over this control. See get_cursor_shape().
If not overridden, defaults to mouse_default_cursor_shape.
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. Returns null 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 with force_drag().
A preview that will follow the mouse that should represent the data can be set with set_drag_preview(). A good time to set the preview is in this method.
Note: If the drag was initiated by a keyboard shortcut or accessibility_drag(), at_position is set to Vector2.INF, and the currently selected item/text position should be used as the drag position.
func _get_drag_data(position):
var mydata = 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.
return mydata
public override Variant _GetDragData(Vector2 atPosition)
{
var myData = MakeData(); // This is your custom method generating the drag data.
SetDragPreview(MakePreview(myData)); // This is your custom method generating the preview of the drag data.
return myData;
}
Vector2 _get_maximum_size() virtual const 🔗
Virtual method to be implemented by the user. Returns the maximum size for this control. Alternative to custom_maximum_size for controlling maximum size via code. The actual maximum size will be the max value of these two (in each axis separately).
If not overridden, defaults to Vector2.ZERO.
Note: This method will not be called when the script is attached to a Control node that already overrides its maximum size (e.g. ScrollContainer).
Note: It is recommended to use get_bound_minimum_size() instead of get_combined_minimum_size() when implementing this method, as the former respects maximum size limits when calculating the minimum size, while the latter does not.
Vector2 _get_minimum_size() virtual const 🔗
由使用者實作的虛方法。返回此控制項的最小大小。替代 custom_minimum_size,以用於通過程式碼控制最小尺寸。實際的最小尺寸將是這兩者的最大值(分別在每個軸上)。
如果未覆蓋,則預設為 Vector2.ZERO。
注意:當腳本被附加到已經覆蓋其最小大小的 Control 節點(例如 Label、Button、PanelContainer 等)時,該方法將不會被呼叫。它只能用於最基本的 GUI 節點,如 Control、Container、Panel 等。
String _get_tooltip(at_position: Vector2) virtual const 🔗
Virtual method to be implemented by the user. Returns the tooltip text for the position at_position in the control's local coordinates, which will typically appear when the cursor is resting over this control. See get_tooltip().
Note: If this method returns an empty String and _make_custom_tooltip() is not overridden, no tooltip is displayed.
AutoTranslateMode _get_tooltip_auto_translate_mode_at(at_position: Vector2) virtual const 🔗
Return the auto-translation mode at the given at_position. If not implemented, the tooltip_auto_translate_mode property will be used instead.
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 also accept_event().
Example: Click on the control to print a message:
func _gui_input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
print("I've been clicked D:")
public override void _GuiInput(InputEvent @event)
{
if (@event is InputEventMouseButton mb)
{
if (mb.ButtonIndex == MouseButton.Left && mb.Pressed)
{
GD.Print("I've been clicked D:");
}
}
}
If the event inherits InputEventMouse, this method will not be called when:
the control's mouse_filter is set to MOUSE_FILTER_IGNORE;
the control is obstructed by another control on top, that doesn't have mouse_filter set to MOUSE_FILTER_IGNORE;
the control's parent has mouse_filter set to MOUSE_FILTER_STOP or has accepted the event;
the control's parent has clip_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: The event's position is relative to this control's origin.
bool _has_point(point: Vector2) virtual const 🔗
Virtual method to be implemented by the user. Returns whether the given point is inside this control.
If not overridden, default behavior is checking if the point is within the control's Rect.
Note: If you want to check if a point is inside the control, you can use Rect2(Vector2.ZERO, size).has_point(point).
Object _make_custom_tooltip(for_text: String) virtual const 🔗
Virtual method to be implemented by the user. Returns a Control node that should be used as a tooltip instead of the default one. for_text is the return value of get_tooltip().
The returned node must be of type Control or Control-derived. It can have child nodes of any type. It is freed when the tooltip disappears, so make sure you always provide a new instance (if you want to use a pre-existing node from your scene tree, you can duplicate it and pass the duplicated instance). When null or a non-Control node is returned, the default tooltip will be used instead.
The returned node will be added as child to a PopupPanel, so you should only provide the contents of that panel. That PopupPanel can be themed using Theme.set_stylebox() for the type "TooltipPanel" (see tooltip_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 its custom_minimum_size to some non-zero value.
Note: The node (and any relevant children) should have their CanvasItem.visible set to true 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 if get_tooltip() returns an empty string. When this happens with the default tooltip, it is not displayed. To copy this behavior, return null in this method when for_text is empty.
Example: Use a constructed node as a tooltip:
func _make_custom_tooltip(for_text):
var label = Label.new()
label.text = for_text
return label
public override Control _MakeCustomTooltip(string forText)
{
var label = new Label();
label.Text = forText;
return label;
}
Example: Use a scene instance as a tooltip:
func _make_custom_tooltip(for_text):
var tooltip = preload("res://some_tooltip_scene.tscn").instantiate()
tooltip.get_node("Label").text = for_text
return tooltip
public override Control _MakeCustomTooltip(string forText)
{
Node tooltip = ResourceLoader.Load<PackedScene>("res://some_tooltip_scene.tscn").Instantiate();
tooltip.GetNode<Label>("Label").Text = forText;
return tooltip;
}
Array[Vector3i] _structured_text_parser(args: Array, text: String) virtual const 🔗
使用者定義的 BiDi 演算法覆蓋函式。
返回 Vector3i 文字範圍和文字基礎方向的 Array,順序為從左至右。這些範圍應該覆蓋完整的來源文字 text,不應該存在重疊。BiDi 演算法會對每個範圍單獨套用。
void accept_event() 🔗
將輸入事件標記為已處理。一旦接受輸入事件,傳播就會停止,不會再傳播到正在偵聽 Node._unhandled_input() 和 Node._unhandled_key_input() 的節點。
注意:不會影響 Input 中的方法,只會影響事件的傳播。
void accessibility_drag() 🔗
Starts drag-and-drop operation without using a mouse.
void accessibility_drop() 🔗
Ends drag-and-drop operation without using a mouse.
void add_theme_color_override(name: StringName, color: Color) 🔗
Creates a local override for a theme Color with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with remove_theme_color_override().
See also get_theme_color().
Example: Override a Label'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", new Color(1, 0.5f, 0));
// Reset the font color of the child label.
GetNode<Label>("MyLabel").RemoveThemeColorOverride("font_color");
// Alternatively it can be overridden with the default value from the Label type.
GetNode<Label>("MyLabel").AddThemeColorOverride("font_color", GetThemeColor("font_color", "Label"));
void add_theme_constant_override(name: StringName, constant: int) 🔗
為名稱為 name 的主題常數建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_constant_override() 移除。
void add_theme_font_override(name: StringName, font: Font) 🔗
為名稱為 name 的主題 Font 建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_font_override() 移除。
另見 get_theme_font()。
void add_theme_font_size_override(name: StringName, font_size: int) 🔗
為名稱為 name 的主題字形大小建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_font_size_override() 移除。
void add_theme_icon_override(name: StringName, texture: Texture2D) 🔗
為名稱為 name 的主題圖示建立本地覆蓋項。為控制項獲取主題專案時,本地覆蓋項始終優先。覆蓋項可以使用 remove_theme_icon_override() 移除。
另見 get_theme_icon()。
void add_theme_stylebox_override(name: StringName, stylebox: StyleBox) 🔗
Creates a local override for a theme StyleBox with the specified name. Local overrides always take precedence when fetching theme items for the control. An override can be removed with remove_theme_stylebox_override().
See also get_theme_stylebox().
Example: Modify 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_theme_stylebox("normal").duplicate()
new_stylebox_normal.border_width_top = 3
new_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.
StyleBoxFlat newStyleboxNormal = GetNode<Button>("MyButton").GetThemeStylebox("normal").Duplicate() as StyleBoxFlat;
newStyleboxNormal.BorderWidthTop = 3;
newStyleboxNormal.BorderColor = new Color(0, 1, 0.5f);
GetNode<Button>("MyButton").AddThemeStyleboxOverride("normal", newStyleboxNormal);
// Remove the stylebox override.
GetNode<Button>("MyButton").RemoveThemeStyleboxOverride("normal");
void begin_bulk_theme_override() 🔗
防止 *_theme_*_override 方法發出 NOTIFICATION_THEME_CHANGED,直到 end_bulk_theme_override() 被呼叫。
void end_bulk_theme_override() 🔗
結束批量主題覆蓋更新。見 begin_bulk_theme_override()。
Control find_next_valid_focus() const 🔗
找到下一個可以接受焦點的 Control,在樹的下方。
Control find_prev_valid_focus() const 🔗
找到上一個可以接受焦點的 Control,在樹的上方。
Control find_valid_focus_neighbor(side: Side) const 🔗
找出下一個可以在指定的 Side 上接收焦點的 Control。
注意:這與get_focus_neighbor() 不同,後者返回指定焦點鄰居的路徑。
void force_drag(data: Variant, preview: Control) 🔗
通過傳遞 data 和 preview 強制拖動並繞過 _get_drag_data() 和 set_drag_preview()。即使滑鼠既沒有在該控制項懸停也沒有在該控制項上按下,拖動都將開始。
方法 _can_drop_data() 和 _drop_data() 必須在想要接收拖放資料的控制項上實作。
float get_anchor(side: Side) const 🔗
返回指定 Side 的錨點。用於 anchor_bottom、anchor_left、anchor_right、和 anchor_top 的取值方法。
返回 offset_left 和 offset_top。另請參閱 position。
Vector2 get_bound_minimum_size() const 🔗
Returns the bound value of get_combined_minimum_size() by get_combined_maximum_size().
This value is the true minimum size of the container, as the maximum size has priority over the minimum size.
For example, if the combined minimum size is (100, 100) and the combined maximum size is (50, 150), the bound minimum size will be (50, 100).
Vector2 get_combined_maximum_size() const 🔗
Returns the combined maximum size from custom_maximum_size and get_maximum_size(), as well as the custom_maximum_size of this node's parent if it is a Control node with propagate_maximum_size set to true.
Vector2 get_combined_minimum_size() const 🔗
Returns the combined minimum size from custom_minimum_size and get_minimum_size().
Vector2 get_combined_pivot_offset() const 🔗
Returns the combined value of pivot_offset and pivot_offset_ratio, in pixels. The ratio is multiplied by the control's size.
CursorShape get_cursor_shape(at_position: Vector2 = Vector2(0, 0)) const 🔗
Returns the mouse cursor shape for this control when hovered over at_position in local coordinates. For most controls, this is the same as mouse_default_cursor_shape, but some built-in controls implement more complex logic.
You can override _get_cursor_shape() to implement custom behavior for this method.
返回 offset_right 和 offset_bottom。
FocusMode get_focus_mode_with_override() const 🔗
Returns the focus_mode, but takes the focus_behavior_recursive into account. If focus_behavior_recursive is set to FOCUS_BEHAVIOR_DISABLED, or it is set to FOCUS_BEHAVIOR_INHERITED and its ancestor is set to FOCUS_BEHAVIOR_DISABLED, then this returns FOCUS_NONE.
NodePath get_focus_neighbor(side: Side) const 🔗
返回指定 Side 的焦點鄰居。用於 focus_neighbor_bottom、focus_neighbor_left、focus_neighbor_right、和 focus_neighbor_top 的取值方法。
Rect2 get_global_rect() const 🔗
返回控制項相對於所屬畫布的位置和大小。參見 global_position 和 size。
注意:如果節點本身或節點與畫布之間的任何父級 CanvasItem 具有非預設旋轉或傾斜,則生成的大小可能沒有意義。
注意:將 Viewport.gui_snap_controls_to_pixels 設定為 true 會導致顯示的控制項和返回的 Rect2 之間的四捨五入不準確。
Vector2 get_maximum_size() const 🔗
Returns the maximum size for this control. See custom_maximum_size.
Vector2 get_minimum_size() const 🔗
返回該控制項的最小尺寸。見 custom_minimum_size。
MouseFilter get_mouse_filter_with_override() const 🔗
Returns the mouse_filter, but takes the mouse_behavior_recursive into account. If mouse_behavior_recursive is set to MOUSE_BEHAVIOR_DISABLED, or it is set to MOUSE_BEHAVIOR_INHERITED and its ancestor is set to MOUSE_BEHAVIOR_DISABLED, then this returns MOUSE_FILTER_IGNORE.
float get_offset(offset: Side) const 🔗
返回指定 Side 的偏移。這是 offset_bottom、offset_left、offset_right 和 offset_top 的 getter 方法。
Vector2 get_parent_area_size() const 🔗
返回父控制項中佔用的寬度/高度。
Control get_parent_control() const 🔗
返回父控制節點。
返回控制項在包含節點的坐標系中的位置和大小。參見 position、scale 和 size。
注意:如果 rotation 不是預設的旋轉,那麼得到的大小是沒有意義的。
注意:將 Viewport.gui_snap_controls_to_pixels 設定為 true,會導致顯示的控制項和返回的 Rect2 之間的四捨五入不準確。
Vector2 get_screen_position() const 🔗
Returns the position of this Control in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
Equivalent to get_screen_transform().origin (see CanvasItem.get_screen_transform()).
Example: Show a popup at the mouse position:
popup_menu.position = get_screen_position() + get_screen_transform().basis_xform(get_local_mouse_position())
# The above code is equivalent to:
popup_menu.position = get_screen_transform() * get_local_mouse_position()
popup_menu.reset_size()
popup_menu.popup()
Color get_theme_color(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回 Color,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的顏色項。如果省略 theme_type 則會使用目前控制項的類別名稱,如果定義了 theme_type_variation 則會優先使用。如果該型別為類別名稱,則還會按照繼承順序檢查父類。如果該型別為變種,則還會按照依賴順序檢查基礎型別,然後再檢查該控制項的類別名稱及其父類。
會首先考慮目前控制項的本地覆蓋項(見 add_theme_color_override()),然後才是其 theme。各個父控制項及其 theme 在目前控制項之後考慮;會跳過沒有 theme 的控制項。如果樹中沒有配對的 Theme,則會使用自訂專案 Theme(見 ProjectSettings.gui/theme/custom)和預設 Theme(見 ThemeDB)。
func _ready():
# 獲取目前 Control 類中定義的字形顏色,前提是存在。
modulate = get_theme_color("font_color")
# 獲取 Button 類中定義的字形顏色。
modulate = get_theme_color("font_color", "Button")
public override void _Ready()
{
// 獲取目前 Control 類中定義的字形顏色,前提是存在。
Modulate = GetThemeColor("font_color");
// 獲取 Button 類中定義的字形顏色。
Modulate = GetThemeColor("font_color", "Button");
}
int get_theme_constant(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回常數,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的常數項。
詳情請參閱 get_theme_color()。
float get_theme_default_base_scale() const 🔗
從樹中第一個配對的 Theme 返回預設基礎縮放值,該 Theme 中應存在有效的 Theme.default_base_scale 值。
詳情請參閱 get_theme_color()。
Font get_theme_default_font() const 🔗
從樹中第一個配對的 Theme 返回預設字形,該 Theme 中應存在有效的 Theme.default_font 值。
詳情請參閱 get_theme_color()。
int get_theme_default_font_size() const 🔗
從樹中第一個配對的 Theme 返回預設字形大小,該 Theme 中應存在有效的 Theme.default_font_size 值。
詳情請參閱 get_theme_color()。
Font get_theme_font(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回 Font,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的字形項。
詳情請參閱 get_theme_color()。
int get_theme_font_size(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回字形大小,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的字形大小項。
詳情請參閱 get_theme_color()。
Texture2D get_theme_icon(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回圖示,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的圖示項。
詳情請參閱 get_theme_color()。
StyleBox get_theme_stylebox(name: StringName, theme_type: StringName = &"") const 🔗
從樹中第一個配對的 Theme 返回 StyleBox,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的樣式盒項。
詳情請參閱 get_theme_color()。
String get_tooltip(at_position: Vector2 = Vector2(0, 0)) const 🔗
Returns the tooltip text for the position at_position in the control's local coordinates, which will typically appear when the cursor is resting over this control. By default, it returns tooltip_text.
You can override _get_tooltip() to implement custom behavior for this method.
Note: If this method returns an empty String and _make_custom_tooltip() is not overridden, no tooltip is displayed.
void grab_click_focus() 🔗
Creates an InputEventMouseButton 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.
public override void _Process(double delta)
{
GrabClickFocus(); // When clicking another Control node, this node will be clicked instead.
}
void grab_focus(hide_focus: bool = false) 🔗
Steal the focus from another control and become the focused control (see focus_mode).
If hide_focus is true, the control will not visually show its focused state. Has no effect for LineEdit and TextEdit when ProjectSettings.gui/common/show_focus_state_on_pointer_event is set to Text Input Controls, or for any control when it is set to Always.
Note: Using this method together with Callable.call_deferred() makes it more reliable, especially when called inside Node._ready().
bool has_focus(ignore_hidden_focus: bool = false) const 🔗
Returns true if this is the current focused control. See focus_mode.
If ignore_hidden_focus is true, controls that have their focus hidden will always return false. Hidden focus happens automatically when controls gain focus via mouse input, or manually using grab_focus() with hide_focus set to true.
bool has_theme_color(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的顏色項。
詳情請參閱 get_theme_color()。
bool has_theme_color_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題 Color 本地覆蓋項,則返回 true。
詳情請參閱 add_theme_color_override()。
bool has_theme_constant(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的常數項。
詳情請參閱 get_theme_color()。
bool has_theme_constant_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題常數本地覆蓋項,則返回 true。
詳情請參閱 add_theme_constant_override()。
bool has_theme_font(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的字形項。
詳情請參閱 get_theme_color()。
bool has_theme_font_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題 Font 本地覆蓋項,則返回 true。
詳情請參閱 add_theme_font_override()。
bool has_theme_font_size(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的字形大小項。
詳情請參閱 get_theme_color()。
bool has_theme_font_size_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題字形大小本地覆蓋項,則返回 true。
詳情請參閱 add_theme_font_size_override()。
bool has_theme_icon(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的圖示項。
詳情請參閱 get_theme_color()。
bool has_theme_icon_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題圖示本地覆蓋項,則返回 true。
詳情請參閱 add_theme_icon_override()。
bool has_theme_stylebox(name: StringName, theme_type: StringName = &"") const 🔗
如果樹中存在配對的 Theme 則返回 true,該 Theme 中應存在指定名稱 name 和主題型別 theme_type 的樣式盒項。
詳情請參閱 get_theme_color()。
bool has_theme_stylebox_override(name: StringName) const 🔗
如果該 Control 節點中存在名為指定 name 的主題 StyleBox 本地覆蓋項,則返回 true。
詳情請參閱 add_theme_stylebox_override()。
bool is_drag_successful() const 🔗
如果拖放操作成功則返回 true,是 Viewport.gui_is_drag_successful() 的替代方案。
建議與 Node.NOTIFICATION_DRAG_END 配合使用。
Returns true if the layout is right-to-left. See also layout_direction.
void release_focus() 🔗
放棄焦點。不會讓其他控制項能夠接收鍵盤輸入。
void remove_theme_color_override(name: StringName) 🔗
移除先前由 add_theme_color_override() 或透過屬性檢視器面板所加入,給定主題 Color 的本地覆寫,該覆寫使用指定的 name。
void remove_theme_constant_override(name: StringName) 🔗
移除針對使用指定 name 的主題常數所設定的本機覆寫,該覆寫先前透過 add_theme_constant_override() 或屬性檢視器面板新增。
void remove_theme_font_override(name: StringName) 🔗
移除先前透過 add_theme_font_override() 或透過屬性檢視器面板新增的、名稱為指定 name 的主題 Font 本地覆寫。
void remove_theme_font_size_override(name: StringName) 🔗
移除使用指定的 name,先前由 add_theme_font_size_override() 或透過屬性檢視器面板新增的主題字型大小的本地覆寫。
void remove_theme_icon_override(name: StringName) 🔗
移除先前透過 add_theme_icon_override() 或屬性檢視器面板新增的、具有指定 name 的主題圖示本地覆寫。
void remove_theme_stylebox_override(name: StringName) 🔗
移除先前由 add_theme_stylebox_override() 或透過屬性檢視器面板新增的、具有指定 name 的主題 StyleBox 本地覆寫。
void reset_size() 🔗
將大小重設為 get_combined_minimum_size()。等價於呼叫 set_size(Vector2())(或任何小於最小值的大小)。
void set_anchor(side: Side, anchor: float, keep_offset: bool = false, push_opposite_anchor: bool = true) 🔗
將指定 Side 的錨點設定為 anchor。用於 anchor_bottom、anchor_left、anchor_right、和 anchor_top 的設值函數。
如果 keep_offset 為 true,則偏移量不會在該操作後更新。
如果 push_opposite_anchor 為 true,並且相對的錨點與該錨點重疊,則相對的錨點的值將被覆蓋。例如,當將左錨點設定為 1 且右錨點的值為 0.5 時,右錨點的值也將為 1。如果 push_opposite_anchor 為 false,則左錨點的值將為 0.5。
void set_anchor_and_offset(side: Side, anchor: float, offset: float, push_opposite_anchor: bool = false) 🔗
工作原理與 set_anchor() 相同,但取代 keep_offset 參數和自動更新的偏移,它允許你自己設定偏移量(參見 set_offset())。
void set_anchors_and_offsets_preset(preset: LayoutPreset, resize_mode: LayoutPresetMode = 0, margin: int = 0) 🔗
設定錨點預設和偏移預設。參見 set_anchors_preset() 和 set_offsets_preset()。
void set_anchors_preset(preset: LayoutPreset, keep_offsets: bool = false) 🔗
將錨點設定為 LayoutPreset 列舉中的 preset。這是相當於在 2D 編輯器中使用佈局功能表的程式碼。
如果 keep_offsets 為 true,則控制項的位置也將被更新。
void set_begin(position: Vector2) 🔗
同時設定 offset_left 和 offset_top。相當於改變 position。
void set_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_funccorresponds to _get_drag_data() and requires a Vector2;can_drop_funccorresponds to _can_drop_data() and requires both a Vector2 and a Variant;drop_funccorresponds to _drop_data() and requires both a Vector2 and a Variant.
void set_drag_preview(control: Control) 🔗
在滑鼠指標處顯示給定的控制項。呼叫此方法的好時機是在 _get_drag_data() 中。控制項不得位於場景樹中。你不應釋放控制項,也不應在拖動持續時間之外保留對控制項的引用。拖拽結束後它會自動刪除。
@export var color = Color(1, 0, 0, 1)
func _get_drag_data(position):
#使用不在樹中的控制項
var cpb = ColorPickerButton.new()
cpb.color = color
cpb.size = Vector2(50, 50)
set_drag_preview(cpb)
return color
[Export]
private Color _color = new Color(1, 0, 0, 1);
public override Variant _GetDragData(Vector2 atPosition)
{
// 使用不在樹中的控制項
var cpb = new ColorPickerButton();
cpb.Color = _color;
cpb.Size = new Vector2(50, 50);
SetDragPreview(cpb);
return _color;
}
void set_end(position: Vector2) 🔗
同時設定 offset_right 和 offset_bottom。
void set_focus_neighbor(side: Side, neighbor: NodePath) 🔗
將指定 Side 的焦點鄰居設定為節點路徑 neighbor 處的 Control。這是 focus_neighbor_bottom、focus_neighbor_left、focus_neighbor_right 和 focus_neighbor_top 的 setter 方法。
void set_global_position(position: Vector2, keep_offsets: bool = false) 🔗
將 global_position 設定為給定的 position。
如果 keep_offsets 為 true,則將更新控制項的錨點而不是偏移量。
void set_offset(side: Side, offset: float) 🔗
將指定 Side 的偏移設定為 offset。用於 offset_bottom、offset_left、offset_right、和 offset_top 的設值方法。
void set_offsets_preset(preset: LayoutPreset, resize_mode: LayoutPresetMode = 0, margin: int = 0) 🔗
將偏移設定為 LayoutPreset 列舉中的 preset。這是相當於在 2D 編輯器中使用佈局功能表的程式碼。
將參數 resize_mode 與 LayoutPresetMode 中的常數一起使用,以更好地確定 Control 的最終大小。如果與更改尺寸大小的預設一起使用,則將忽略常數尺寸大小,例如 PRESET_LEFT_WIDE。
使用參數 margin 來確定 Control 和邊緣之間的間隙。
void set_position(position: Vector2, keep_offsets: bool = false) 🔗
將 position 設定為給定的 position。
如果 keep_offsets 為 true,則將更新控制項的錨點而不是偏移量。
void set_size(size: Vector2, keep_offsets: bool = false) 🔗
設定大小(參見 size)。
如果 keep_offsets 為 true,則將更新控制項的錨點而不是偏移量。
void update_maximum_size() 🔗
Invalidates the maximum size cache in this node and in parent nodes up to top level. Intended to be used with get_maximum_size() when the return value is changed. Setting custom_maximum_size directly calls this method automatically.
Note: Calling this method also calls update_minimum_size() since the combined minimum size may be affected by the maximum size change.
void update_minimum_size() 🔗
Invalidates the minimum size cache in this node and in parent nodes up to top level. Intended to be used with get_minimum_size() when the return value is changed. Setting custom_minimum_size directly calls this method automatically.
void warp_mouse(position: Vector2) 🔗
將滑鼠游標移動到 position,相對於該 Control 的 position。
注意:warp_mouse() 僅在 Windows、macOS 和 Linux 上受支援。它在 Android、iOS 和 Web 上沒有效果。