From 59e9a8c275ac56bdc23883d8902920e93bcb6c69 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Thu, 13 Jan 2022 18:13:45 -0300 Subject: [PATCH] Fix theming for floating window docks --- doc/classes/Panel.xml | 10 ---------- editor/editor_node.cpp | 7 ++++--- editor/editor_themes.cpp | 2 +- scene/gui/panel.cpp | 23 +---------------------- scene/gui/panel.h | 15 --------------- 5 files changed, 6 insertions(+), 51 deletions(-) diff --git a/doc/classes/Panel.xml b/doc/classes/Panel.xml index 21ac7dfac15..3246fa7eba5 100644 --- a/doc/classes/Panel.xml +++ b/doc/classes/Panel.xml @@ -11,16 +11,6 @@ https://godotengine.org/asset-library/asset/516 https://godotengine.org/asset-library/asset/523 - - - - - - - - - - The style of this [Panel]. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index b98b7fd3dcc..a4b6790d1c4 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4236,8 +4236,9 @@ void EditorNode::_dock_make_float() { Control *dock = dock_slot[dock_popup_selected]->get_current_tab_control(); ERR_FAIL_COND(!dock); - const Size2i borders = Size2i(4, 4) * EDSCALE; - Size2 dock_size = dock->get_size() + borders * 2; // remember size + Size2 borders = Size2(4, 4) * EDSCALE; + // Remember size and position before removing it from the main window. + Size2 dock_size = dock->get_size() + borders * 2; Point2 dock_screen_pos = dock->get_global_position() + get_tree()->get_root()->get_position() - borders; int dock_index = dock->get_index(); @@ -4246,7 +4247,7 @@ void EditorNode::_dock_make_float() { Window *window = memnew(Window); window->set_title(dock->get_name()); Panel *p = memnew(Panel); - p->set_mode(Panel::MODE_FOREGROUND); + p->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("PanelForeground"), SNAME("EditorStyles"))); p->set_anchors_and_offsets_preset(Control::PRESET_WIDE); window->add_child(p); MarginContainer *margin = memnew(MarginContainer); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index ad5012edbf7..7aa5ba7023b 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -1279,7 +1279,7 @@ Ref create_editor_theme(const Ref p_theme) { // Panel theme->set_stylebox(SNAME("panel"), SNAME("Panel"), make_flat_stylebox(dark_color_1, 6, 4, 6, 4, corner_width)); - theme->set_stylebox(SNAME("panel_fg"), SNAME("Panel"), style_default); + theme->set_stylebox(SNAME("PanelForeground"), SNAME("EditorStyles"), style_default); // Label theme->set_stylebox(SNAME("normal"), SNAME("Label"), style_empty); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 86858fdc780..c88e4ae2f21 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -30,35 +30,14 @@ #include "panel.h" -#include "core/string/print_string.h" - void Panel::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref style = mode == MODE_BACKGROUND ? get_theme_stylebox(SNAME("panel")) : get_theme_stylebox(SNAME("panel_fg")); + Ref style = get_theme_stylebox(SNAME("panel")); style->draw(ci, Rect2(Point2(), get_size())); } } -void Panel::set_mode(Mode p_mode) { - mode = p_mode; - update(); -} - -Panel::Mode Panel::get_mode() const { - return mode; -} - -void Panel::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Panel::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &Panel::get_mode); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Background,Foreground"), "set_mode", "get_mode"); - - BIND_ENUM_CONSTANT(MODE_BACKGROUND); - BIND_ENUM_CONSTANT(MODE_FOREGROUND); -} - Panel::Panel() { // Has visible stylebox, so stop by default. set_mouse_filter(MOUSE_FILTER_STOP); diff --git a/scene/gui/panel.h b/scene/gui/panel.h index 37f14c250ca..5d2e9126806 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -36,26 +36,11 @@ class Panel : public Control { GDCLASS(Panel, Control); -public: - enum Mode { - MODE_BACKGROUND, - MODE_FOREGROUND, - }; - -private: - Mode mode = MODE_BACKGROUND; - protected: void _notification(int p_what); - static void _bind_methods(); public: - void set_mode(Mode p_mode); - Mode get_mode() const; - Panel(); }; -VARIANT_ENUM_CAST(Panel::Mode) - #endif // PANEL_H