@@ -500,6 +500,13 @@ void TabContainer::_on_tab_visibility_changed(Control *p_child) {
500
500
updating_visibility = false ;
501
501
}
502
502
503
+ void TabContainer::_refresh_tab_indices () {
504
+ Vector<Control *> controls = _get_tab_controls ();
505
+ for (int i = 0 ; i < controls.size (); i++) {
506
+ controls[i]->set_meta (" _tab_index" , i);
507
+ }
508
+ }
509
+
503
510
void TabContainer::_refresh_tab_names () {
504
511
Vector<Control *> controls = _get_tab_controls ();
505
512
for (int i = 0 ; i < controls.size (); i++) {
@@ -523,6 +530,7 @@ void TabContainer::add_child_notify(Node *p_child) {
523
530
c->hide ();
524
531
525
532
tab_bar->add_tab (p_child->get_name ());
533
+ c->set_meta (" _tab_index" , tab_bar->get_tab_count () - 1 );
526
534
527
535
_update_margins ();
528
536
if (get_tab_count () == 1 ) {
@@ -547,19 +555,10 @@ void TabContainer::move_child_notify(Node *p_child) {
547
555
548
556
Control *c = Object::cast_to<Control>(p_child);
549
557
if (c && !c->is_set_as_top_level ()) {
550
- int old_idx = -1 ;
551
- String tab_name = String (c->get_meta (" _tab_name" , c->get_name ()));
552
-
553
- // Find the previous tab index of the control.
554
- for (int i = 0 ; i < get_tab_count (); i++) {
555
- if (get_tab_title (i) == tab_name) {
556
- old_idx = i;
557
- break ;
558
- }
559
- }
560
-
561
- tab_bar->move_tab (old_idx, get_tab_idx_from_control (c));
558
+ tab_bar->move_tab (c->get_meta (" _tab_index" ), get_tab_idx_from_control (c));
562
559
}
560
+
561
+ _refresh_tab_indices ();
563
562
}
564
563
565
564
void TabContainer::remove_child_notify (Node *p_child) {
@@ -578,14 +577,18 @@ void TabContainer::remove_child_notify(Node *p_child) {
578
577
579
578
// As the child hasn't been removed yet, keep track of it so when the "tab_changed" signal is fired it can be ignored.
580
579
children_removing.push_back (c);
580
+
581
581
tab_bar->remove_tab (idx);
582
+ _refresh_tab_indices ();
583
+
582
584
children_removing.erase (c);
583
585
584
586
_update_margins ();
585
587
if (get_tab_count () == 0 ) {
586
588
queue_redraw ();
587
589
}
588
590
591
+ p_child->remove_meta (" _tab_index" );
589
592
p_child->remove_meta (" _tab_name" );
590
593
p_child->disconnect (" renamed" , callable_mp (this , &TabContainer::_refresh_tab_names));
591
594
p_child->disconnect (SNAME (" visibility_changed" ), callable_mp (this , &TabContainer::_on_tab_visibility_changed));
0 commit comments