Add more signals to `TabContainer` that `TabBar` already has

This commit is contained in:
Emmanouil Papadeas 2023-04-23 18:50:35 +03:00
parent 24cb43a874
commit 0a6a4969dc
3 changed files with 34 additions and 0 deletions

View File

@ -184,6 +184,12 @@
</member> </member>
</members> </members>
<signals> <signals>
<signal name="active_tab_rearranged">
<param index="0" name="idx_to" type="int" />
<description>
Emitted when the active tab is rearranged via mouse drag. See [member drag_to_rearrange_enabled].
</description>
</signal>
<signal name="pre_popup_pressed"> <signal name="pre_popup_pressed">
<description> <description>
Emitted when the [TabContainer]'s [Popup] button is clicked. See [method set_popup] for details. 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 switching to another tab.
</description> </description>
</signal> </signal>
<signal name="tab_clicked">
<param index="0" name="tab" type="int" />
<description>
Emitted when a tab is clicked, even if it is the current tab.
</description>
</signal>
<signal name="tab_hovered">
<param index="0" name="tab" type="int" />
<description>
Emitted when a tab is hovered by the mouse.
</description>
</signal>
<signal name="tab_selected"> <signal name="tab_selected">
<param index="0" name="tab" type="int" /> <param index="0" name="tab" type="int" />
<description> <description>

View File

@ -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)); move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index(false));
if (!is_tab_disabled(hover_now)) { if (!is_tab_disabled(hover_now)) {
emit_signal(SNAME("active_tab_rearranged"), hover_now);
set_current_tab(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) { void TabContainer::_on_tab_changed(int p_tab) {
call_deferred(SNAME("_repaint")); 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("_repaint"), &TabContainer::_repaint);
ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed); 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_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_selected", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("pre_popup_pressed")); ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
@ -992,6 +1004,8 @@ TabContainer::TabContainer() {
add_child(tab_bar, false, INTERNAL_MODE_FRONT); add_child(tab_bar, false, INTERNAL_MODE_FRONT);
tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE); 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_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_selected", callable_mp(this, &TabContainer::_on_tab_selected));
tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed)); tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed));

View File

@ -90,6 +90,8 @@ class TabContainer : public Container {
void _update_margins(); void _update_margins();
void _on_mouse_exited(); void _on_mouse_exited();
void _on_tab_changed(int p_tab); 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_selected(int p_tab);
void _on_tab_button_pressed(int p_tab); void _on_tab_button_pressed(int p_tab);