Classref: Document Button and ButtonArray
Also bind relevant constants and define some object types and better argument names for the docs.
This commit is contained in:
parent
e9a5471ee1
commit
3a4ec88b37
|
@ -5684,12 +5684,14 @@
|
||||||
<argument index="0" name="texture" type="Texture">
|
<argument index="0" name="texture" type="Texture">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Set the icon that will be displayed next to the text inside the button area.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_button_icon" qualifiers="const">
|
<method name="get_button_icon" qualifiers="const">
|
||||||
<return type="Texture">
|
<return type="Texture">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
|
Return the button icon.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="set_flat">
|
<method name="set_flat">
|
||||||
|
@ -5717,23 +5719,34 @@
|
||||||
<argument index="0" name="align" type="int">
|
<argument index="0" name="align" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Set the text alignment policy, using one of the ALIGN_* constants.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_text_align" qualifiers="const">
|
<method name="get_text_align" qualifiers="const">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
|
Return the text alignment policy.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="is_flat" qualifiers="const">
|
<method name="is_flat" qualifiers="const">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
Return the state of the [i]flat[/i] property (see [method set_flat])
|
Return the state of the [i]flat[/i] property (see [method set_flat]).
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<constants>
|
<constants>
|
||||||
|
<constant name="ALIGN_LEFT" value="0">
|
||||||
|
Align the text to the left.
|
||||||
|
</constant>
|
||||||
|
<constant name="ALIGN_CENTER" value="1">
|
||||||
|
Center the text.
|
||||||
|
</constant>
|
||||||
|
<constant name="ALIGN_RIGHT" value="2">
|
||||||
|
Align the text to the right.
|
||||||
|
</constant>
|
||||||
</constants>
|
</constants>
|
||||||
<theme_items>
|
<theme_items>
|
||||||
<theme_item name="hseparation" type="int">
|
<theme_item name="hseparation" type="int">
|
||||||
|
@ -5765,57 +5778,60 @@
|
||||||
Array of Buttons.
|
Array of Buttons.
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
Array of Buttons. A Button array is useful to have an array of buttons laid out vertically or horizontally. Only one can be selected. This is useful for joy pad based interfaces and option menus.
|
Array of Buttons. A ButtonArray is useful to have an array of buttons laid out vertically or horizontally. Only one button can be selected, and is referenced by its index in the array (first button is 0, second button is 1, etc.).
|
||||||
|
This is useful [i]e.g.[/i] for joypad-friendly interfaces and option menus.
|
||||||
</description>
|
</description>
|
||||||
<methods>
|
<methods>
|
||||||
<method name="add_button">
|
<method name="add_button">
|
||||||
<argument index="0" name="text" type="String">
|
<argument index="0" name="text" type="String">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Add a new button.
|
Append a new button to the array, with the specified text.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="add_icon_button">
|
<method name="add_icon_button">
|
||||||
<argument index="0" name="icon" type="Object">
|
<argument index="0" name="icon" type="Texture">
|
||||||
</argument>
|
</argument>
|
||||||
<argument index="1" name="text" type="String" default="""">
|
<argument index="1" name="text" type="String" default="""">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Append a new button to the array, with the specified icon and text.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="set_button_text">
|
<method name="set_button_text">
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<argument index="1" name="text" type="String">
|
<argument index="1" name="text" type="String">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
|
Define the text of the specified button.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="set_button_icon">
|
<method name="set_button_icon">
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<argument index="1" name="icon" type="Object">
|
<argument index="1" name="icon" type="Texture">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Set the icon of an existing button.
|
Set the icon of the specified button.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_button_text" qualifiers="const">
|
<method name="get_button_text" qualifiers="const">
|
||||||
<return type="String">
|
<return type="String">
|
||||||
</return>
|
</return>
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Return the text of an existing button.
|
Return the text of the specified button.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_button_icon" qualifiers="const">
|
<method name="get_button_icon" qualifiers="const">
|
||||||
<return type="Object">
|
<return type="Texture">
|
||||||
</return>
|
</return>
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Return the icon of an existing button.
|
Return the icon of the specified button.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_button_count" qualifiers="const">
|
<method name="get_button_count" qualifiers="const">
|
||||||
|
@ -5829,42 +5845,42 @@
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
Return the currently selected button in the array.
|
Return the index of the currently selected button in the array.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_hovered" qualifiers="const">
|
<method name="get_hovered" qualifiers="const">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
Return the currently hovered button in the array.
|
Return the index of the currently hovered button in the array.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="set_selected">
|
<method name="set_selected">
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Select a button in the array.
|
Select a button in the array based on the given index.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="erase_button">
|
<method name="erase_button">
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
Remove a button in the array, by index.
|
Remove the specified button in the array.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="clear">
|
<method name="clear">
|
||||||
<description>
|
<description>
|
||||||
Clear the button array.
|
Remove all buttons from the array.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
</methods>
|
</methods>
|
||||||
<signals>
|
<signals>
|
||||||
<signal name="button_selected">
|
<signal name="button_selected">
|
||||||
<argument index="0" name="button" type="int">
|
<argument index="0" name="button_idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<description>
|
||||||
A Button was selected (returns the index).
|
A button has been selected, its index is given as the argument.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
</signals>
|
</signals>
|
||||||
|
@ -43309,7 +43325,7 @@ This method controls whether the position between two cached points is interpola
|
||||||
Holds an [Object], but does not contribute to the reference count if the object is a reference.
|
Holds an [Object], but does not contribute to the reference count if the object is a reference.
|
||||||
</brief_description>
|
</brief_description>
|
||||||
<description>
|
<description>
|
||||||
A weakref can hold a [Reference], without contributing to the reference counter. A weakref can be created from an [Object] using [method @GDScript.weakref]. If this object is not a reference, weakref still works, however, it does not have any effect on the object. Weakrefs are useful in cases where multiple classes have variables that refer to eachother. Without weakrefs, using these classes could lead to memory leaks, since both references keep eachother from being released. Making part of the variables a weakref can prevent this cyclic dependency, and allows the references to be released.
|
A weakref can hold a [Reference], without contributing to the reference counter. A weakref can be created from an [Object] using [method @GDScript.weakref]. If this object is not a reference, weakref still works, however, it does not have any effect on the object. Weakrefs are useful in cases where multiple classes have variables that refer to eachother. Without weakrefs, using these classes could lead to memory leaks, since both references keep eachother from being released. Making part of the variables a weakref can prevent this cyclic dependency, and allows the references to be released.
|
||||||
</description>
|
</description>
|
||||||
<methods>
|
<methods>
|
||||||
<method name="get_ref" qualifiers="const">
|
<method name="get_ref" qualifiers="const">
|
||||||
|
|
|
@ -227,6 +227,10 @@ void Button::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("get_text_align"),&Button::get_text_align);
|
ObjectTypeDB::bind_method(_MD("get_text_align"),&Button::get_text_align);
|
||||||
ObjectTypeDB::bind_method(_MD("is_flat"),&Button::is_flat);
|
ObjectTypeDB::bind_method(_MD("is_flat"),&Button::is_flat);
|
||||||
|
|
||||||
|
BIND_CONSTANT( ALIGN_LEFT );
|
||||||
|
BIND_CONSTANT( ALIGN_CENTER );
|
||||||
|
BIND_CONSTANT( ALIGN_RIGHT );
|
||||||
|
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL ), _SCS("set_text"),_SCS("get_text") );
|
ADD_PROPERTYNZ( PropertyInfo( Variant::STRING, "text", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_DEFAULT_INTL ), _SCS("set_text"),_SCS("get_text") );
|
||||||
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture" ), _SCS("set_button_icon"),_SCS("get_button_icon") );
|
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture" ), _SCS("set_button_icon"),_SCS("get_button_icon") );
|
||||||
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flat" ), _SCS("set_flat"),_SCS("is_flat") );
|
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flat" ), _SCS("set_flat"),_SCS("is_flat") );
|
||||||
|
|
|
@ -362,10 +362,10 @@ ButtonArray::Align ButtonArray::get_align() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ButtonArray::add_button(const String& p_button) {
|
void ButtonArray::add_button(const String& p_text) {
|
||||||
|
|
||||||
Button button;
|
Button button;
|
||||||
button.text=p_button;
|
button.text=p_text;
|
||||||
buttons.push_back(button);
|
buttons.push_back(button);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
@ -375,10 +375,10 @@ void ButtonArray::add_button(const String& p_button) {
|
||||||
minimum_size_changed();
|
minimum_size_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonArray::add_icon_button(const Ref<Texture>& p_icon,const String& p_button) {
|
void ButtonArray::add_icon_button(const Ref<Texture>& p_icon,const String& p_text) {
|
||||||
|
|
||||||
Button button;
|
Button button;
|
||||||
button.text=p_button;
|
button.text=p_text;
|
||||||
button.icon=p_icon;
|
button.icon=p_icon;
|
||||||
buttons.push_back(button);
|
buttons.push_back(button);
|
||||||
if (selected==-1)
|
if (selected==-1)
|
||||||
|
@ -396,6 +396,7 @@ void ButtonArray::set_button_text(int p_button, const String& p_text) {
|
||||||
minimum_size_changed();
|
minimum_size_changed();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonArray::set_button_icon(int p_button, const Ref<Texture>& p_icon) {
|
void ButtonArray::set_button_icon(int p_button, const Ref<Texture>& p_icon) {
|
||||||
|
|
||||||
ERR_FAIL_INDEX(p_button,buttons.size());
|
ERR_FAIL_INDEX(p_button,buttons.size());
|
||||||
|
@ -403,11 +404,13 @@ void ButtonArray::set_button_icon(int p_button, const Ref<Texture>& p_icon) {
|
||||||
update();
|
update();
|
||||||
minimum_size_changed();
|
minimum_size_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
String ButtonArray::get_button_text(int p_button) const {
|
String ButtonArray::get_button_text(int p_button) const {
|
||||||
|
|
||||||
ERR_FAIL_INDEX_V(p_button,buttons.size(),"");
|
ERR_FAIL_INDEX_V(p_button,buttons.size(),"");
|
||||||
return buttons[p_button].text;
|
return buttons[p_button].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Texture> ButtonArray::get_button_icon(int p_button) const {
|
Ref<Texture> ButtonArray::get_button_icon(int p_button) const {
|
||||||
|
|
||||||
ERR_FAIL_INDEX_V(p_button,buttons.size(),Ref<Texture>());
|
ERR_FAIL_INDEX_V(p_button,buttons.size(),Ref<Texture>());
|
||||||
|
@ -470,16 +473,16 @@ void ButtonArray::get_translatable_strings(List<String> *p_strings) const {
|
||||||
void ButtonArray::_bind_methods() {
|
void ButtonArray::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("add_button","text"),&ButtonArray::add_button);
|
ObjectTypeDB::bind_method(_MD("add_button","text"),&ButtonArray::add_button);
|
||||||
ObjectTypeDB::bind_method(_MD("add_icon_button","icon","text"),&ButtonArray::add_icon_button,DEFVAL(""));
|
ObjectTypeDB::bind_method(_MD("add_icon_button","icon:Texture","text"),&ButtonArray::add_icon_button,DEFVAL(""));
|
||||||
ObjectTypeDB::bind_method(_MD("set_button_text","button","text"),&ButtonArray::set_button_text);
|
ObjectTypeDB::bind_method(_MD("set_button_text","button_idx","text"),&ButtonArray::set_button_text);
|
||||||
ObjectTypeDB::bind_method(_MD("set_button_icon","button","icon"),&ButtonArray::set_button_icon);
|
ObjectTypeDB::bind_method(_MD("set_button_icon","button_idx","icon:Texture"),&ButtonArray::set_button_icon);
|
||||||
ObjectTypeDB::bind_method(_MD("get_button_text","button"),&ButtonArray::get_button_text);
|
ObjectTypeDB::bind_method(_MD("get_button_text","button_idx"),&ButtonArray::get_button_text);
|
||||||
ObjectTypeDB::bind_method(_MD("get_button_icon","button"),&ButtonArray::get_button_icon);
|
ObjectTypeDB::bind_method(_MD("get_button_icon:Texture","button_idx"),&ButtonArray::get_button_icon);
|
||||||
ObjectTypeDB::bind_method(_MD("get_button_count"),&ButtonArray::get_button_count);
|
ObjectTypeDB::bind_method(_MD("get_button_count"),&ButtonArray::get_button_count);
|
||||||
ObjectTypeDB::bind_method(_MD("get_selected"),&ButtonArray::get_selected);
|
ObjectTypeDB::bind_method(_MD("get_selected"),&ButtonArray::get_selected);
|
||||||
ObjectTypeDB::bind_method(_MD("get_hovered"),&ButtonArray::get_hovered);
|
ObjectTypeDB::bind_method(_MD("get_hovered"),&ButtonArray::get_hovered);
|
||||||
ObjectTypeDB::bind_method(_MD("set_selected","button"),&ButtonArray::set_selected);
|
ObjectTypeDB::bind_method(_MD("set_selected","button_idx"),&ButtonArray::set_selected);
|
||||||
ObjectTypeDB::bind_method(_MD("erase_button","button"),&ButtonArray::erase_button);
|
ObjectTypeDB::bind_method(_MD("erase_button","button_idx"),&ButtonArray::erase_button);
|
||||||
ObjectTypeDB::bind_method(_MD("clear"),&ButtonArray::clear);
|
ObjectTypeDB::bind_method(_MD("clear"),&ButtonArray::clear);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("_input_event"),&ButtonArray::_input_event);
|
ObjectTypeDB::bind_method(_MD("_input_event"),&ButtonArray::_input_event);
|
||||||
|
@ -490,7 +493,7 @@ void ButtonArray::_bind_methods() {
|
||||||
BIND_CONSTANT( ALIGN_FILL );
|
BIND_CONSTANT( ALIGN_FILL );
|
||||||
BIND_CONSTANT( ALIGN_EXPAND_FILL );
|
BIND_CONSTANT( ALIGN_EXPAND_FILL );
|
||||||
|
|
||||||
ADD_SIGNAL( MethodInfo("button_selected",PropertyInfo(Variant::INT,"button")));
|
ADD_SIGNAL( MethodInfo("button_selected",PropertyInfo(Variant::INT,"button_idx")));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue