- Added `tab_selected` signal which has same behavior as `tab_changed`

lest breaking current API, though, it is noted in the documentation of TabContainer
class, of the upcoming Godot (v3.0+) changes in behavior, that is, `tab_selected` will be
emitted for selecting any tab, while `tab_changed` only if a tab changes.
- Added `get_previous_tab()`. Which returns the previous shown tab. **Note:** In Godot v3.0+, only `tab_changed` can modify previous tab index.
- Add documentation for the added function and signals. Fix a typo too.
This commit is contained in:
Thaer Razeq 2017-03-02 17:07:07 -06:00
parent 43574f65da
commit 886f150b4a
3 changed files with 68 additions and 33 deletions

View File

@ -39867,13 +39867,21 @@
<return type="int">
</return>
<description>
Return the current tab that is being showed.
Return the current tab index that is being shown.
</description>
</method>
<method name="get_previous_tab" qualifiers="const">
<return type="int">
</return>
<description>
Return the previous tab index that was being shown.
</description>
</method>
<method name="get_current_tab_control" qualifiers="const">
<return type="Control">
</return>
<description>
Return the current tab control that is being shown.
</description>
</method>
<method name="get_popup" qualifiers="const">
@ -39976,9 +39984,16 @@
<argument index="0" name="tab" type="int">
</argument>
<description>
Emitted when the current tab changes.
Emitted when a tab gets selected. Same behavior as [tab_selected] signal for backward compatibility. Note: In Godot v3.0+ this will change to be only emitted when tab gets changed.
</description>
</signal>
<signal name="tab_selected">
<argument index="0" name="tab" type="int">
</argument>
<description>
Emitted when a tab is being selected, even if it is the same tab.
</description>
</signal>
</signals>
<constants>
</constants>

View File

@ -414,8 +414,9 @@ void TabContainer::add_child_notify(Node *p_child) {
else {
c->show();
//call_deferred("set_current_tab",0);
first=true;
current=0;
first = true;
current = 0;
previous = 0;
}
c->set_area_as_parent_rect();
if (tabs_visible)
@ -451,7 +452,8 @@ void TabContainer::set_current_tab(int p_current) {
ERR_FAIL_INDEX( p_current, get_tab_count() );
current=p_current;
int pending_previous = current;
current = p_current;
int idx=0;
@ -478,7 +480,13 @@ void TabContainer::set_current_tab(int p_current) {
}
_change_notify("current_tab");
emit_signal("tab_changed",current);
if (pending_previous != current)
previous = pending_previous;
emit_signal("tab_selected", current);
emit_signal("tab_changed", current);
update();
}
@ -487,6 +495,11 @@ int TabContainer::get_current_tab() const {
return current;
}
int TabContainer::get_previous_tab() const {
return previous;
}
Control* TabContainer::get_tab_control(int p_idx) const {
int idx=0;
@ -508,6 +521,7 @@ Control* TabContainer::get_tab_control(int p_idx) const {
return NULL;
}
Control* TabContainer::get_current_tab_control() const {
int idx=0;
@ -555,6 +569,7 @@ void TabContainer::set_tab_align(TabAlign p_align) {
_change_notify("tab_align");
}
TabContainer::TabAlign TabContainer::get_tab_align() const {
return align;
@ -711,26 +726,28 @@ Popup* TabContainer::get_popup() const {
void TabContainer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_input_event"),&TabContainer::_input_event);
ObjectTypeDB::bind_method(_MD("get_tab_count"),&TabContainer::get_tab_count);
ObjectTypeDB::bind_method(_MD("set_current_tab","tab_idx"),&TabContainer::set_current_tab);
ObjectTypeDB::bind_method(_MD("get_current_tab"),&TabContainer::get_current_tab);
ObjectTypeDB::bind_method(_MD("get_current_tab_control:Control"),&TabContainer::get_current_tab_control);
ObjectTypeDB::bind_method(_MD("get_tab_control:Control","idx"),&TabContainer::get_tab_control);
ObjectTypeDB::bind_method(_MD("set_tab_align","align"),&TabContainer::set_tab_align);
ObjectTypeDB::bind_method(_MD("get_tab_align"),&TabContainer::get_tab_align);
ObjectTypeDB::bind_method(_MD("set_tabs_visible","visible"),&TabContainer::set_tabs_visible);
ObjectTypeDB::bind_method(_MD("are_tabs_visible"),&TabContainer::are_tabs_visible);
ObjectTypeDB::bind_method(_MD("set_tab_title","tab_idx","title"),&TabContainer::set_tab_title);
ObjectTypeDB::bind_method(_MD("get_tab_title","tab_idx"),&TabContainer::get_tab_title);
ObjectTypeDB::bind_method(_MD("set_tab_icon","tab_idx","icon:Texture"),&TabContainer::set_tab_icon);
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"),&TabContainer::get_tab_icon);
ObjectTypeDB::bind_method(_MD("set_popup","popup:Popup"),&TabContainer::set_popup);
ObjectTypeDB::bind_method(_MD("get_popup:Popup"),&TabContainer::get_popup);
ObjectTypeDB::bind_method(_MD("_input_event"), &TabContainer::_input_event);
ObjectTypeDB::bind_method(_MD("get_tab_count"), &TabContainer::get_tab_count);
ObjectTypeDB::bind_method(_MD("set_current_tab","tab_idx"), &TabContainer::set_current_tab);
ObjectTypeDB::bind_method(_MD("get_current_tab"), &TabContainer::get_current_tab);
ObjectTypeDB::bind_method(_MD("get_previous_tab"), &TabContainer::get_previous_tab);
ObjectTypeDB::bind_method(_MD("get_current_tab_control:Control"), &TabContainer::get_current_tab_control);
ObjectTypeDB::bind_method(_MD("get_tab_control:Control","idx"), &TabContainer::get_tab_control);
ObjectTypeDB::bind_method(_MD("set_tab_align","align"), &TabContainer::set_tab_align);
ObjectTypeDB::bind_method(_MD("get_tab_align"), &TabContainer::get_tab_align);
ObjectTypeDB::bind_method(_MD("set_tabs_visible","visible"), &TabContainer::set_tabs_visible);
ObjectTypeDB::bind_method(_MD("are_tabs_visible"), &TabContainer::are_tabs_visible);
ObjectTypeDB::bind_method(_MD("set_tab_title","tab_idx","title"), &TabContainer::set_tab_title);
ObjectTypeDB::bind_method(_MD("get_tab_title","tab_idx"), &TabContainer::get_tab_title);
ObjectTypeDB::bind_method(_MD("set_tab_icon","tab_idx","icon:Texture"), &TabContainer::set_tab_icon);
ObjectTypeDB::bind_method(_MD("get_tab_icon:Texture","tab_idx"), &TabContainer::get_tab_icon);
ObjectTypeDB::bind_method(_MD("set_popup","popup:Popup"), &TabContainer::set_popup);
ObjectTypeDB::bind_method(_MD("get_popup:Popup"), &TabContainer::get_popup);
ObjectTypeDB::bind_method(_MD("_child_renamed_callback"),&TabContainer::_child_renamed_callback);
ObjectTypeDB::bind_method(_MD("_child_renamed_callback"), &TabContainer::_child_renamed_callback);
ADD_SIGNAL(MethodInfo("tab_changed",PropertyInfo(Variant::INT,"tab")));
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
ADD_PROPERTY( PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM,"Left,Center,Right"), _SCS("set_tab_align"), _SCS("get_tab_align") );
@ -741,13 +758,14 @@ void TabContainer::_bind_methods() {
TabContainer::TabContainer() {
tab_display_ofs=0;
buttons_visible_cache=false;
tabs_ofs_cache=0;
current=0;
mouse_x_cache=0;
align=ALIGN_CENTER;
tabs_visible=true;
popup=NULL;
tab_display_ofs = 0;
buttons_visible_cache = false;
tabs_ofs_cache = 0;
current = 0;
previous = 0;
mouse_x_cache = 0;
align = ALIGN_CENTER;
tabs_visible = true;
popup = NULL;
}

View File

@ -50,6 +50,7 @@ private:
int tabs_ofs_cache;
int last_tab_cache;
int current;
int previous;
bool tabs_visible;
bool buttons_visible_cache;
TabAlign align;
@ -86,6 +87,7 @@ public:
int get_tab_count() const;
void set_current_tab(int p_current);
int get_current_tab() const;
int get_previous_tab() const;
Control* get_tab_control(int p_idx) const;
Control* get_current_tab_control() const;