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...
Button¶
Inherits: BaseButton < Control < CanvasItem < Node < Object
Inherited By: CheckBox, CheckButton, ColorPickerButton, MenuButton, OptionButton
A themed button that can contain text and an icon.
描述¶
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:
func _ready():
var button = Button.new()
button.text = "Click me"
button.pressed.connect(self._button_pressed)
add_child(button)
func _button_pressed():
print("Hello world!")
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.
教程¶
属性¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Theme Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Property Descriptions¶
HorizontalAlignment alignment = 1
void set_text_alignment ( HorizontalAlignment value )
HorizontalAlignment get_text_alignment ( )
Text alignment policy for the button's text, use one of the HorizontalAlignment constants.
bool clip_text = false
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.
bool expand_icon = false
When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect. See also icon_max_width.
bool flat = false
Flat buttons don't display decoration.
Texture2D 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.
HorizontalAlignment icon_alignment = 0
void set_icon_alignment ( HorizontalAlignment value )
HorizontalAlignment get_icon_alignment ( )
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.
String language = ""
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
String text = ""
The button's text that will be displayed inside the button's area.
TextDirection text_direction = 0
void set_text_direction ( TextDirection value )
TextDirection get_text_direction ( )
Base text writing direction.
OverrunBehavior text_overrun_behavior = 0