mirror of
https://github.com/godotengine/godot
synced 2024-09-05 08:08:29 +00:00
Merge pull request #74632 from davthedev/tabs-hover
Add theming support for hovered tabs
This commit is contained in:
commit
dfee04ae2a
|
@ -341,6 +341,9 @@
|
|||
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 0.5)">
|
||||
Font color of disabled tabs.
|
||||
</theme_item>
|
||||
<theme_item name="font_hovered_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)">
|
||||
Font color of the currently hovered tab. Does not apply to the selected tab.
|
||||
</theme_item>
|
||||
<theme_item name="font_outline_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
|
||||
The tint of text outline of the tab name.
|
||||
</theme_item>
|
||||
|
@ -393,6 +396,9 @@
|
|||
<theme_item name="tab_disabled" data_type="style" type="StyleBox">
|
||||
The style of disabled tabs.
|
||||
</theme_item>
|
||||
<theme_item name="tab_hovered" data_type="style" type="StyleBox">
|
||||
The style of the currently hovered tab. Does not apply to the selected tab.
|
||||
</theme_item>
|
||||
<theme_item name="tab_selected" data_type="style" type="StyleBox">
|
||||
The style of the currently selected tab.
|
||||
</theme_item>
|
||||
|
|
|
@ -215,6 +215,9 @@
|
|||
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.875, 0.875, 0.875, 0.5)">
|
||||
Font color of disabled tabs.
|
||||
</theme_item>
|
||||
<theme_item name="font_hovered_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)">
|
||||
Font color of the currently hovered tab.
|
||||
</theme_item>
|
||||
<theme_item name="font_outline_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
|
||||
The tint of text outline of the tab name.
|
||||
</theme_item>
|
||||
|
@ -271,6 +274,9 @@
|
|||
<theme_item name="tab_disabled" data_type="style" type="StyleBox">
|
||||
The style of disabled tabs.
|
||||
</theme_item>
|
||||
<theme_item name="tab_hovered" data_type="style" type="StyleBox">
|
||||
The style of the currently hovered tab.
|
||||
</theme_item>
|
||||
<theme_item name="tab_selected" data_type="style" type="StyleBox">
|
||||
The style of the currently selected tab.
|
||||
</theme_item>
|
||||
|
|
|
@ -747,6 +747,12 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||
style_tab_selected->set_border_color(tab_highlight);
|
||||
style_tab_selected->set_corner_radius_all(0);
|
||||
|
||||
Ref<StyleBoxFlat> style_tab_hovered = style_tab_base->duplicate();
|
||||
|
||||
style_tab_hovered->set_bg_color(dark_color_1.lerp(base_color, 0.4));
|
||||
// Hovered tab has a subtle highlight between normal and selected states.
|
||||
style_tab_hovered->set_corner_radius_all(0);
|
||||
|
||||
Ref<StyleBoxFlat> style_tab_unselected = style_tab_base->duplicate();
|
||||
style_tab_unselected->set_expand_margin(SIDE_BOTTOM, 0);
|
||||
style_tab_unselected->set_bg_color(dark_color_1);
|
||||
|
@ -1326,17 +1332,21 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
|
|||
theme->set_stylebox("tabbar_background", "TabContainer", style_tabbar_background);
|
||||
|
||||
theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected);
|
||||
theme->set_stylebox("tab_hovered", "TabContainer", style_tab_hovered);
|
||||
theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected);
|
||||
theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled);
|
||||
theme->set_stylebox("tab_selected", "TabBar", style_tab_selected);
|
||||
theme->set_stylebox("tab_hovered", "TabBar", style_tab_hovered);
|
||||
theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected);
|
||||
theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled);
|
||||
theme->set_stylebox("button_pressed", "TabBar", style_menu);
|
||||
theme->set_stylebox("button_highlight", "TabBar", style_menu);
|
||||
theme->set_color("font_selected_color", "TabContainer", font_color);
|
||||
theme->set_color("font_hovered_color", "TabContainer", font_color);
|
||||
theme->set_color("font_unselected_color", "TabContainer", font_disabled_color);
|
||||
theme->set_color("font_outline_color", "TabContainer", font_outline_color);
|
||||
theme->set_color("font_selected_color", "TabBar", font_color);
|
||||
theme->set_color("font_hovered_color", "TabBar", font_color);
|
||||
theme->set_color("font_unselected_color", "TabBar", font_disabled_color);
|
||||
theme->set_color("font_outline_color", "TabBar", font_outline_color);
|
||||
theme->set_color("drop_mark_color", "TabContainer", tab_highlight);
|
||||
|
|
|
@ -44,7 +44,7 @@ Size2 TabBar::get_minimum_size() const {
|
|||
return ms;
|
||||
}
|
||||
|
||||
int y_margin = MAX(MAX(theme_cache.tab_unselected_style->get_minimum_size().height, theme_cache.tab_selected_style->get_minimum_size().height), theme_cache.tab_disabled_style->get_minimum_size().height);
|
||||
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);
|
||||
|
||||
for (int i = 0; i < tabs.size(); i++) {
|
||||
if (tabs[i].hidden) {
|
||||
|
@ -58,6 +58,8 @@ Size2 TabBar::get_minimum_size() const {
|
|||
style = theme_cache.tab_disabled_style;
|
||||
} else if (current == i) {
|
||||
style = theme_cache.tab_selected_style;
|
||||
} else if (hover == i) {
|
||||
style = theme_cache.tab_hovered_style;
|
||||
} else {
|
||||
style = theme_cache.tab_unselected_style;
|
||||
}
|
||||
|
@ -309,6 +311,7 @@ void TabBar::_update_theme_item_cache() {
|
|||
theme_cache.icon_max_width = get_theme_constant(SNAME("icon_max_width"));
|
||||
|
||||
theme_cache.tab_unselected_style = get_theme_stylebox(SNAME("tab_unselected"));
|
||||
theme_cache.tab_hovered_style = get_theme_stylebox(SNAME("tab_hovered"));
|
||||
theme_cache.tab_selected_style = get_theme_stylebox(SNAME("tab_selected"));
|
||||
theme_cache.tab_disabled_style = get_theme_stylebox(SNAME("tab_disabled"));
|
||||
|
||||
|
@ -324,6 +327,7 @@ void TabBar::_update_theme_item_cache() {
|
|||
theme_cache.outline_size = get_theme_constant(SNAME("outline_size"));
|
||||
|
||||
theme_cache.font_selected_color = get_theme_color(SNAME("font_selected_color"));
|
||||
theme_cache.font_hovered_color = get_theme_color(SNAME("font_hovered_color"));
|
||||
theme_cache.font_unselected_color = get_theme_color(SNAME("font_unselected_color"));
|
||||
theme_cache.font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
|
||||
theme_cache.font_outline_color = get_theme_color(SNAME("font_outline_color"));
|
||||
|
@ -399,6 +403,9 @@ void TabBar::_notification(int p_what) {
|
|||
if (tabs[i].disabled) {
|
||||
sb = theme_cache.tab_disabled_style;
|
||||
col = theme_cache.font_disabled_color;
|
||||
} else if (i == hover) {
|
||||
sb = theme_cache.tab_hovered_style;
|
||||
col = theme_cache.font_hovered_color;
|
||||
} else {
|
||||
sb = theme_cache.tab_unselected_style;
|
||||
col = theme_cache.font_unselected_color;
|
||||
|
@ -874,6 +881,7 @@ void TabBar::_update_hover() {
|
|||
if (hover != -1) {
|
||||
emit_signal(SNAME("tab_hovered"), hover);
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
if (hover_buttons == -1) { // No hover.
|
||||
|
@ -1313,6 +1321,8 @@ int TabBar::get_tab_width(int p_idx) const {
|
|||
style = theme_cache.tab_disabled_style;
|
||||
} else if (current == p_idx) {
|
||||
style = theme_cache.tab_selected_style;
|
||||
} else if (hover == p_idx) {
|
||||
style = theme_cache.tab_hovered_style;
|
||||
} else {
|
||||
style = theme_cache.tab_unselected_style;
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ private:
|
|||
int icon_max_width = 0;
|
||||
|
||||
Ref<StyleBox> tab_unselected_style;
|
||||
Ref<StyleBox> tab_hovered_style;
|
||||
Ref<StyleBox> tab_selected_style;
|
||||
Ref<StyleBox> tab_disabled_style;
|
||||
|
||||
|
@ -127,6 +128,7 @@ private:
|
|||
int outline_size = 0;
|
||||
|
||||
Color font_selected_color;
|
||||
Color font_hovered_color;
|
||||
Color font_unselected_color;
|
||||
Color font_disabled_color;
|
||||
Color font_outline_color;
|
||||
|
|
|
@ -150,6 +150,7 @@ void TabContainer::_update_theme_item_cache() {
|
|||
theme_cache.outline_size = get_theme_constant(SNAME("outline_size"));
|
||||
|
||||
theme_cache.tab_unselected_style = get_theme_stylebox(SNAME("tab_unselected"));
|
||||
theme_cache.tab_hovered_style = get_theme_stylebox(SNAME("tab_hovered"));
|
||||
theme_cache.tab_selected_style = get_theme_stylebox(SNAME("tab_selected"));
|
||||
theme_cache.tab_disabled_style = get_theme_stylebox(SNAME("tab_disabled"));
|
||||
|
||||
|
@ -227,6 +228,7 @@ void TabContainer::_on_theme_changed() {
|
|||
}
|
||||
|
||||
tab_bar->add_theme_style_override(SNAME("tab_unselected"), theme_cache.tab_unselected_style);
|
||||
tab_bar->add_theme_style_override(SNAME("tab_hovered"), theme_cache.tab_hovered_style);
|
||||
tab_bar->add_theme_style_override(SNAME("tab_selected"), theme_cache.tab_selected_style);
|
||||
tab_bar->add_theme_style_override(SNAME("tab_disabled"), theme_cache.tab_disabled_style);
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ class TabContainer : public Container {
|
|||
int outline_size = 0;
|
||||
|
||||
Ref<StyleBox> tab_unselected_style;
|
||||
Ref<StyleBox> tab_hovered_style;
|
||||
Ref<StyleBox> tab_selected_style;
|
||||
Ref<StyleBox> tab_disabled_style;
|
||||
|
||||
|
|
|
@ -827,8 +827,11 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||
style_tab_unselected->set_border_color(style_popup_border_color);
|
||||
Ref<StyleBoxFlat> style_tab_disabled = style_tab_unselected->duplicate();
|
||||
style_tab_disabled->set_bg_color(style_disabled_color);
|
||||
Ref<StyleBoxFlat> style_tab_hovered = style_tab_unselected->duplicate();
|
||||
style_tab_hovered->set_bg_color(Color(0.1, 0.1, 0.1, 0.3));
|
||||
|
||||
theme->set_stylebox("tab_selected", "TabContainer", style_tab_selected);
|
||||
theme->set_stylebox("tab_hovered", "TabContainer", style_tab_hovered);
|
||||
theme->set_stylebox("tab_unselected", "TabContainer", style_tab_unselected);
|
||||
theme->set_stylebox("tab_disabled", "TabContainer", style_tab_disabled);
|
||||
theme->set_stylebox("panel", "TabContainer", make_flat_stylebox(style_normal_color, 0, 0, 0, 0));
|
||||
|
@ -846,6 +849,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||
theme->set_font_size("font_size", "TabContainer", -1);
|
||||
|
||||
theme->set_color("font_selected_color", "TabContainer", control_font_hover_color);
|
||||
theme->set_color("font_hovered_color", "TabContainer", control_font_hover_color);
|
||||
theme->set_color("font_unselected_color", "TabContainer", control_font_low_color);
|
||||
theme->set_color("font_disabled_color", "TabContainer", control_font_disabled_color);
|
||||
theme->set_color("font_outline_color", "TabContainer", Color(1, 1, 1));
|
||||
|
@ -859,6 +863,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||
// TabBar
|
||||
|
||||
theme->set_stylebox("tab_selected", "TabBar", style_tab_selected);
|
||||
theme->set_stylebox("tab_hovered", "TabBar", style_tab_hovered);
|
||||
theme->set_stylebox("tab_unselected", "TabBar", style_tab_unselected);
|
||||
theme->set_stylebox("tab_disabled", "TabBar", style_tab_disabled);
|
||||
theme->set_stylebox("button_pressed", "TabBar", button_pressed);
|
||||
|
@ -875,6 +880,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||
theme->set_font_size("font_size", "TabBar", -1);
|
||||
|
||||
theme->set_color("font_selected_color", "TabBar", control_font_hover_color);
|
||||
theme->set_color("font_hovered_color", "TabBar", control_font_hover_color);
|
||||
theme->set_color("font_unselected_color", "TabBar", control_font_low_color);
|
||||
theme->set_color("font_disabled_color", "TabBar", control_font_disabled_color);
|
||||
theme->set_color("font_outline_color", "TabBar", Color(1, 1, 1));
|
||||
|
|
Loading…
Reference in a new issue