diff --git a/doc/classes/TabBar.xml b/doc/classes/TabBar.xml index d080294c1a4..3f808f792fc 100644 --- a/doc/classes/TabBar.xml +++ b/doc/classes/TabBar.xml @@ -395,6 +395,9 @@ The size of the tab text outline. [b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended. + + The space between tabs in the tab bar. + The font used to draw tab names. diff --git a/doc/classes/TabContainer.xml b/doc/classes/TabContainer.xml index 090afa02207..8244ee0fe0b 100644 --- a/doc/classes/TabContainer.xml +++ b/doc/classes/TabContainer.xml @@ -330,6 +330,9 @@ The space at the left or right edges of the tab bar, accordingly with the current [member tab_alignment]. The margin is ignored with [constant TabBar.ALIGNMENT_RIGHT] if the tabs are clipped (see [member clip_tabs]) or a popup has been set (see [method set_popup]). The margin is always ignored with [constant TabBar.ALIGNMENT_CENTER]. + + The space between tabs in the tab bar. + The font used to draw tab names. diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 65e3d23c0bf..8f3f3f59ac2 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -430,9 +430,12 @@ void TabBar::_notification(int p_what) { int limit_minus_buttons = size.width - theme_cache.increment_icon->get_width() - theme_cache.decrement_icon->get_width(); int ofs = tabs[offset].ofs_cache; + int tab_separation_offset = 0; // Draw unselected tabs in the back. for (int i = offset; i <= max_drawn_tab; i++) { + tab_separation_offset = i * theme_cache.tab_separation; + if (tabs[i].hidden) { continue; } @@ -452,7 +455,7 @@ void TabBar::_notification(int p_what) { col = theme_cache.font_unselected_color; } - _draw_tab(sb, col, i, rtl ? size.width - ofs - tabs[i].size_cache : ofs, false); + _draw_tab(sb, col, i, rtl ? size.width - ofs - tab_separation_offset - tabs[i].size_cache : ofs + tab_separation_offset, false); } ofs += tabs[i].size_cache; @@ -460,8 +463,13 @@ void TabBar::_notification(int p_what) { // Draw selected tab in the front, but only if it's visible. if (current >= offset && current <= max_drawn_tab && !tabs[current].hidden) { + tab_separation_offset = current * theme_cache.tab_separation; + if (tab_alignment == ALIGNMENT_LEFT) { + tab_separation_offset = current == 0 ? 0 : theme_cache.tab_separation; + } + Ref sb = tabs[current].disabled ? theme_cache.tab_disabled_style : theme_cache.tab_selected_style; - float x = rtl ? size.width - tabs[current].ofs_cache - tabs[current].size_cache : tabs[current].ofs_cache; + float x = rtl ? size.width - tabs[current].ofs_cache - tab_separation_offset - tabs[current].size_cache : tabs[current].ofs_cache + tab_separation_offset; _draw_tab(sb, theme_cache.font_selected_color, current, x, has_focus()); } @@ -1053,12 +1061,17 @@ void TabBar::_update_cache(bool p_update_hover) { } w += tabs[i].size_cache; + if (i > 0) { + w += theme_cache.tab_separation; + } // Check if all tabs would fit inside the area. if (clip_tabs && i > offset && (w > limit || (offset > 0 && w > limit_minus_buttons))) { tabs.write[i].ofs_cache = 0; w -= tabs[i].size_cache; + w -= theme_cache.tab_separation; + max_drawn_tab = i - 1; while (w > limit_minus_buttons && max_drawn_tab > offset) { @@ -1066,6 +1079,7 @@ void TabBar::_update_cache(bool p_update_hover) { if (!tabs[max_drawn_tab].hidden) { w -= tabs[max_drawn_tab].size_cache; + w -= theme_cache.tab_separation; } max_drawn_tab--; @@ -1647,10 +1661,14 @@ void TabBar::ensure_tab_visible(int p_idx) { Rect2 TabBar::get_tab_rect(int p_tab) const { ERR_FAIL_INDEX_V(p_tab, tabs.size(), Rect2()); + int tab_separation_offset = p_tab * theme_cache.tab_separation; + if (tab_alignment == ALIGNMENT_LEFT) { + tab_separation_offset = p_tab == 0 ? 0 : theme_cache.tab_separation + } if (is_layout_rtl()) { - return Rect2(get_size().width - tabs[p_tab].ofs_cache - tabs[p_tab].size_cache, 0, tabs[p_tab].size_cache, get_size().height); + return Rect2(get_size().width - tabs[p_tab].ofs_cache - tab_separation_offset - tabs[p_tab].size_cache, 0, tabs[p_tab].size_cache, get_size().height); } else { - return Rect2(tabs[p_tab].ofs_cache, 0, tabs[p_tab].size_cache, get_size().height); + return Rect2(tabs[p_tab].ofs_cache + tab_separation_offset, 0, tabs[p_tab].size_cache, get_size().height); } } @@ -1847,6 +1865,7 @@ void TabBar::_bind_methods() { BIND_ENUM_CONSTANT(CLOSE_BUTTON_MAX); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabBar, h_separation); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabBar, tab_separation); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabBar, icon_max_width); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabBar, tab_unselected_style, "tab_unselected"); diff --git a/scene/gui/tab_bar.h b/scene/gui/tab_bar.h index f5ae75de51f..79b5df3ec40 100644 --- a/scene/gui/tab_bar.h +++ b/scene/gui/tab_bar.h @@ -127,6 +127,7 @@ private: struct ThemeCache { int h_separation = 0; + int tab_separation = 0; int icon_max_width = 0; Ref tab_unselected_style; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index c43d0c5d55c..cc80a158eb1 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -247,6 +247,7 @@ void TabContainer::_on_theme_changed() { tab_bar->add_theme_font_size_override(SceneStringName(font_size), theme_cache.tab_font_size); tab_bar->add_theme_constant_override(SNAME("h_separation"), theme_cache.icon_separation); + tab_bar->add_theme_constant_override(SNAME("tab_separation"), theme_cache.tab_separation); tab_bar->add_theme_constant_override(SNAME("icon_max_width"), theme_cache.icon_max_width); tab_bar->add_theme_constant_override(SNAME("outline_size"), theme_cache.outline_size); @@ -1078,6 +1079,7 @@ void TabContainer::_bind_methods() { BIND_ENUM_CONSTANT(POSITION_MAX); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, side_margin); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, tab_separation); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, panel_style, "panel"); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tabbar_style, "tabbar_background"); diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index e00bc780d47..a2d3cc4cfdf 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -71,6 +71,7 @@ private: // TabBar overrides. int icon_separation = 0; + int tab_separation = 0; int icon_max_width = 0; int outline_size = 0;