diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 70fcb316565..7bc8c42592e 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -5684,12 +5684,14 @@ + Set the icon that will be displayed next to the text inside the button area. + Return the button icon. @@ -5717,23 +5719,34 @@ + Set the text alignment policy, using one of the ALIGN_* constants. + Return the text alignment policy. - 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]). + + Align the text to the left. + + + Center the text. + + + Align the text to the right. + @@ -5765,57 +5778,60 @@ Array of Buttons. - 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. - Add a new button. + Append a new button to the array, with the specified text. - + + Append a new button to the array, with the specified icon and text. - + + Define the text of the specified button. - + - + - Set the icon of an existing button. + Set the icon of the specified button. - + - Return the text of an existing button. + Return the text of the specified button. - + - + - Return the icon of an existing button. + Return the icon of the specified button. @@ -5829,42 +5845,42 @@ - Return the currently selected button in the array. + Return the index of the currently selected button in the array. - Return the currently hovered button in the array. + Return the index of the currently hovered button in the array. - + - Select a button in the array. + Select a button in the array based on the given index. - + - Remove a button in the array, by index. + Remove the specified button in the array. - Clear the button array. + Remove all buttons from the array. - + - A Button was selected (returns the index). + A button has been selected, its index is given as the argument. @@ -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. - 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. diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 0f3f762ba14..0f1622a838e 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -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") ); diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp index de77b83403d..be48296110c 100644 --- a/scene/gui/button_array.cpp +++ b/scene/gui/button_array.cpp @@ -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& p_icon,const String& p_button) { +void ButtonArray::add_icon_button(const Ref& 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& p_icon) { ERR_FAIL_INDEX(p_button,buttons.size()); @@ -403,11 +404,13 @@ void ButtonArray::set_button_icon(int p_button, const Ref& 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 ButtonArray::get_button_icon(int p_button) const { ERR_FAIL_INDEX_V(p_button,buttons.size(),Ref()); @@ -470,16 +473,16 @@ void ButtonArray::get_translatable_strings(List *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"))); }