diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-04-03 18:01:10 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-04-03 18:01:10 +0200 |
commit | 91ff34b5b569916479fdcb40430d10cb7f15401c (patch) | |
tree | 43808ea366c44fbf666b9e62b6f1158808af20df /scene/main/window.cpp | |
parent | 5fbbe3be0b3da034557eae0a5066f784d72df4a9 (diff) | |
download | redot-engine-91ff34b5b569916479fdcb40430d10cb7f15401c.tar.gz |
Add a warning when trying to access theme items too early
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r-- | scene/main/window.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 0588a116a8..dbc778deec 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1073,6 +1073,8 @@ Viewport *Window::get_embedder() const { void Window::_notification(int p_what) { switch (p_what) { case NOTIFICATION_POSTINITIALIZE: { + initialized = true; + _invalidate_theme_cache(); _update_theme_item_cache(); } break; @@ -1754,6 +1756,10 @@ StringName Window::get_theme_type_variation() const { /// Theme property lookup. Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name); if (tex) { @@ -1773,6 +1779,10 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName } Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const Ref<StyleBox> *style = theme_style_override.getptr(p_name); if (style) { @@ -1792,6 +1802,10 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN } Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const Ref<Font> *font = theme_font_override.getptr(p_name); if (font) { @@ -1811,6 +1825,10 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t } int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const int *font_size = theme_font_size_override.getptr(p_name); if (font_size && (*font_size) > 0) { @@ -1830,6 +1848,10 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th } Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const Color *color = theme_color_override.getptr(p_name); if (color) { @@ -1849,6 +1871,10 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them } int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { const int *constant = theme_constant_override.getptr(p_name); if (constant) { @@ -1868,6 +1894,10 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the } bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_icon_override(p_name)) { return true; @@ -1880,6 +1910,10 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_ } bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_stylebox_override(p_name)) { return true; @@ -1892,6 +1926,10 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th } bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_font_override(p_name)) { return true; @@ -1904,6 +1942,10 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_ } bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_font_size_override(p_name)) { return true; @@ -1916,6 +1958,10 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t } bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_color_override(p_name)) { return true; @@ -1928,6 +1974,10 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme } bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (!initialized) { + WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + } + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { if (has_theme_constant_override(p_name)) { return true; |