Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix tabbar desired size not growing with maximum size up to all tabs being shown when offset is not 0

ajreckof1b1d5151211e
diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp
index 4e5004a425c..ceee73a20e2 100644
--- a/scene/gui/tab_bar.cpp
+++ b/scene/gui/tab_bar.cpp
@@ -1680,13 +1680,13 @@ Size2 TabBar::get_desired_size() const {
bool overflowed = false;
// First pass: check if all tabs fit without buttons.
- for (int i = offset; i < tabs.size(); i++) {
+ for (int i = 0; i < tabs.size(); i++) {
if (tabs[i].hidden) {
continue;
}
int next_w = w + tabs[i].size_cache;
- if (i > offset) {
+ if (i > 0) {
next_w += theme_cache.tab_separation;
}
@@ -1699,14 +1699,15 @@ Size2 TabBar::get_desired_size() const {
}
// If buttons are needed, recompute against the reduced limit.
- if (offset > 0 || overflowed) {
+ if (overflowed) {
w = 0;
+ int next_w = 0;
for (int i = offset; i < tabs.size(); i++) {
if (tabs[i].hidden) {
continue;
}
- int next_w = w + tabs[i].size_cache;
+ next_w = w + tabs[i].size_cache;
if (i > offset) {
next_w += theme_cache.tab_separation;
}
@@ -1717,9 +1718,24 @@ Size2 TabBar::get_desired_size() const {
w = next_w;
}
+
+ // If all tab after offset fit, try to add tabs before the offset as well to prevent keeping a desired size low because of offset.
+ if (next_w == w) {
+ for (int i = offset - 1; i >= 0; i--) {
+ if (tabs[i].hidden) {
+ continue;
+ }
+ next_w = w + tabs[i].size_cache + theme_cache.tab_separation;
+ if (next_w > limit_minus_buttons) {
+ break;
+ }
+
+ w = next_w;
+ }
+ }
}
- int desired = (offset > 0 || overflowed) ? w + buttons_size : w;
+ int desired = (overflowed) ? w + buttons_size : w;
desired = MIN(desired, limit);
return Size2(desired, 0);