From 408a08f2c1f0c5701f7083fcbdfdf58375d09c05 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Thu, 3 Aug 2023 20:53:49 +0200 Subject: [PATCH] Expose the `TabBar` of a `TabContainer` Add `TabContainer::get_tab_bar` method to retrieve the `TabBar` of a `TabContainer`. --- doc/classes/TabContainer.xml | 7 +++++++ scene/gui/tab_container.cpp | 5 +++++ scene/gui/tab_container.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml index 940eb89dab8a..013ab3bd7788 100644 --- a/doc/classes/TabContainer.xml +++ b/doc/classes/TabContainer.xml @@ -30,6 +30,13 @@ Returns the previously active tab index. + + + + Returns the [TabBar] contained in this container. + [b]Warning:[/b] This is a required internal node, removing and freeing it or editing its tabs may cause a crash. If you wish to edit the tabs, use the methods provided in [TabContainer]. + + diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index a6be8f29488d..846613e47f20 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -620,6 +620,10 @@ void TabContainer::remove_child_notify(Node *p_child) { } } +TabBar *TabContainer::get_tab_bar() const { + return tab_bar; +} + int TabContainer::get_tab_count() const { return tab_bar->get_tab_count(); } @@ -947,6 +951,7 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab); ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab); ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control); + ClassDB::bind_method(D_METHOD("get_tab_bar"), &TabContainer::get_tab_bar); ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control); ClassDB::bind_method(D_METHOD("set_tab_alignment", "alignment"), &TabContainer::set_tab_alignment); ClassDB::bind_method(D_METHOD("get_tab_alignment"), &TabContainer::get_tab_alignment); diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 711b57e42117..4dbf832f67a7 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -111,6 +111,8 @@ class TabContainer : public Container { static void _bind_methods(); public: + TabBar *get_tab_bar() const; + int get_tab_idx_at_point(const Point2 &p_point) const; int get_tab_idx_from_control(Control *p_child) const;