Struct gdnative_bindings_lily::BaseButton [−][src]
pub struct BaseButton { /* fields omitted */ }
Expand description
core class BaseButton
inherits Control
(unsafe).
Official documentation
See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.
Class hierarchy
BaseButton inherits methods from:
Safety
All types in the Godot API have “interior mutability” in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
Constants
Determines when the button is considered clicked, one of the [enum ActionMode] constants.
ButtonGroup associated to the button.
Binary mask to choose which mouse buttons this button will respond to.
To allow both left-click and right-click, use BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT
.
Returns the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to “draw” signal. The visual state of the button is defined by the [enum DrawMode] enum.
Focus access mode to use when switching between enabled/disabled (see [member Control.focus_mode] and [member disabled]).
If true
, the button is in disabled state and can’t be clicked or toggled.
Returns true
if the mouse has entered the button and has not left it yet.
If true
, the button stays pressed when moving the cursor outside the button while pressing it.
Note: This property only affects the button’s visual appearance. Signals will be emitted at the same moment regardless of this property’s value.
If true
, the button’s state is pressed. Means the button is pressed down or toggled (if [member toggle_mode] is active).
If true
, the button will add information about its shortcut in the tooltip.
If true
, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
Determines when the button is considered clicked, one of the [enum ActionMode] constants.
ButtonGroup associated to the button.
Binary mask to choose which mouse buttons this button will respond to.
To allow both left-click and right-click, use BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT
.
If true
, the button is in disabled state and can’t be clicked or toggled.
Focus access mode to use when switching between enabled/disabled (see [member Control.focus_mode] and [member disabled]).
If true
, the button stays pressed when moving the cursor outside the button while pressing it.
Note: This property only affects the button’s visual appearance. Signals will be emitted at the same moment regardless of this property’s value.
If true
, the button’s state is pressed. Means the button is pressed down or toggled (if [member toggle_mode] is active).
ShortCut associated to the button.
If true
, the button will add information about its shortcut in the tooltip.
If true
, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked.
Methods from Deref<Target = Control>
Marks an input event as handled. Once you accept an input event, it stops propagating, even to nodes listening to [method Node._unhandled_input] or [method Node._unhandled_key_input].
Sample code is GDScript unless otherwise noted.
Overrides the Color with given name
in the [member theme] resource the control uses.
Note: Unlike other theme overrides, there is no way to undo a color override without manually assigning the previous color.
Example of overriding a label’s color and resetting it later:
# Override the child node "MyLabel"'s font color to orange.
$MyLabel.add_color_override("font_color", Color(1, 0.5, 0))
# Reset the color by creating a new node to get the default value:
var default_label_color = Label.new().get_color("font_color")
$MyLabel.add_color_override("font_color", default_label_color)
Overrides an integer constant with given name
in the [member theme] resource the control uses. If the constant
is 0
, the override is cleared and the constant from assigned Theme is used.
Overrides the font with given name
in the [member theme] resource the control uses. If font
is null
or invalid, the override is cleared and the font from assigned Theme is used.
Overrides the icon with given name
in the [member theme] resource the control uses. If icon
is null
or invalid, the override is cleared and the icon from assigned Theme is used.
pub fn add_stylebox_override(
&self,
name: impl Into<GodotString>,
stylebox: impl AsArg<StyleBox>
)
pub fn add_stylebox_override(
&self,
name: impl Into<GodotString>,
stylebox: impl AsArg<StyleBox>
)
Sample code is GDScript unless otherwise noted.
Overrides the StyleBox with given name
in the [member theme] resource the control uses. If stylebox
is empty or invalid, the override is cleared and the StyleBox from assigned Theme is used.
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 = 3
new_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)
Forces drag and bypasses [method get_drag_data] and [method set_drag_preview] by passing data
and preview
. Drag will start even if the mouse is neither over nor pressed on this control.
The methods [method can_drop_data] and [method drop_data] must be implemented on controls that want to receive drop data.
Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top margin updates when the node moves or changes size. You can use one of the [enum Anchor] constants for convenience.
Returns [member margin_left] and [member margin_top]. See also [member rect_position].
pub fn get_color(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Color
pub fn get_color(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Color
Sample code is GDScript unless otherwise noted.
Returns a color from assigned Theme with given name
and associated with Control of given type
.
func _ready():
modulate = get_color("font_color", "Button") #get the color defined for button fonts
Default Arguments
type
-""
Returns combined minimum size from [member rect_min_size] and [method get_minimum_size].
pub fn get_constant(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> i64
pub fn get_constant(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> i64
Returns a constant from assigned Theme with given name
and associated with Control of given type
.
Default Arguments
type
-""
Returns the mouse cursor shape the control displays on mouse hover. See [enum CursorShape].
Default Arguments
position
-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, 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.
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.
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.
Tells Godot which node it should give keyboard focus to if the user presses the top arrow on the keyboard or top on a gamepad by default. You can change the key by editing the ui_top
input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.
Tells Godot which node it should give keyboard focus to if the user presses Tab on a keyboard by default. You can change the key by editing the ui_focus_next
input action.
If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
Returns the control that has the keyboard focus or null
if none.
Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab on a keyboard by default. You can change the key by editing the ui_focus_prev
input action.
If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
pub fn get_font(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<Font, Shared>>
pub fn get_font(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<Font, Shared>>
Returns a font from assigned Theme with given name
and associated with Control of given type
.
Default Arguments
type
-""
The node’s global position, relative to the world (usually to the top-left corner of the window).
Returns the position and size of the control relative to the top-left corner of the screen. See [member rect_position] and [member rect_size].
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.
Tells the parent Container nodes how they should resize and place the node on the X axis. Use one of the [enum SizeFlags] constants to change the flags. See the constants to learn what each does.
pub fn get_icon(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<Texture, Shared>>
pub fn get_icon(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<Texture, Shared>>
Returns an icon from assigned Theme with given name
and associated with Control of given type
.
Default Arguments
type
-""
Distance between the node’s top edge and its parent control, based on [member anchor_top]. Margins are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Margins update automatically when you move or resize the node.
Returns the minimum size for this control. See [member rect_min_size].
Controls whether the control will be able to receive mouse button input events through [method _gui_input] and how these events should be handled. Also controls whether the control can receive the [signal mouse_entered], and [signal mouse_exited] signals. See the constants to learn what each does.
Returns the width/height occupied in the parent control.
Returns the parent control node.
By default, the node’s pivot is its top-left corner. When you change its [member rect_scale], it will scale around this pivot. Set this property to [member rect_size] / 2 to center the pivot in the node’s rectangle.
The node’s position, relative to its parent. It corresponds to the rectangle’s top-left corner. The property is not affected by [member rect_pivot_offset].
Returns the position and size of the control relative to the top-left corner of the parent Control. See [member rect_position] and [member rect_size].
Returns the rotation (in radians).
The node’s rotation around its pivot, in degrees. See [member rect_pivot_offset] to change the pivot’s position.
The node’s scale, relative to its [member rect_size]. Change this property to scale the node around its [member rect_pivot_offset]. The Control’s [member 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 [url=https://docs.godotengine.org/en/latest/tutorials/viewports/multiple_resolutions.html]documentation[/url] 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 using yield(get_tree(), "idle_frame")
then set its [member rect_scale] property.
The size of the node’s bounding rectangle, in pixels. Container nodes update this property automatically.
If the node and at least one of its neighbours uses the [constant SIZE_EXPAND] size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.
pub fn get_stylebox(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<StyleBox, Shared>>
pub fn get_stylebox(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> Option<Ref<StyleBox, Shared>>
Returns a StyleBox from assigned Theme with given name
and associated with Control of given type
.
Default Arguments
type
-""
Returns the tooltip, which will appear when the cursor is resting over this control. See [member hint_tooltip].
Default Arguments
at_position
-Vector2( 0, 0 )
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.
Tells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the [enum SizeFlags] constants to change the flags. See the constants to learn what each does.
Sample code is GDScript unless otherwise noted.
Creates an 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
Steal the focus from another control and become the focused control (see [member focus_mode]).
pub fn has_color(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
pub fn has_color(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
Returns true
if Color with given name
and associated with Control of given type
exists in assigned Theme.
Default Arguments
type
-""
pub fn has_constant(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
pub fn has_constant(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
Returns true
if constant with given name
and associated with Control of given type
exists in assigned Theme.
Default Arguments
type
-""
Returns true
if constant with given name
has a valid override in this Control node.
Returns true
if this is the current focused control. See [member focus_mode].
pub fn has_font(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
pub fn has_font(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
Returns true
if font with given name
and associated with Control of given type
exists in assigned Theme.
Default Arguments
type
-""
Returns true
if font with given name
has a valid override in this Control node.
pub fn has_icon(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
pub fn has_icon(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
Returns true
if icon with given name
and associated with Control of given type
exists in assigned Theme.
Default Arguments
type
-""
Returns true
if icon with given name
has a valid override in this Control node.
pub fn has_stylebox(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
pub fn has_stylebox(
&self,
name: impl Into<GodotString>,
node_type: impl Into<GodotString>
) -> bool
Returns true
if StyleBox with given name
and associated with Control of given type
exists in assigned Theme.
Default Arguments
type
-""
Enables whether rendering of CanvasItem based children should be clipped to this control’s rectangle. If true
, parts of a child which would be visibly outside of this control’s rectangle will not be rendered.
Invalidates the size cache in this node and in parent nodes up to toplevel. Intended to be used with [method get_minimum_size] when the return value is changed. Setting [member rect_min_size] directly calls this method automatically.
Give up the focus. No other control will be able to receive keyboard input.
Sets the anchor identified by margin
constant from [enum Margin] enum to value anchor
. A setter method for [member anchor_bottom], [member anchor_left], [member anchor_right] and [member anchor_top].
If keep_margin
is true
, margins aren’t updated after this operation.
If push_opposite_anchor
is true
and the opposite anchor overlaps this anchor, the opposite one will have its value overridden. For example, when setting left anchor to 1 and the right anchor has value of 0.5, the right anchor will also get value of 1. If push_opposite_anchor
was false
, the left anchor would get value 0.5.
Default Arguments
keep_margin
-false
push_opposite_anchor
-true
Works the same as [method set_anchor], but instead of keep_margin
argument and automatic update of margin, it allows to set the margin offset yourself (see [method set_margin]).
Default Arguments
push_opposite_anchor
-false
Sets both anchor preset and margin preset. See [method set_anchors_preset] and [method set_margins_preset].
Default Arguments
resize_mode
-0
margin
-0
Sets the anchors to a preset
from [enum Control.LayoutPreset] enum. This is code equivalent of using the Layout menu in 2D editor.
If keep_margins
is true
, control’s position will also be updated.
Default Arguments
keep_margins
-false
Sets [member margin_left] and [member margin_top] at the same time. Equivalent of changing [member rect_position].
Enables whether rendering of CanvasItem based children should be clipped to this control’s rectangle. If true
, parts of a child which would be visibly outside of this control’s rectangle will not be rendered.
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.
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.
Sample code is GDScript unless otherwise noted.
Forwards the handling of this control’s drag and drop to target
control.
Forwarding can be implemented in the target control similar to the methods [method get_drag_data], [method can_drop_data], and [method drop_data] but with two differences:
- The function name must be suffixed with _fw
- The function must take an extra argument that is the control doing the forwarding
# ThisControl.gd
extends Control
func _ready():
set_drag_forwarding(target_control)
# TargetControl.gd
extends Control
func can_drop_data_fw(position, data, from_control):
return true
func drop_data_fw(position, data, from_control):
my_handle_data(data)
func get_drag_data_fw(position, from_control):
set_drag_preview(my_preview)
return my_data()
Sample code is GDScript unless otherwise noted.
Shows the given control at the mouse pointer. A good time to call this method is in [method get_drag_data]. The control must not be in the scene tree.
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
Sets [member margin_right] and [member margin_bottom] at the same time.
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.
Tells Godot which node it should give keyboard focus to if the user presses the top arrow on the keyboard or top on a gamepad by default. You can change the key by editing the ui_top
input action. The node must be a Control. If this property is not set, Godot will give focus to the closest Control to the bottom of this one.
Tells Godot which node it should give keyboard focus to if the user presses Tab on a keyboard by default. You can change the key by editing the ui_focus_next
input action.
If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
Tells Godot which node it should give keyboard focus to if the user presses Shift+Tab on a keyboard by default. You can change the key by editing the ui_focus_prev
input action.
If this property is not set, Godot will select a “best guess” based on surrounding nodes in the scene tree.
Sets the [member rect_global_position] to given position
.
If keep_margins
is true
, control’s anchors will be updated instead of margins.
Default Arguments
keep_margins
-false
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.
Tells the parent Container nodes how they should resize and place the node on the X axis. Use one of the [enum SizeFlags] constants to change the flags. See the constants to learn what each does.
Distance between the node’s top edge and its parent control, based on [member anchor_top]. Margins are often controlled by one or multiple parent Container nodes, so you should not modify them manually if your node is a direct child of a Container. Margins update automatically when you move or resize the node.
Sets the margins to a preset
from [enum Control.LayoutPreset] enum. This is code equivalent of using the Layout menu in 2D editor.
Use parameter resize_mode
with constants from [enum Control.LayoutPresetMode] to better determine the resulting size of the Control. Constant size will be ignored if used with presets that change size, e.g. PRESET_LEFT_WIDE
.
Use parameter margin
to determine the gap between the Control and the edges.
Default Arguments
resize_mode
-0
margin
-0
Controls whether the control will be able to receive mouse button input events through [method _gui_input] and how these events should be handled. Also controls whether the control can receive the [signal mouse_entered], and [signal mouse_exited] signals. See the constants to learn what each does.
By default, the node’s pivot is its top-left corner. When you change its [member rect_scale], it will scale around this pivot. Set this property to [member rect_size] / 2 to center the pivot in the node’s rectangle.
Sets the [member rect_position] to given position
.
If keep_margins
is true
, control’s anchors will be updated instead of margins.
Default Arguments
keep_margins
-false
Sets the rotation (in radians).
The node’s rotation around its pivot, in degrees. See [member rect_pivot_offset] to change the pivot’s position.
The node’s scale, relative to its [member rect_size]. Change this property to scale the node around its [member rect_pivot_offset]. The Control’s [member 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 [url=https://docs.godotengine.org/en/latest/tutorials/viewports/multiple_resolutions.html]documentation[/url] 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 using yield(get_tree(), "idle_frame")
then set its [member rect_scale] property.
Sets the size (see [member rect_size]).
If keep_margins
is true
, control’s anchors will be updated instead of margins.
Default Arguments
keep_margins
-false
If the node and at least one of its neighbours uses the [constant SIZE_EXPAND] size flag, the parent Container will let it take more or less space depending on this property. If this node has a stretch ratio of 2 and its neighbour a ratio of 1, this node will take two thirds of the available space.
Changes the tooltip text. The tooltip appears when the user’s mouse cursor stays idle over this control for a few moments, provided that the [member mouse_filter] property is not [constant MOUSE_FILTER_IGNORE]. You can change the time required for the tooltip to appear with gui/timers/tooltip_delay_sec
option in Project Settings.
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.
Tells the parent Container nodes how they should resize and place the node on the Y axis. Use one of the [enum SizeFlags] constants to change the flags. See the constants to learn what each does.
Displays a control as modal. Control must be a subwindow. Modal controls capture the input signals until closed or the area outside them is accessed. When a modal control loses focus, or the ESC key is pressed, they automatically hide. Modal controls are used extensively for popup dialogs and menus.
If exclusive
is true
, other controls will not receive input and clicking outside this control will not close it.
Default Arguments
exclusive
-false
Moves the mouse cursor to to_position
, relative to [member rect_position] of this Control.
Trait Implementations
type RefKind = ManuallyManaged
type RefKind = ManuallyManaged
Creates an explicitly null reference of Self
as a method argument. This makes type
inference easier for the compiler compared to Option
. Read more
Creates a new instance of Self
using a zero-argument constructor, as a Unique
reference. Read more
Performs a dynamic reference downcast to target type. Read more
Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more
Creates a persistent reference to the same Godot object with shared thread access. Read more
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
Creates a persistent reference to the same Godot object with thread-local thread access. Read more
Creates a persistent reference to the same Godot object with unique access. Read more
Recovers a instance ID previously returned by Object::get_instance_id
if the object is
still alive. See also TRef::try_from_instance_id
. Read more
Auto Trait Implementations
impl RefUnwindSafe for BaseButton
impl !Send for BaseButton
impl !Sync for BaseButton
impl Unpin for BaseButton
impl UnwindSafe for BaseButton