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:
Rémi Verschelde 2016-04-27 23:58:24 +02:00
parent e9a5471ee1
commit 3a4ec88b37
3 changed files with 58 additions and 35 deletions

View File

@ -5684,12 +5684,14 @@
<argument index="0" name="texture" type="Texture">
</argument>
<description>
Set the icon that will be displayed next to the text inside the button area.
</description>
</method>
<method name="get_button_icon" qualifiers="const">
<return type="Texture">
</return>
<description>
Return the button icon.
</description>
</method>
<method name="set_flat">
@ -5717,23 +5719,34 @@
<argument index="0" name="align" type="int">
</argument>
<description>
Set the text alignment policy, using one of the ALIGN_* constants.
</description>
</method>
<method name="get_text_align" qualifiers="const">
<return type="int">
</return>
<description>
Return the text alignment policy.
</description>
</method>
<method name="is_flat" qualifiers="const">
<return type="bool">
</return>
<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>
</method>
</methods>
<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>
<theme_items>
<theme_item name="hseparation" type="int">
@ -5765,57 +5778,60 @@
Array of Buttons.
</brief_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>
<methods>
<method name="add_button">
<argument index="0" name="text" type="String">
</argument>
<description>
Add a new button.
Append a new button to the array, with the specified text.
</description>
</method>
<method name="add_icon_button">
<argument index="0" name="icon" type="Object">
<argument index="0" name="icon" type="Texture">
</argument>
<argument index="1" name="text" type="String" default="&quot;&quot;">
</argument>
<description>
Append a new button to the array, with the specified icon and text.
</description>
</method>
<method name="set_button_text">
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<argument index="1" name="text" type="String">
</argument>
<description>
Define the text of the specified button.
</description>
</method>
<method name="set_button_icon">
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<argument index="1" name="icon" type="Object">
<argument index="1" name="icon" type="Texture">
</argument>
<description>
Set the icon of an existing button.
Set the icon of the specified button.
</description>
</method>
<method name="get_button_text" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<description>
Return the text of an existing button.
Return the text of the specified button.
</description>
</method>
<method name="get_button_icon" qualifiers="const">
<return type="Object">
<return type="Texture">
</return>
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<description>
Return the icon of an existing button.
Return the icon of the specified button.
</description>
</method>
<method name="get_button_count" qualifiers="const">
@ -5829,42 +5845,42 @@
<return type="int">
</return>
<description>
Return the currently selected button in the array.
Return the index of the currently selected button in the array.
</description>
</method>
<method name="get_hovered" qualifiers="const">
<return type="int">
</return>
<description>
Return the currently hovered button in the array.
Return the index of the currently hovered button in the array.
</description>
</method>
<method name="set_selected">
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<description>
Select a button in the array.
Select a button in the array based on the given index.
</description>
</method>
<method name="erase_button">
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<description>
Remove a button in the array, by index.
Remove the specified button in the array.
</description>
</method>
<method name="clear">
<description>
Clear the button array.
Remove all buttons from the array.
</description>
</method>
</methods>
<signals>
<signal name="button_selected">
<argument index="0" name="button" type="int">
<argument index="0" name="button_idx" type="int">
</argument>
<description>
A Button was selected (returns the index).
A button has been selected, its index is given as the argument.
</description>
</signal>
</signals>

View File

@ -227,6 +227,10 @@ void Button::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_text_align"),&Button::get_text_align);
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::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") );

View File

@ -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.text=p_button;
button.text=p_text;
buttons.push_back(button);
update();
@ -375,10 +375,10 @@ void ButtonArray::add_button(const String& p_button) {
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.text=p_button;
button.text=p_text;
button.icon=p_icon;
buttons.push_back(button);
if (selected==-1)
@ -396,6 +396,7 @@ void ButtonArray::set_button_text(int p_button, const String& p_text) {
minimum_size_changed();
}
void ButtonArray::set_button_icon(int p_button, const Ref<Texture>& p_icon) {
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();
minimum_size_changed();
}
String ButtonArray::get_button_text(int p_button) const {
ERR_FAIL_INDEX_V(p_button,buttons.size(),"");
return buttons[p_button].text;
}
Ref<Texture> ButtonArray::get_button_icon(int p_button) const {
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() {
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("set_button_text","button","text"),&ButtonArray::set_button_text);
ObjectTypeDB::bind_method(_MD("set_button_icon","button","icon"),&ButtonArray::set_button_icon);
ObjectTypeDB::bind_method(_MD("get_button_text","button"),&ButtonArray::get_button_text);
ObjectTypeDB::bind_method(_MD("get_button_icon","button"),&ButtonArray::get_button_icon);
ObjectTypeDB::bind_method(_MD("add_icon_button","icon:Texture","text"),&ButtonArray::add_icon_button,DEFVAL(""));
ObjectTypeDB::bind_method(_MD("set_button_text","button_idx","text"),&ButtonArray::set_button_text);
ObjectTypeDB::bind_method(_MD("set_button_icon","button_idx","icon:Texture"),&ButtonArray::set_button_icon);
ObjectTypeDB::bind_method(_MD("get_button_text","button_idx"),&ButtonArray::get_button_text);
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_selected"),&ButtonArray::get_selected);
ObjectTypeDB::bind_method(_MD("get_hovered"),&ButtonArray::get_hovered);
ObjectTypeDB::bind_method(_MD("set_selected","button"),&ButtonArray::set_selected);
ObjectTypeDB::bind_method(_MD("erase_button","button"),&ButtonArray::erase_button);
ObjectTypeDB::bind_method(_MD("set_selected","button_idx"),&ButtonArray::set_selected);
ObjectTypeDB::bind_method(_MD("erase_button","button_idx"),&ButtonArray::erase_button);
ObjectTypeDB::bind_method(_MD("clear"),&ButtonArray::clear);
ObjectTypeDB::bind_method(_MD("_input_event"),&ButtonArray::_input_event);
@ -490,7 +493,7 @@ void ButtonArray::_bind_methods() {
BIND_CONSTANT( ALIGN_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")));
}