Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register theme properties with ThemeDB #81312

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions scene/gui/box_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

#include "box_container.h"

#include "label.h"
#include "margin_container.h"
#include "scene/gui/label.h"
#include "scene/gui/margin_container.h"
#include "scene/theme/theme_db.h"

struct _MinSizeCache {
int min_size = 0;
Expand Down Expand Up @@ -288,12 +289,6 @@ Size2 BoxContainer::get_minimum_size() const {
return minimum;
}

void BoxContainer::_update_theme_item_cache() {
Container::_update_theme_item_cache();

theme_cache.separation = get_theme_constant(SNAME("separation"));
}

void BoxContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
Expand Down Expand Up @@ -399,6 +394,8 @@ void BoxContainer::_bind_methods() {

ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), "set_alignment", "get_alignment");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical");

BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, BoxContainer, separation);
}

MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control *p_control, bool p_expand) {
Expand Down
2 changes: 0 additions & 2 deletions scene/gui/box_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class BoxContainer : public Container {
protected:
bool is_fixed = false;

virtual void _update_theme_item_cache() override;

void _notification(int p_what);
void _validate_property(PropertyInfo &p_property) const;
static void _bind_methods();
Expand Down
77 changes: 37 additions & 40 deletions scene/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "button.h"

#include "core/string/translation.h"
#include "scene/theme/theme_db.h"
#include "servers/rendering_server.h"

Size2 Button::get_minimum_size() const {
Expand All @@ -49,46 +50,6 @@ void Button::_set_internal_margin(Side p_side, float p_value) {
void Button::_queue_update_size_cache() {
}

void Button::_update_theme_item_cache() {
BaseButton::_update_theme_item_cache();

theme_cache.normal = get_theme_stylebox(SNAME("normal"));
theme_cache.normal_mirrored = get_theme_stylebox(SNAME("normal_mirrored"));
theme_cache.pressed = get_theme_stylebox(SNAME("pressed"));
theme_cache.pressed_mirrored = get_theme_stylebox(SNAME("pressed_mirrored"));
theme_cache.hover = get_theme_stylebox(SNAME("hover"));
theme_cache.hover_mirrored = get_theme_stylebox(SNAME("hover_mirrored"));
theme_cache.hover_pressed = get_theme_stylebox(SNAME("hover_pressed"));
theme_cache.hover_pressed_mirrored = get_theme_stylebox(SNAME("hover_pressed_mirrored"));
theme_cache.disabled = get_theme_stylebox(SNAME("disabled"));
theme_cache.disabled_mirrored = get_theme_stylebox(SNAME("disabled_mirrored"));
theme_cache.focus = get_theme_stylebox(SNAME("focus"));

theme_cache.font_color = get_theme_color(SNAME("font_color"));
theme_cache.font_focus_color = get_theme_color(SNAME("font_focus_color"));
theme_cache.font_pressed_color = get_theme_color(SNAME("font_pressed_color"));
theme_cache.font_hover_color = get_theme_color(SNAME("font_hover_color"));
theme_cache.font_hover_pressed_color = get_theme_color(SNAME("font_hover_pressed_color"));
theme_cache.font_disabled_color = get_theme_color(SNAME("font_disabled_color"));

theme_cache.font = get_theme_font(SNAME("font"));
theme_cache.font_size = get_theme_font_size(SNAME("font_size"));
theme_cache.outline_size = get_theme_constant(SNAME("outline_size"));
theme_cache.font_outline_color = get_theme_color(SNAME("font_outline_color"));

theme_cache.icon_normal_color = get_theme_color(SNAME("icon_normal_color"));
theme_cache.icon_focus_color = get_theme_color(SNAME("icon_focus_color"));
theme_cache.icon_pressed_color = get_theme_color(SNAME("icon_pressed_color"));
theme_cache.icon_hover_color = get_theme_color(SNAME("icon_hover_color"));
theme_cache.icon_hover_pressed_color = get_theme_color(SNAME("icon_hover_pressed_color"));
theme_cache.icon_disabled_color = get_theme_color(SNAME("icon_disabled_color"));

theme_cache.icon = get_theme_icon(SNAME("icon"));

theme_cache.h_separation = get_theme_constant(SNAME("h_separation"));
theme_cache.icon_max_width = get_theme_constant(SNAME("icon_max_width"));
}

void Button::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
Expand Down Expand Up @@ -670,6 +631,42 @@ void Button::_bind_methods() {
ADD_GROUP("BiDi", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");

BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, normal);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, normal_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, pressed);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, pressed_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, hover);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, hover_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, hover_pressed);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, hover_pressed_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, disabled_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, Button, focus);

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_focus_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_pressed_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_hover_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_hover_pressed_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_disabled_color);

BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, Button, font);
BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, Button, font_size);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Button, outline_size);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, font_outline_color);

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_normal_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_focus_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_pressed_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_hover_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_hover_pressed_color);
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, Button, icon_disabled_color);

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, Button, icon);

BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Button, h_separation);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, Button, icon_max_width);
}

Button::Button(const String &p_text) {
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class Button : public BaseButton {

protected:
void _set_internal_margin(Side p_side, float p_value);
virtual void _update_theme_item_cache() override;
virtual void _queue_update_size_cache();

void _notification(int p_what);
static void _bind_methods();

Expand Down
33 changes: 16 additions & 17 deletions scene/gui/check_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "check_box.h"

#include "scene/theme/theme_db.h"
#include "servers/rendering_server.h"

Size2 CheckBox::get_icon_size() const {
Expand Down Expand Up @@ -73,23 +74,6 @@ Size2 CheckBox::get_minimum_size() const {
return minsize;
}

void CheckBox::_update_theme_item_cache() {
Button::_update_theme_item_cache();

theme_cache.h_separation = get_theme_constant(SNAME("h_separation"));
theme_cache.check_v_offset = get_theme_constant(SNAME("check_v_offset"));
theme_cache.normal_style = get_theme_stylebox(SNAME("normal"));

theme_cache.checked = get_theme_icon(SNAME("checked"));
theme_cache.unchecked = get_theme_icon(SNAME("unchecked"));
theme_cache.radio_checked = get_theme_icon(SNAME("radio_checked"));
theme_cache.radio_unchecked = get_theme_icon(SNAME("radio_unchecked"));
theme_cache.checked_disabled = get_theme_icon(SNAME("checked_disabled"));
theme_cache.unchecked_disabled = get_theme_icon(SNAME("unchecked_disabled"));
theme_cache.radio_checked_disabled = get_theme_icon(SNAME("radio_checked_disabled"));
theme_cache.radio_unchecked_disabled = get_theme_icon(SNAME("radio_unchecked_disabled"));
}

void CheckBox::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED:
Expand Down Expand Up @@ -149,6 +133,21 @@ bool CheckBox::is_radio() {
return get_button_group().is_valid();
}

void CheckBox::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, CheckBox, h_separation);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, CheckBox, check_v_offset);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, CheckBox, normal_style, "normal");

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, checked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, unchecked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, radio_checked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, radio_unchecked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, checked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, unchecked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, radio_checked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckBox, radio_unchecked_disabled);
}

CheckBox::CheckBox(const String &p_text) :
Button(p_text) {
set_toggle_mode(true);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/check_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class CheckBox : public Button {
Size2 get_icon_size() const;
Size2 get_minimum_size() const override;

virtual void _update_theme_item_cache() override;
void _notification(int p_what);
static void _bind_methods();

bool is_radio();

Expand Down
34 changes: 16 additions & 18 deletions scene/gui/check_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "check_button.h"

#include "core/string/print_string.h"
#include "scene/theme/theme_db.h"
#include "servers/rendering_server.h"

Size2 CheckButton::get_icon_size() const {
Expand Down Expand Up @@ -78,23 +78,6 @@ Size2 CheckButton::get_minimum_size() const {
return minsize;
}

void CheckButton::_update_theme_item_cache() {
Button::_update_theme_item_cache();

theme_cache.h_separation = get_theme_constant(SNAME("h_separation"));
theme_cache.check_v_offset = get_theme_constant(SNAME("check_v_offset"));
theme_cache.normal_style = get_theme_stylebox(SNAME("normal"));

theme_cache.checked = get_theme_icon(SNAME("checked"));
theme_cache.unchecked = get_theme_icon(SNAME("unchecked"));
theme_cache.checked_disabled = get_theme_icon(SNAME("checked_disabled"));
theme_cache.unchecked_disabled = get_theme_icon(SNAME("unchecked_disabled"));
theme_cache.checked_mirrored = get_theme_icon(SNAME("checked_mirrored"));
theme_cache.unchecked_mirrored = get_theme_icon(SNAME("unchecked_mirrored"));
theme_cache.checked_disabled_mirrored = get_theme_icon(SNAME("checked_disabled_mirrored"));
theme_cache.unchecked_disabled_mirrored = get_theme_icon(SNAME("unchecked_disabled_mirrored"));
}

void CheckButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED:
Expand Down Expand Up @@ -153,6 +136,21 @@ void CheckButton::_notification(int p_what) {
}
}

void CheckButton::_bind_methods() {
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, CheckButton, h_separation);
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, CheckButton, check_v_offset);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, CheckButton, normal_style, "normal");

BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, checked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, unchecked);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, checked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, unchecked_disabled);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, checked_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, unchecked_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, checked_disabled_mirrored);
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CheckButton, unchecked_disabled_mirrored);
}

CheckButton::CheckButton(const String &p_text) :
Button(p_text) {
set_toggle_mode(true);
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/check_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class CheckButton : public Button {
Size2 get_icon_size() const;
virtual Size2 get_minimum_size() const override;

virtual void _update_theme_item_cache() override;
void _notification(int p_what);
static void _bind_methods();

public:
CheckButton(const String &p_text = String());
Expand Down
96 changes: 47 additions & 49 deletions scene/gui/code_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "core/os/keyboard.h"
#include "core/string/string_builder.h"
#include "core/string/ustring.h"
#include "scene/theme/theme_db.h"

void CodeEdit::_notification(int p_what) {
switch (p_what) {
Expand Down Expand Up @@ -228,55 +229,6 @@ void CodeEdit::_notification(int p_what) {
}
}

void CodeEdit::_update_theme_item_cache() {
TextEdit::_update_theme_item_cache();

/* Gutters */
theme_cache.code_folding_color = get_theme_color(SNAME("code_folding_color"));
theme_cache.can_fold_icon = get_theme_icon(SNAME("can_fold"));
theme_cache.folded_icon = get_theme_icon(SNAME("folded"));
theme_cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"));

theme_cache.breakpoint_color = get_theme_color(SNAME("breakpoint_color"));
theme_cache.breakpoint_icon = get_theme_icon(SNAME("breakpoint"));

theme_cache.bookmark_color = get_theme_color(SNAME("bookmark_color"));
theme_cache.bookmark_icon = get_theme_icon(SNAME("bookmark"));

theme_cache.executing_line_color = get_theme_color(SNAME("executing_line_color"));
theme_cache.executing_line_icon = get_theme_icon(SNAME("executing_line"));

theme_cache.line_number_color = get_theme_color(SNAME("line_number_color"));

/* Code Completion */
theme_cache.code_completion_style = get_theme_stylebox(SNAME("completion"));
theme_cache.code_completion_icon_separation = get_theme_constant(SNAME("h_separation"), SNAME("ItemList"));

theme_cache.code_completion_max_width = get_theme_constant(SNAME("completion_max_width"));
theme_cache.code_completion_max_lines = get_theme_constant(SNAME("completion_lines"));
theme_cache.code_completion_scroll_width = get_theme_constant(SNAME("completion_scroll_width"));
theme_cache.code_completion_scroll_color = get_theme_color(SNAME("completion_scroll_color"));
theme_cache.code_completion_scroll_hovered_color = get_theme_color(SNAME("completion_scroll_hovered_color"));
theme_cache.code_completion_background_color = get_theme_color(SNAME("completion_background_color"));
theme_cache.code_completion_selected_color = get_theme_color(SNAME("completion_selected_color"));
theme_cache.code_completion_existing_color = get_theme_color(SNAME("completion_existing_color"));

/* Code hint */
theme_cache.code_hint_style = get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel"));
theme_cache.code_hint_color = get_theme_color(SNAME("font_color"), SNAME("TooltipLabel"));

/* Line length guideline */
theme_cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color"));

/* Other visuals */
theme_cache.style_normal = get_theme_stylebox(SNAME("normal"));

theme_cache.font = get_theme_font(SNAME("font"));
theme_cache.font_size = get_theme_font_size(SNAME("font_size"));

theme_cache.line_spacing = get_theme_constant(SNAME("line_spacing"));
}

void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) {
Expand Down Expand Up @@ -2527,6 +2479,52 @@ void CodeEdit::_bind_methods() {
/* Symbol lookup */
ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "column")));
ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol")));

/* Theme items */
/* Gutters */
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, code_folding_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, can_fold_icon, "can_fold");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, folded_icon, "folded");
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CodeEdit, folded_eol_icon);

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, breakpoint_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, breakpoint_icon, "breakpoint");

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, bookmark_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, bookmark_icon, "bookmark");

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, executing_line_color);
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, executing_line_icon, "executing_line");

BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, line_number_color);

/* Code Completion */
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, CodeEdit, code_completion_style, "completion");
BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_CONSTANT, CodeEdit, code_completion_icon_separation, "h_separation", "ItemList");

BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, CodeEdit, code_completion_max_width, "completion_max_width");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, CodeEdit, code_completion_max_lines, "completion_lines");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, CodeEdit, code_completion_scroll_width, "completion_scroll_width");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, code_completion_scroll_color, "completion_scroll_color");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, code_completion_scroll_hovered_color, "completion_scroll_hovered_color");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, code_completion_background_color, "completion_background_color");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, code_completion_selected_color, "completion_selected_color");
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_COLOR, CodeEdit, code_completion_existing_color, "completion_existing_color");

/* Code hint */
BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, CodeEdit, code_hint_style, "panel", "TooltipPanel");
BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, CodeEdit, code_hint_color, "font_color", "TooltipLabel");

/* Line length guideline */
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, line_length_guideline_color);

/* Other visuals */
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, CodeEdit, style_normal, "normal");

BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, CodeEdit, font);
BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, CodeEdit, font_size);

BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, CodeEdit, line_spacing);
}

/* Auto brace completion */
Expand Down
Loading