mirror of https://github.com/godotengine/godot
Add tab spacing modifier for tabs in TabBar and TabContainer
This commit is contained in:
parent
394508d26d
commit
b860ab6580
|
|
@ -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.
|
||||
</theme_item>
|
||||
<theme_item name="tab_separation" data_type="constant" type="int" default="0">
|
||||
The space between tabs in the tab bar.
|
||||
</theme_item>
|
||||
<theme_item name="font" data_type="font" type="Font">
|
||||
The font used to draw tab names.
|
||||
</theme_item>
|
||||
|
|
|
|||
|
|
@ -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].
|
||||
</theme_item>
|
||||
<theme_item name="tab_separation" data_type="constant" type="int" default="0">
|
||||
The space between tabs in the tab bar.
|
||||
</theme_item>
|
||||
<theme_item name="font" data_type="font" type="Font">
|
||||
The font used to draw tab names.
|
||||
</theme_item>
|
||||
|
|
|
|||
|
|
@ -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<StyleBox> 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");
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ private:
|
|||
|
||||
struct ThemeCache {
|
||||
int h_separation = 0;
|
||||
int tab_separation = 0;
|
||||
int icon_max_width = 0;
|
||||
|
||||
Ref<StyleBox> tab_unselected_style;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ private:
|
|||
|
||||
// TabBar overrides.
|
||||
int icon_separation = 0;
|
||||
int tab_separation = 0;
|
||||
int icon_max_width = 0;
|
||||
int outline_size = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue