Browse Source

Add 'get_previous_tab()' to 'Tabs'

(cherry picked from commit 2b319889cb942f97a8d0f619ec881f068511ba7b)
Michael Alexsander 5 years ago
parent
commit
2d848227cf
3 changed files with 20 additions and 1 deletions
  1. 7 0
      doc/classes/Tabs.xml
  2. 11 1
      scene/gui/tabs.cpp
  3. 2 0
      scene/gui/tabs.h

+ 7 - 0
doc/classes/Tabs.xml

@@ -36,6 +36,13 @@
 				Returns [code]true[/code] if the offset buttons (the ones that appear when there's not enough space for all tabs) are visible.
 				Returns [code]true[/code] if the offset buttons (the ones that appear when there's not enough space for all tabs) are visible.
 			</description>
 			</description>
 		</method>
 		</method>
+		<method name="get_previous_tab" qualifiers="const">
+			<return type="int">
+			</return>
+			<description>
+				Returns the previously active tab index.
+			</description>
+		</method>
 		<method name="get_select_with_rmb" qualifiers="const">
 		<method name="get_select_with_rmb" qualifiers="const">
 			<return type="bool">
 			<return type="bool">
 			</return>
 			</return>

+ 11 - 1
scene/gui/tabs.cpp

@@ -408,6 +408,7 @@ void Tabs::set_current_tab(int p_current) {
 	if (current == p_current) return;
 	if (current == p_current) return;
 	ERR_FAIL_INDEX(p_current, get_tab_count());
 	ERR_FAIL_INDEX(p_current, get_tab_count());
 
 
+	previous = current;
 	current = p_current;
 	current = p_current;
 
 
 	_change_notify("current_tab");
 	_change_notify("current_tab");
@@ -422,6 +423,10 @@ int Tabs::get_current_tab() const {
 	return current;
 	return current;
 }
 }
 
 
+int Tabs::get_previous_tab() const {
+	return previous;
+}
+
 int Tabs::get_hovered_tab() const {
 int Tabs::get_hovered_tab() const {
 	return hover;
 	return hover;
 }
 }
@@ -624,6 +629,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
 void Tabs::clear_tabs() {
 void Tabs::clear_tabs() {
 	tabs.clear();
 	tabs.clear();
 	current = 0;
 	current = 0;
+	previous = 0;
 	call_deferred("_update_hover");
 	call_deferred("_update_hover");
 	update();
 	update();
 }
 }
@@ -639,8 +645,10 @@ void Tabs::remove_tab(int p_idx) {
 	update();
 	update();
 	minimum_size_changed();
 	minimum_size_changed();
 
 
-	if (current < 0)
+	if (current < 0) {
 		current = 0;
 		current = 0;
+		previous = 0;
+	}
 	if (current >= tabs.size())
 	if (current >= tabs.size())
 		current = tabs.size() - 1;
 		current = tabs.size() - 1;
 
 
@@ -960,6 +968,7 @@ void Tabs::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count);
 	ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count);
 	ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
 	ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
 	ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab);
 	ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab);
+	ClassDB::bind_method(D_METHOD("get_previous_tab"), &Tabs::get_previous_tab);
 	ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &Tabs::set_tab_title);
 	ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &Tabs::set_tab_title);
 	ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &Tabs::get_tab_title);
 	ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &Tabs::get_tab_title);
 	ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &Tabs::set_tab_icon);
 	ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &Tabs::set_tab_icon);
@@ -1014,6 +1023,7 @@ void Tabs::_bind_methods() {
 Tabs::Tabs() {
 Tabs::Tabs() {
 
 
 	current = 0;
 	current = 0;
+	previous = 0;
 	tab_align = ALIGN_CENTER;
 	tab_align = ALIGN_CENTER;
 	rb_hover = -1;
 	rb_hover = -1;
 	rb_pressing = false;
 	rb_pressing = false;

+ 2 - 0
scene/gui/tabs.h

@@ -79,6 +79,7 @@ private:
 	bool missing_right;
 	bool missing_right;
 	Vector<Tab> tabs;
 	Vector<Tab> tabs;
 	int current;
 	int current;
+	int previous;
 	int _get_top_margin() const;
 	int _get_top_margin() const;
 	TabAlign tab_align;
 	TabAlign tab_align;
 	int rb_hover;
 	int rb_hover;
@@ -140,6 +141,7 @@ public:
 	int get_tab_count() const;
 	int get_tab_count() const;
 	void set_current_tab(int p_current);
 	void set_current_tab(int p_current);
 	int get_current_tab() const;
 	int get_current_tab() const;
+	int get_previous_tab() const;
 	int get_hovered_tab() const;
 	int get_hovered_tab() const;
 
 
 	int get_tab_offset() const;
 	int get_tab_offset() const;