From 0a6a4969dc6d02c18764245839abe1d8ff889405 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Sun, 23 Apr 2023 18:50:35 +0300 Subject: [PATCH] Add more signals to `TabContainer` that `TabBar` already has --- doc/classes/TabContainer.xml | 18 ++++++++++++++++++ scene/gui/tab_container.cpp | 14 ++++++++++++++ scene/gui/tab_container.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml index dbc769cfe90..f8603908f39 100644 --- a/doc/classes/TabContainer.xml +++ b/doc/classes/TabContainer.xml @@ -184,6 +184,12 @@ + + + + Emitted when the active tab is rearranged via mouse drag. See [member drag_to_rearrange_enabled]. + + Emitted when the [TabContainer]'s [Popup] button is clicked. See [method set_popup] for details. @@ -201,6 +207,18 @@ Emitted when switching to another tab. + + + + Emitted when a tab is clicked, even if it is the current tab. + + + + + + Emitted when a tab is hovered by the mouse. + + diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 0db2b905de2..b3f716267b1 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -453,6 +453,7 @@ void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, C move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index(false)); if (!is_tab_disabled(hover_now)) { + emit_signal(SNAME("active_tab_rearranged"), hover_now); set_current_tab(hover_now); } @@ -497,6 +498,14 @@ void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, C } } +void TabContainer::_on_tab_clicked(int p_tab) { + emit_signal(SNAME("tab_clicked"), p_tab); +} + +void TabContainer::_on_tab_hovered(int p_tab) { + emit_signal(SNAME("tab_hovered"), p_tab); +} + void TabContainer::_on_tab_changed(int p_tab) { call_deferred(SNAME("_repaint")); @@ -971,7 +980,10 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("_repaint"), &TabContainer::_repaint); ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed); + ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to"))); ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); + ADD_SIGNAL(MethodInfo("tab_clicked", PropertyInfo(Variant::INT, "tab"))); + ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("pre_popup_pressed")); @@ -992,6 +1004,8 @@ TabContainer::TabContainer() { add_child(tab_bar, false, INTERNAL_MODE_FRONT); tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE); tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed)); + tab_bar->connect("tab_clicked", callable_mp(this, &TabContainer::_on_tab_clicked)); + tab_bar->connect("tab_hovered", callable_mp(this, &TabContainer::_on_tab_hovered)); tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected)); tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed)); diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index e2a77bf477c..ca391cff9b7 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -90,6 +90,8 @@ class TabContainer : public Container { void _update_margins(); void _on_mouse_exited(); void _on_tab_changed(int p_tab); + void _on_tab_clicked(int p_tab); + void _on_tab_hovered(int p_tab); void _on_tab_selected(int p_tab); void _on_tab_button_pressed(int p_tab);