Skip to content

Commit

Permalink
Merge pull request #54267 from pycbouh/controls-button-font-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Oct 26, 2021
2 parents 46a139a + 12838bd commit 344babb
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 7 deletions.
6 changes: 6 additions & 0 deletions doc/classes/Button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.2)">
Text [Color] used when the [Button] is disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [Button] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [Button] is being hovered.
</theme_item>
Expand All @@ -143,6 +146,9 @@
<theme_item name="icon_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Icon modulate [Color] used when the [Button] is disabled.
</theme_item>
<theme_item name="icon_focus_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Icon modulate [Color] used when the [Button] is focused. Only replaces the normal modulate color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="icon_hover_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Icon modulate [Color] used when the [Button] is being hovered.
</theme_item>
Expand Down
5 changes: 5 additions & 0 deletions doc/classes/CheckBox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
The check icon to display when the [CheckBox] is checked.
</theme_item>
<theme_item name="checked_disabled" data_type="icon" type="Texture2D">
The check icon to display when the [CheckBox] is checked and disabled.
</theme_item>
<theme_item name="disabled" data_type="style" type="StyleBox">
The [StyleBox] to display as a background when the [CheckBox] is disabled.
Expand All @@ -37,6 +38,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.2)">
The [CheckBox] text's font color when it's disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
The [CheckBox] text's font color when it's focused. Only replaces the normal text color of the checkbox. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
The [CheckBox] text's font color when it's hovered.
</theme_item>
Expand Down Expand Up @@ -84,6 +88,7 @@
The check icon to display when the [CheckBox] is unchecked.
</theme_item>
<theme_item name="unchecked_disabled" data_type="icon" type="Texture2D">
The check icon to display when the [CheckBox] is unchecked and disabled.
</theme_item>
</theme_items>
</class>
3 changes: 3 additions & 0 deletions doc/classes/CheckButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.2)">
The [CheckButton] text's font color when it's disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
The [CheckButton] text's font color when it's focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
The [CheckButton] text's font color when it's hovered.
</theme_item>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/ColorPickerButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.3)">
Text [Color] used when the [ColorPickerButton] is disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Text [Color] used when the [ColorPickerButton] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(1, 1, 1, 1)">
Text [Color] used when the [ColorPickerButton] is being hovered.
</theme_item>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/LinkButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<theme_item name="font_color" data_type="color" type="Color" default="Color(0.88, 0.88, 0.88, 1)">
Default text [Color] of the [LinkButton].
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [LinkButton] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [LinkButton] is being hovered.
</theme_item>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/MenuButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(1, 1, 1, 0.3)">
Text [Color] used when the [MenuButton] is disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [MenuButton] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [MenuButton] is being hovered.
</theme_item>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/OptionButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
<theme_item name="font_disabled_color" data_type="color" type="Color" default="Color(0.9, 0.9, 0.9, 0.2)">
Text [Color] used when the [OptionButton] is disabled.
</theme_item>
<theme_item name="font_focus_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [OptionButton] is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.
</theme_item>
<theme_item name="font_hover_color" data_type="color" type="Color" default="Color(0.94, 0.94, 0.94, 1)">
Text [Color] used when the [OptionButton] is being hovered.
</theme_item>
Expand Down
12 changes: 12 additions & 0 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

const Color font_color = mono_color.lerp(base_color, 0.25);
const Color font_hover_color = mono_color.lerp(base_color, 0.125);
const Color font_focus_color = mono_color.lerp(base_color, 0.125);
const Color font_disabled_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.3);
const Color font_readonly_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.65);
const Color selection_color = accent_color * Color(1, 1, 1, 0.4);
Expand All @@ -392,6 +393,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

Color icon_hover_color = Color(1, 1, 1) * (dark_theme ? 1.15 : 1.45);
icon_hover_color.a = 1.0;
Color icon_focus_color = icon_hover_color;
// Make the pressed icon color overbright because icons are not completely white on a dark theme.
// On a light theme, icons are dark, so we need to modulate them with an even brighter color.
Color icon_pressed_color = accent_color * (dark_theme ? 1.15 : 3.5);
Expand Down Expand Up @@ -625,6 +627,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_color("font_color", "MenuButton", font_color);
theme->set_color("font_hover_color", "MenuButton", font_hover_color);
theme->set_color("font_focus_color", "MenuButton", font_focus_color);

theme->set_stylebox("MenuHover", "EditorStyles", style_widget_hover);

Expand All @@ -637,9 +640,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_color("font_color", "Button", font_color);
theme->set_color("font_hover_color", "Button", font_hover_color);
theme->set_color("font_focus_color", "Button", font_focus_color);
theme->set_color("font_pressed_color", "Button", accent_color);
theme->set_color("font_disabled_color", "Button", font_disabled_color);
theme->set_color("icon_hover_color", "Button", icon_hover_color);
theme->set_color("icon_focus_color", "Button", icon_focus_color);
theme->set_color("icon_pressed_color", "Button", icon_pressed_color);

// OptionButton
Expand All @@ -657,9 +662,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_color("font_color", "OptionButton", font_color);
theme->set_color("font_hover_color", "OptionButton", font_hover_color);
theme->set_color("font_focus_color", "OptionButton", font_focus_color);
theme->set_color("font_pressed_color", "OptionButton", accent_color);
theme->set_color("font_disabled_color", "OptionButton", font_disabled_color);
theme->set_color("icon_hover_color", "OptionButton", icon_hover_color);
theme->set_color("icon_focus_color", "OptionButton", icon_focus_color);
theme->set_icon("arrow", "OptionButton", theme->get_icon("GuiOptionArrow", "EditorIcons"));
theme->set_constant("arrow_margin", "OptionButton", widget_default_margin.x - 2 * EDSCALE);
theme->set_constant("modulate_arrow", "OptionButton", true);
Expand All @@ -683,9 +690,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_color("font_color", "CheckButton", font_color);
theme->set_color("font_hover_color", "CheckButton", font_hover_color);
theme->set_color("font_focus_color", "CheckButton", font_focus_color);
theme->set_color("font_pressed_color", "CheckButton", accent_color);
theme->set_color("font_disabled_color", "CheckButton", font_disabled_color);
theme->set_color("icon_hover_color", "CheckButton", icon_hover_color);
theme->set_color("icon_focus_color", "CheckButton", icon_focus_color);

theme->set_constant("hseparation", "CheckButton", 8 * EDSCALE);
theme->set_constant("check_vadjust", "CheckButton", 0 * EDSCALE);
Expand All @@ -712,9 +721,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_color("font_color", "CheckBox", font_color);
theme->set_color("font_hover_color", "CheckBox", font_hover_color);
theme->set_color("font_focus_color", "CheckBox", font_focus_color);
theme->set_color("font_pressed_color", "CheckBox", accent_color);
theme->set_color("font_disabled_color", "CheckBox", font_disabled_color);
theme->set_color("icon_hover_color", "CheckBox", icon_hover_color);
theme->set_color("icon_focus_color", "CheckBox", icon_focus_color);

theme->set_constant("hseparation", "CheckBox", 8 * EDSCALE);
theme->set_constant("check_vadjust", "CheckBox", 0 * EDSCALE);
Expand Down Expand Up @@ -1219,6 +1230,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_stylebox("focus", "LinkButton", style_empty);
theme->set_color("font_color", "LinkButton", font_color);
theme->set_color("font_hover_color", "LinkButton", font_hover_color);
theme->set_color("font_focus_color", "LinkButton", font_focus_color);
theme->set_color("font_pressed_color", "LinkButton", accent_color);
theme->set_color("font_disabled_color", "LinkButton", font_disabled_color);

Expand Down
6 changes: 5 additions & 1 deletion editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2894,7 +2894,11 @@ void TileMapEditor::_layers_selection_button_draw() {
clr = get_theme_color(SNAME("font_disabled_color"));
break;
default:
clr = get_theme_color(SNAME("font_color"));
if (layers_selection_button->has_focus()) {
clr = get_theme_color(SNAME("font_focus_color"));
} else {
clr = get_theme_color(SNAME("font_color"));
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion editor/plugins/tiles/tile_set_atlas_source_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,11 @@ void TileSetAtlasSourceEditor::_tile_data_editor_dropdown_button_draw() {
clr = get_theme_color(SNAME("font_disabled_color"));
break;
default:
clr = get_theme_color(SNAME("font_color"));
if (tile_data_editor_dropdown_button->has_focus()) {
clr = get_theme_color(SNAME("font_focus_color"));
} else {
clr = get_theme_color(SNAME("font_color"));
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@ void Button::_notification(int p_what) {
if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
}
color = get_theme_color(SNAME("font_color"));
if (has_theme_color(SNAME("icon_normal_color"))) {
color_icon = get_theme_color(SNAME("icon_normal_color"));

// Focus colors only take precedence over normal state.
if (has_focus()) {
color = get_theme_color(SNAME("font_focus_color"));
if (has_theme_color(SNAME("icon_focus_color"))) {
color_icon = get_theme_color(SNAME("icon_focus_color"));
}
} else {
color = get_theme_color(SNAME("font_color"));
if (has_theme_color(SNAME("icon_normal_color"))) {
color_icon = get_theme_color(SNAME("icon_normal_color"));
}
}
} break;
case DRAW_HOVER_PRESSED: {
Expand Down
6 changes: 6 additions & 0 deletions scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,32 @@ VBoxContainer *FileDialog::get_vbox() {
void FileDialog::_theme_changed() {
Color font_color = vbox->get_theme_color(SNAME("font_color"), SNAME("Button"));
Color font_hover_color = vbox->get_theme_color(SNAME("font_hover_color"), SNAME("Button"));
Color font_focus_color = vbox->get_theme_color(SNAME("font_focus_color"), SNAME("Button"));
Color font_pressed_color = vbox->get_theme_color(SNAME("font_pressed_color"), SNAME("Button"));

dir_up->add_theme_color_override("icon_normal_color", font_color);
dir_up->add_theme_color_override("icon_hover_color", font_hover_color);
dir_up->add_theme_color_override("icon_focus_color", font_focus_color);
dir_up->add_theme_color_override("icon_pressed_color", font_pressed_color);

dir_prev->add_theme_color_override("icon_color_normal", font_color);
dir_prev->add_theme_color_override("icon_color_hover", font_hover_color);
dir_prev->add_theme_color_override("icon_focus_color", font_focus_color);
dir_prev->add_theme_color_override("icon_color_pressed", font_pressed_color);

dir_next->add_theme_color_override("icon_color_normal", font_color);
dir_next->add_theme_color_override("icon_color_hover", font_hover_color);
dir_next->add_theme_color_override("icon_focus_color", font_focus_color);
dir_next->add_theme_color_override("icon_color_pressed", font_pressed_color);

refresh->add_theme_color_override("icon_normal_color", font_color);
refresh->add_theme_color_override("icon_hover_color", font_hover_color);
refresh->add_theme_color_override("icon_focus_color", font_focus_color);
refresh->add_theme_color_override("icon_pressed_color", font_pressed_color);

show_hidden->add_theme_color_override("icon_normal_color", font_color);
show_hidden->add_theme_color_override("icon_hover_color", font_hover_color);
show_hidden->add_theme_color_override("icon_focus_color", font_focus_color);
show_hidden->add_theme_color_override("icon_pressed_color", font_pressed_color);
}

Expand Down
7 changes: 6 additions & 1 deletion scene/gui/link_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ void LinkButton::_notification(int p_what) {

switch (get_draw_mode()) {
case DRAW_NORMAL: {
color = get_theme_color(SNAME("font_color"));
if (has_focus()) {
color = get_theme_color(SNAME("font_focus_color"));
} else {
color = get_theme_color(SNAME("font_color"));
}

do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
} break;
case DRAW_HOVER_PRESSED:
Expand Down
6 changes: 5 additions & 1 deletion scene/gui/option_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ void OptionButton::_notification(int p_what) {
clr = get_theme_color(SNAME("font_disabled_color"));
break;
default:
clr = get_theme_color(SNAME("font_color"));
if (has_focus()) {
clr = get_theme_color(SNAME("font_focus_color"));
} else {
clr = get_theme_color(SNAME("font_color"));
}
}
}

Expand Down
Loading

0 comments on commit 344babb

Please sign in to comment.