0.2.0-dev Download ZIP
183 lines ·11.8 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="Button" inherits="BaseButton" api_type="core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | A themed button that can contain text and an icon. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | [Button] is the standard themed button. It can contain text and an icon, and it will display them according to the current [Theme]. |
| 8 | [b]Example:[/b] Create a button and connect a method that will be called when the button is pressed: |
| 9 | [codeblocks] |
| 10 | [gdscript] |
| 11 | func _ready(): |
| 12 | var button = Button.new() |
| 13 | button.text = "Click me" |
| 14 | button.pressed.connect(_button_pressed) |
| 15 | add_child(button) |
| 16 | |
| 17 | func _button_pressed(): |
| 18 | print("Hello world!") |
| 19 | [/gdscript] |
| 20 | [csharp] |
| 21 | public override void _Ready() |
| 22 | { |
| 23 | var button = new Button(); |
| 24 | button.Text = "Click me"; |
| 25 | button.Pressed += ButtonPressed; |
| 26 | AddChild(button); |
| 27 | } |
| 28 | |
| 29 | private void ButtonPressed() |
| 30 | { |
| 31 | GD.Print("Hello world!"); |
| 32 | } |
| 33 | [/csharp] |
| 34 | [/codeblocks] |
| 35 | See also [BaseButton] which contains common properties and methods associated with this node. |
| 36 | [b]Note:[/b] 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. |
| 37 | </description> |
| 38 | <tutorials> |
| 39 | <link title="2D Dodge The Creeps Demo">https://godotengine.org/asset-library/asset/2712</link> |
| 40 | <link title="Operating System Testing Demo">https://godotengine.org/asset-library/asset/2789</link> |
| 41 | </tutorials> |
| 42 | <members> |
| 43 | <member name="alignment" type="int" setter="set_text_alignment" getter="get_text_alignment" enum="HorizontalAlignment" default="1"> |
| 44 | Text alignment policy for the button's text. |
| 45 | </member> |
| 46 | <member name="autowrap_mode" type="int" setter="set_autowrap_mode" getter="get_autowrap_mode" enum="TextServer.AutowrapMode" default="0"> |
| 47 | If set to something other than [constant TextServer.AUTOWRAP_OFF], the text gets wrapped inside the node's bounding rectangle. |
| 48 | </member> |
| 49 | <member name="autowrap_trim_flags" type="int" setter="set_autowrap_trim_flags" getter="get_autowrap_trim_flags" enum="TextServer.LineBreakFlag" is_bitfield="true" default="128"> |
| 50 | Autowrap space trimming flags. See [constant TextServer.BREAK_TRIM_START_EDGE_SPACES] and [constant TextServer.BREAK_TRIM_END_EDGE_SPACES] for more info. |
| 51 | </member> |
| 52 | <member name="clip_text" type="bool" setter="set_clip_text" getter="get_clip_text" default="false"> |
| 53 | If [code]true[/code], text that is too large to fit the button is clipped horizontally. If [code]false[/code], 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. |
| 54 | </member> |
| 55 | <member name="expand_icon" type="bool" setter="set_expand_icon" getter="is_expand_icon" default="false"> |
| 56 | When enabled, the button's icon will expand/shrink to fit the button's size while keeping its aspect. See also [theme_item icon_max_width]. |
| 57 | </member> |
| 58 | <member name="flat" type="bool" setter="set_flat" getter="is_flat" default="false"> |
| 59 | Flat buttons don't display decoration. |
| 60 | </member> |
| 61 | <member name="icon" type="Texture2D" setter="set_button_icon" getter="get_button_icon"> |
| 62 | Button's icon, if text is present the icon will be placed before the text. |
| 63 | To edit margin and spacing of the icon, use [theme_item h_separation] theme property and [code]content_margin_*[/code] properties of the used [StyleBox]es. |
| 64 | </member> |
| 65 | <member name="icon_alignment" type="int" setter="set_icon_alignment" getter="get_icon_alignment" enum="HorizontalAlignment" default="0"> |
| 66 | Specifies if the icon should be aligned horizontally to the left, right, or center of a button. Uses the same [enum HorizontalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon. |
| 67 | </member> |
| 68 | <member name="language" type="String" setter="set_language" getter="get_language" default=""""> |
| 69 | Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead. |
| 70 | </member> |
| 71 | <member name="text" type="String" setter="set_text" getter="get_text" default=""""> |
| 72 | The button's text that will be displayed inside the button's area. |
| 73 | </member> |
| 74 | <member name="text_direction" type="int" setter="set_text_direction" getter="get_text_direction" enum="Control.TextDirection" default="0"> |
| 75 | Base text writing direction. |
| 76 | </member> |
| 77 | <member name="text_overrun_behavior" type="int" setter="set_text_overrun_behavior" getter="get_text_overrun_behavior" enum="TextServer.OverrunBehavior" default="0"> |
| 78 | Sets the clipping behavior when the text exceeds the node's bounding rectangle. |
| 79 | </member> |
| 80 | <member name="vertical_icon_alignment" type="int" setter="set_vertical_icon_alignment" getter="get_vertical_icon_alignment" enum="VerticalAlignment" default="1"> |
| 81 | Specifies if the icon should be aligned vertically to the top, bottom, or center of a button. Uses the same [enum VerticalAlignment] constants as the text alignment. If centered horizontally and vertically, text will draw on top of the icon. |
| 82 | </member> |
| 83 | </members> |
| 84 | <theme_items> |
| 85 | <theme_item name="font_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 1)"> |
| 86 | Default text [Color] of the [Button]. |
| 87 | </theme_item> |
| 88 | <theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 0.5)"> |
| 89 | Text [Color] used when the [Button] is disabled. |
| 90 | </theme_item> |
| 91 | <theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)"> |
| 92 | Text [Color] used when the [Button] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color. |
| 93 | </theme_item> |
| 94 | <theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)"> |
| 95 | Text [Color] used when the [Button] is being hovered. |
| 96 | </theme_item> |
| 97 | <theme_item name="font_hover_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 98 | Text [Color] used when the [Button] is being hovered and pressed. |
| 99 | </theme_item> |
| 100 | <theme_item name="font_outline_color" data_type="color" type="Color" default="Color(0, 0, 0, 1)"> |
| 101 | The tint of text outline of the [Button]. |
| 102 | </theme_item> |
| 103 | <theme_item name="font_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 104 | Text [Color] used when the [Button] is being pressed. |
| 105 | </theme_item> |
| 106 | <theme_item name="icon_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.4)"> |
| 107 | Icon modulate [Color] used when the [Button] is disabled. |
| 108 | </theme_item> |
| 109 | <theme_item name="icon_focus_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 110 | Icon modulate [Color] used when the [Button] is focused. Only replaces the normal modulate color of the button. Disabled, hovered, and pressed states take precedence over this color. |
| 111 | </theme_item> |
| 112 | <theme_item name="icon_hover_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 113 | Icon modulate [Color] used when the [Button] is being hovered. |
| 114 | </theme_item> |
| 115 | <theme_item name="icon_hover_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 116 | Icon modulate [Color] used when the [Button] is being hovered and pressed. |
| 117 | </theme_item> |
| 118 | <theme_item name="icon_normal_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 119 | Default icon modulate [Color] of the [Button]. |
| 120 | </theme_item> |
| 121 | <theme_item name="icon_pressed_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)"> |
| 122 | Icon modulate [Color] used when the [Button] is being pressed. |
| 123 | </theme_item> |
| 124 | <theme_item name="align_to_largest_stylebox" data_type="constant" type="int" default="0"> |
| 125 | This constant acts as a boolean. If [code]true[/code], the minimum size of the button and text/icon alignment is always based on the largest stylebox margins, otherwise it's based on the current button state stylebox margins. |
| 126 | </theme_item> |
| 127 | <theme_item name="h_separation" data_type="constant" type="int" default="4"> |
| 128 | The horizontal space between [Button]'s icon and text. Negative values will be treated as [code]0[/code] when used. |
| 129 | </theme_item> |
| 130 | <theme_item name="icon_max_width" data_type="constant" type="int" default="0"> |
| 131 | The maximum allowed width of the [Button]'s icon. This limit is applied on top of the default size of the icon, or its expanded size if [member expand_icon] is [code]true[/code]. The height is adjusted according to the icon's ratio. If the button has additional icons (e.g. [CheckBox]), they will also be limited. |
| 132 | </theme_item> |
| 133 | <theme_item name="line_spacing" data_type="constant" type="int" default="0"> |
| 134 | Additional vertical spacing between lines (in pixels), spacing is added to line descent. This value can be negative. |
| 135 | </theme_item> |
| 136 | <theme_item name="outline_size" data_type="constant" type="int" default="0"> |
| 137 | The size of the text outline. |
| 138 | [b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended. |
| 139 | </theme_item> |
| 140 | <theme_item name="font" data_type="font" type="Font"> |
| 141 | [Font] of the [Button]'s text. |
| 142 | </theme_item> |
| 143 | <theme_item name="font_size" data_type="font_size" type="int"> |
| 144 | Font size of the [Button]'s text. |
| 145 | </theme_item> |
| 146 | <theme_item name="icon" data_type="icon" type="Texture2D"> |
| 147 | Default icon for the [Button]. Appears only if [member icon] is not assigned. |
| 148 | </theme_item> |
| 149 | <theme_item name="disabled" data_type="style" type="StyleBox" keywords="enabled"> |
| 150 | [StyleBox] used when the [Button] is disabled. |
| 151 | </theme_item> |
| 152 | <theme_item name="disabled_mirrored" data_type="style" type="StyleBox"> |
| 153 | [StyleBox] used when the [Button] is disabled (for right-to-left layouts). |
| 154 | </theme_item> |
| 155 | <theme_item name="focus" data_type="style" type="StyleBox"> |
| 156 | [StyleBox] used when the [Button] is focused. The [theme_item focus] [StyleBox] is displayed [i]over[/i] the base [StyleBox], so a partially transparent [StyleBox] should be used to ensure the base [StyleBox] remains visible. A [StyleBox] that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a [StyleBoxEmpty] resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons. |
| 157 | </theme_item> |
| 158 | <theme_item name="hover" data_type="style" type="StyleBox"> |
| 159 | [StyleBox] used when the [Button] is being hovered. |
| 160 | </theme_item> |
| 161 | <theme_item name="hover_mirrored" data_type="style" type="StyleBox"> |
| 162 | [StyleBox] used when the [Button] is being hovered (for right-to-left layouts). |
| 163 | </theme_item> |
| 164 | <theme_item name="hover_pressed" data_type="style" type="StyleBox"> |
| 165 | [StyleBox] used when the [Button] is being pressed and hovered at the same time. |
| 166 | </theme_item> |
| 167 | <theme_item name="hover_pressed_mirrored" data_type="style" type="StyleBox"> |
| 168 | [StyleBox] used when the [Button] is being pressed and hovered at the same time (for right-to-left layouts). |
| 169 | </theme_item> |
| 170 | <theme_item name="normal" data_type="style" type="StyleBox"> |
| 171 | Default [StyleBox] for the [Button]. |
| 172 | </theme_item> |
| 173 | <theme_item name="normal_mirrored" data_type="style" type="StyleBox"> |
| 174 | Default [StyleBox] for the [Button] (for right-to-left layouts). |
| 175 | </theme_item> |
| 176 | <theme_item name="pressed" data_type="style" type="StyleBox"> |
| 177 | [StyleBox] used when the [Button] is being pressed. |
| 178 | </theme_item> |
| 179 | <theme_item name="pressed_mirrored" data_type="style" type="StyleBox"> |
| 180 | [StyleBox] used when the [Button] is being pressed (for right-to-left layouts). |
| 181 | </theme_item> |
| 182 | </theme_items> |
| 183 | </class> |