Class Button
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Button is the standard themed button. It can contain text and an icon, and it will display them according to the current Theme.
Example of creating a button and assigning an action when pressed by code:
public override void _Ready()
{
var button = new Button();
button.Text = "Click me";
button.Pressed += ButtonPressed;
AddChild(button);
}
private void ButtonPressed()
{
GD.Print("Hello world!");
}
See also BaseButton which contains common properties and methods associated with this node.
Note: Buttons do not interpret touch input and therefore don't support multitouch, since mouse emulation can only press one button at a given time. Use TouchScreenButton for buttons that trigger gameplay movement or actions.
public class Button : BaseButton, IDisposable
- Inheritance
-
Button
- Implements
- Derived
- Inherited Members
Constructors
Button()
public Button()
Properties
Alignment
Text alignment policy for the button's text, use one of the HorizontalAlignment constants.
public HorizontalAlignment Alignment { get; set; }
Property Value
ClipText
When this property is enabled, text that is too large to fit the button is clipped, when disabled the Button will always be wide enough to hold the text.
public bool ClipText { get; set; }
Property Value
ExpandIcon
When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect. See also icon_max_width
.
public bool ExpandIcon { get; set; }
Property Value
Flat
Flat buttons don't display decoration.
public bool Flat { get; set; }
Property Value
Icon
Button's icon, if text is present the icon will be placed before the text.
To edit margin and spacing of the icon, use h_separation
theme property and content_margin_*
properties of the used StyleBoxes.
public Texture2D Icon { get; set; }
Property Value
IconAlignment
Specifies if the icon should be aligned horizontally to the left, right, or center of a button. Uses the same HorizontalAlignment constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.
public HorizontalAlignment IconAlignment { get; set; }
Property Value
Language
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
public string Language { get; set; }
Property Value
Text
The button's text that will be displayed inside the button's area.
public string Text { get; set; }
Property Value
TextDirection
Base text writing direction.
public Control.TextDirection TextDirection { get; set; }
Property Value
TextOverrunBehavior
Sets the clipping behavior when the text exceeds the node's bounding rectangle. See TextServer.OverrunBehavior for a description of all modes.
public TextServer.OverrunBehavior TextOverrunBehavior { get; set; }
Property Value
VerticalIconAlignment
Specifies if the icon should be aligned vertically to the top, bottom, or center of a button. Uses the same VerticalAlignment constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon.
public VerticalAlignment VerticalIconAlignment { get; set; }
Property Value
Methods
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.