Skip to content

Commit 88280a6

Browse files
committed
Fix TabBar minimum size with clip_tabs on
1 parent c6d130a commit 88280a6

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

scene/gui/tab_bar.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Size2 TabBar::get_minimum_size() const {
4444
}
4545

4646
int y_margin = MAX(MAX(MAX(theme_cache.tab_unselected_style->get_minimum_size().height, theme_cache.tab_hovered_style->get_minimum_size().height), theme_cache.tab_selected_style->get_minimum_size().height), theme_cache.tab_disabled_style->get_minimum_size().height);
47+
int max_tab_width = 0;
4748

4849
for (int i = 0; i < tabs.size(); i++) {
4950
if (tabs[i].hidden) {
@@ -102,10 +103,14 @@ Size2 TabBar::get_minimum_size() const {
102103
if (i < tabs.size() - 1) {
103104
ms.width += theme_cache.tab_separation;
104105
}
106+
107+
if (ms.width - ofs > max_tab_width) {
108+
max_tab_width = ms.width - ofs;
109+
}
105110
}
106111

107112
if (clip_tabs) {
108-
ms.width = 0;
113+
ms.width = max_tab_width + (get_tab_count() > 1 ? theme_cache.decrement_icon->get_width() + theme_cache.increment_icon->get_width() : 0);
109114
}
110115

111116
return ms;

scene/gui/tab_container.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,17 +948,17 @@ Size2 TabContainer::get_minimum_size() const {
948948

949949
if (tabs_visible) {
950950
ms = tab_bar->get_minimum_size();
951-
ms.x += theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT);
952-
ms.y += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
951+
ms.width += theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT);
952+
ms.height += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
953953

954954
if (!get_clip_tabs()) {
955955
if (get_popup()) {
956-
ms.x += theme_cache.menu_icon->get_width();
956+
ms.width += theme_cache.menu_icon->get_width();
957957
}
958958

959959
if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
960960
(get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) {
961-
ms.x += theme_cache.side_margin;
961+
ms.width += theme_cache.side_margin;
962962
}
963963
}
964964
}
@@ -975,12 +975,12 @@ Size2 TabContainer::get_minimum_size() const {
975975
Size2 cms = c->get_combined_minimum_size();
976976
largest_child_min_size = largest_child_min_size.max(cms);
977977
}
978-
ms.y += largest_child_min_size.y;
978+
ms.height += largest_child_min_size.height;
979979

980980
Size2 panel_ms = theme_cache.panel_style->get_minimum_size();
981981

982-
ms.x = MAX(ms.x, largest_child_min_size.x + panel_ms.x);
983-
ms.y += panel_ms.y;
982+
ms.width = MAX(ms.width, largest_child_min_size.width + panel_ms.width);
983+
ms.height += panel_ms.height;
984984

985985
return ms;
986986
}

tests/scene/test_tab_bar.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,11 @@ TEST_CASE("[SceneTree][TabBar] layout and offset") {
820820
MessageQueue::get_singleton()->flush();
821821
CHECK(tab_bar->get_tab_offset() == 0);
822822

823-
// Horizontal size and minimum size get set to 0.
824-
CHECK(tab_bar->get_minimum_size().x == 0);
823+
// Horizontal size and minimum size get set to the widest tab plus arrow icons.
824+
const float offset_button_size = tab_bar->get_theme_icon("decrement_icon")->get_width() + tab_bar->get_theme_icon("increment_icon")->get_width();
825+
CHECK(tab_bar->get_minimum_size().x == offset_button_size + MAX(tab_rects[0].size.x, MAX(tab_rects[1].size.x, tab_rects[2].size.x)));
825826
CHECK(tab_bar->get_minimum_size().y == all_tabs_size.y);
826-
CHECK(tab_bar->get_size().x == 0);
827+
CHECK(tab_bar->get_size().x == offset_button_size + MAX(tab_rects[0].size.x, MAX(tab_rects[1].size.x, tab_rects[2].size.x)));
827828
CHECK(tab_bar->get_size().y == all_tabs_size.y);
828829
}
829830

0 commit comments

Comments
 (0)