Skip to content

Commit ef3a6e0

Browse files
committed
Merge pull request godotengine#82384 from YeldhamDev/corner_cases_man_i_swear
Make hovered tabs be drawn with the unselected's width at minimum
2 parents 1c436a0 + 685fa66 commit ef3a6e0

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

doc/classes/TabBar.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
</theme_item>
415415
<theme_item name="tab_hovered" data_type="style" type="StyleBox">
416416
The style of the currently hovered tab. Does not apply to the selected tab.
417+
[b]Note:[/b] This style will be drawn with the same width as [theme_item tab_unselected] at minimum.
417418
</theme_item>
418419
<theme_item name="tab_selected" data_type="style" type="StyleBox">
419420
The style of the currently selected tab.

doc/classes/TabContainer.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@
318318
</theme_item>
319319
<theme_item name="tab_hovered" data_type="style" type="StyleBox">
320320
The style of the currently hovered tab.
321+
[b]Note:[/b] This style will be drawn with the same width as [theme_item tab_unselected] at minimum.
321322
</theme_item>
322323
<theme_item name="tab_selected" data_type="style" type="StyleBox">
323324
The style of the currently selected tab.

scene/gui/tab_bar.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ void TabBar::_update_hover() {
948948
}
949949
}
950950

951-
void TabBar::_update_cache() {
951+
void TabBar::_update_cache(bool p_update_hover) {
952952
if (tabs.is_empty()) {
953953
buttons_visible = false;
954954
return;
@@ -1011,7 +1011,9 @@ void TabBar::_update_cache() {
10111011
buttons_visible = offset > 0 || missing_right;
10121012

10131013
if (tab_alignment == ALIGNMENT_LEFT) {
1014-
_update_hover();
1014+
if (p_update_hover) {
1015+
_update_hover();
1016+
}
10151017
return;
10161018
}
10171019

@@ -1029,7 +1031,9 @@ void TabBar::_update_cache() {
10291031
}
10301032
}
10311033

1032-
_update_hover();
1034+
if (p_update_hover) {
1035+
_update_hover();
1036+
}
10331037
}
10341038

10351039
void TabBar::_on_mouse_exited() {
@@ -1039,7 +1043,7 @@ void TabBar::_on_mouse_exited() {
10391043
highlight_arrow = -1;
10401044
dragging_valid_tab = false;
10411045

1042-
_update_cache();
1046+
_update_cache(false);
10431047
queue_redraw();
10441048
}
10451049

@@ -1373,7 +1377,8 @@ int TabBar::get_tab_width(int p_idx) const {
13731377
style = theme_cache.tab_disabled_style;
13741378
} else if (current == p_idx) {
13751379
style = theme_cache.tab_selected_style;
1376-
} else if (hover == p_idx) {
1380+
// Use the unselected style's width if the hovered one is shorter, to avoid an infinite loop when switching tabs with the mouse.
1381+
} else if (hover == p_idx && theme_cache.tab_hovered_style->get_minimum_size().width >= theme_cache.tab_unselected_style->get_minimum_size().width) {
13771382
style = theme_cache.tab_hovered_style;
13781383
} else {
13791384
style = theme_cache.tab_unselected_style;

scene/gui/tab_bar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class TabBar : public Control {
148148
void _ensure_no_over_offset();
149149

150150
void _update_hover();
151-
void _update_cache();
151+
void _update_cache(bool p_update_hover = true);
152152

153153
void _on_mouse_exited();
154154

0 commit comments

Comments
 (0)