Skip to content

Button

Inherits: BaseButton < Control < CanvasItem < Entity < 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: Create a button and connect a method that will be called when the button is pressed:

public override void OnStart()
{
var button = new Button();
button.Text = "Click me";
button.Pressed += ButtonPressed;
AddChild(button);
}
private void ButtonPressed()
{
Orb.Print("Hello world!");
}

See also BaseButton which contains common properties and methods associated with this node.

Note: Buttons support multitouch via touch input, allowing multiple buttons to be pressed at the same time. Otherwise, mouse input is used, limiting interaction to one button press at a time.

Type Name Default
HorizontalAlignment alignment 1
TextSystem.AutowrapMode autowrap_mode 0
BitField[TextSystem.LineBreakFlag] autowrap_trim_flags 128
bool clip_text false
bool expand_icon false
bool flat false
Texture2D icon
HorizontalAlignment icon_alignment 0
String language ""
String text ""
Control.TextDirection text_direction 0
TextSystem.OverrunBehavior text_overrun_behavior 0
VerticalAlignment vertical_icon_alignment 1

font_color

Color font_color (color) = Color(0.875, 0.875, 0.875, 1)

font_disabled_color

Color font_disabled_color (color) = Color(0.875, 0.875, 0.875, 0.5)

font_focus_color

Color font_focus_color (color) = Color(0.95, 0.95, 0.95, 1)

font_hover_color

Color font_hover_color (color) = Color(0.95, 0.95, 0.95, 1)

font_hover_pressed_color

Color font_hover_pressed_color (color) = Color(1, 1, 1, 1)

font_outline_color

Color font_outline_color (color) = Color(0, 0, 0, 1)

font_pressed_color

Color font_pressed_color (color) = Color(1, 1, 1, 1)

icon_disabled_color

Color icon_disabled_color (color) = Color(1, 1, 1, 0.4)

icon_focus_color

Color icon_focus_color (color) = Color(1, 1, 1, 1)

icon_hover_color

Color icon_hover_color (color) = Color(1, 1, 1, 1)

icon_hover_pressed_color

Color icon_hover_pressed_color (color) = Color(1, 1, 1, 1)

icon_normal_color

Color icon_normal_color (color) = Color(1, 1, 1, 1)

icon_pressed_color

Color icon_pressed_color (color) = Color(1, 1, 1, 1)

align_to_largest_stylebox

int align_to_largest_stylebox (constant) = 0

h_separation

int h_separation (constant) = 4

icon_max_width

int icon_max_width (constant) = 0

line_spacing

int line_spacing (constant) = 0

outline_size

int outline_size (constant) = 0

font

Font font (font)

font_size

int font_size (font_size)

icon

Texture2D icon (icon)

disabled

StyleBox disabled (style)

disabled_mirrored

StyleBox disabled_mirrored (style)

focus

StyleBox focus (style)

hover

StyleBox hover (style)

hover_mirrored

StyleBox hover_mirrored (style)

hover_pressed

StyleBox hover_pressed (style)

hover_pressed_mirrored

StyleBox hover_pressed_mirrored (style)

normal

StyleBox normal (style)

normal_mirrored

StyleBox normal_mirrored (style)

pressed

StyleBox pressed (style)

pressed_mirrored

StyleBox pressed_mirrored (style)

alignment

HorizontalAlignment alignment = 1

Text alignment policy for the button’s text.

autowrap_mode

TextSystem.AutowrapMode autowrap_mode = 0

If set to something other than TextSystem.AUTOWRAP_OFF, the text gets wrapped inside the node’s bounding rectangle.

autowrap_trim_flags

BitField[TextSystem.LineBreakFlag] autowrap_trim_flags = 128

Autowrap space trimming flags. See TextSystem.BREAK_TRIM_START_EDGE_SPACES and TextSystem.BREAK_TRIM_END_EDGE_SPACES for more info.

clip_text

bool clip_text = false

If true, text that is too large to fit the button is clipped horizontally. If false, the button will always be wide enough to hold the text. The text is not vertically clipped, and the button’s height is not affected by this property.

expand_icon

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.

flat

bool flat = false

Flat buttons don’t display decoration.

icon

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.

icon_alignment

HorizontalAlignment icon_alignment = 0

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.

language

String language = ""

Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.

text

String text = ""

The button’s text that will be displayed inside the button’s area.

text_direction

Control.TextDirection text_direction = 0

Base text writing direction.

text_overrun_behavior

TextSystem.OverrunBehavior text_overrun_behavior = 0

Sets the clipping behavior when the text exceeds the node’s bounding rectangle.

vertical_icon_alignment

VerticalAlignment vertical_icon_alignment = 1

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.