File tree Expand file tree Collapse file tree 7 files changed +1557
-6
lines changed
Expand file tree Collapse file tree 7 files changed +1557
-6
lines changed Original file line number Diff line number Diff line change @@ -354,6 +354,8 @@ void TabBar::_notification(int p_what) {
354354 if (scroll_to_selected) {
355355 ensure_tab_visible (current);
356356 }
357+ // Set initialized even if no tabs were set.
358+ initialized = true ;
357359 } break ;
358360
359361 case NOTIFICATION_INTERNAL_PROCESS: {
@@ -655,10 +657,10 @@ void TabBar::set_tab_count(int p_count) {
655657 }
656658
657659 if (!initialized) {
658- if (queued_current != current) {
659- current = queued_current;
660- }
661660 initialized = true ;
661+ if (queued_current != CURRENT_TAB_UNINITIALIZED && queued_current != current) {
662+ set_current_tab (queued_current);
663+ }
662664 }
663665
664666 queue_redraw ();
@@ -740,6 +742,13 @@ bool TabBar::select_next_available() {
740742 return false ;
741743}
742744
745+ void TabBar::set_tab_offset (int p_offset) {
746+ ERR_FAIL_INDEX (p_offset, tabs.size ());
747+ offset = p_offset;
748+ _update_cache ();
749+ queue_redraw ();
750+ }
751+
743752int TabBar::get_tab_offset () const {
744753 return offset;
745754}
Original file line number Diff line number Diff line change @@ -117,8 +117,9 @@ class TabBar : public Control {
117117 bool scroll_to_selected = true ;
118118 int tabs_rearrange_group = -1 ;
119119
120+ static const int CURRENT_TAB_UNINITIALIZED = -2 ;
120121 bool initialized = false ;
121- int queued_current = - 1 ;
122+ int queued_current = CURRENT_TAB_UNINITIALIZED ;
122123
123124 const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5 ;
124125 const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20 ;
@@ -249,6 +250,7 @@ class TabBar : public Control {
249250 bool select_previous_available ();
250251 bool select_next_available ();
251252
253+ void set_tab_offset (int p_offset);
252254 int get_tab_offset () const ;
253255 bool get_offset_buttons_visible () const ;
254256
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ void TabContainer::_notification(int p_what) {
190190 } break ;
191191
192192 case NOTIFICATION_VISIBILITY_CHANGED: {
193- if (!is_visible () || setup_current_tab > - 2 ) {
193+ if (!is_visible ()) {
194194 return ;
195195 }
196196
@@ -200,7 +200,7 @@ void TabContainer::_notification(int p_what) {
200200 // beat it to the punch and make sure that the correct node is the only one visible first.
201201 // Otherwise, it can prevent a tab change done right before this container was made visible.
202202 Vector<Control *> controls = _get_tab_controls ();
203- int current = get_current_tab ();
203+ int current = setup_current_tab > - 2 ? setup_current_tab : get_current_tab ();
204204 for (int i = 0 ; i < controls.size (); i++) {
205205 controls[i]->set_visible (i == current);
206206 }
You can’t perform that action at this time.
0 commit comments