diff options
Diffstat (limited to 'scene/gui')
42 files changed, 387 insertions, 323 deletions
diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cpp index 711dd13781..1663a7d602 100644 --- a/scene/gui/aspect_ratio_container.cpp +++ b/scene/gui/aspect_ratio_container.cpp @@ -35,16 +35,10 @@ Size2 AspectRatioContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } @@ -107,13 +101,10 @@ void AspectRatioContainer::_notification(int p_what) { bool rtl = is_layout_rtl(); Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } // Temporary fix for editor crash. TextureRect *trect = Object::cast_to<TextureRect>(c); diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 66b14dc967..01e3cce78b 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -33,7 +33,6 @@ #include "core/config/project_settings.h" #include "core/os/keyboard.h" #include "scene/main/window.h" -#include "scene/scene_string_names.h" void BaseButton::_unpress_group() { if (!button_group.is_valid()) { @@ -135,7 +134,7 @@ void BaseButton::_notification(int p_what) { void BaseButton::_pressed() { GDVIRTUAL_CALL(_pressed); pressed(); - emit_signal(SNAME("pressed")); + emit_signal(SceneStringName(pressed)); } void BaseButton::_toggled(bool p_pressed) { @@ -162,7 +161,7 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) { status.pressed = !status.pressed; _unpress_group(); if (button_group.is_valid()) { - button_group->emit_signal(SNAME("pressed"), this); + button_group->emit_signal(SceneStringName(pressed), this); } _toggled(status.pressed); _pressed(); @@ -226,7 +225,7 @@ void BaseButton::set_pressed(bool p_pressed) { if (p_pressed) { _unpress_group(); if (button_group.is_valid()) { - button_group->emit_signal(SNAME("pressed"), this); + button_group->emit_signal(SceneStringName(pressed), this); } } _toggled(status.pressed); @@ -368,7 +367,7 @@ void BaseButton::shortcut_input(const Ref<InputEvent> &p_event) { _unpress_group(); if (button_group.is_valid()) { - button_group->emit_signal(SNAME("pressed"), this); + button_group->emit_signal(SceneStringName(pressed), this); } _toggled(status.pressed); diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 2728126e64..d8fcbbb883 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -55,11 +55,8 @@ void BoxContainer::_resort() { HashMap<Control *, _MinSizeCache> min_size_cache; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -109,11 +106,8 @@ void BoxContainer::_resort() { float error = 0.0; // Keep track of accumulated error in pixels for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -201,11 +195,8 @@ void BoxContainer::_resort() { } for (int i = start; i != end; i += delta) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -253,14 +244,7 @@ Size2 BoxContainer::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) { - continue; - } - if (c->is_set_as_top_level()) { - continue; - } - - if (!c->is_visible()) { + if (!c || !c->is_visible() || c->is_set_as_top_level()) { continue; } diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index ad3f607661..15b7f62036 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -298,6 +298,7 @@ void Button::_notification(int p_what) { icon_size = Size2(icon_width, icon_height); } icon_size = _fit_icon_size(icon_size); + icon_size = icon_size.round(); } if (icon_size.width > 0.0f) { @@ -336,6 +337,7 @@ void Button::_notification(int p_what) { icon_ofs.y = size.y - style_margin_bottom - icon_size.height; } break; } + icon_ofs = icon_ofs.floor(); Rect2 icon_region = Rect2(icon_ofs, icon_size); draw_texture_rect(_icon, icon_region, false, icon_modulate_color); diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp index acdeae289b..1af33d2814 100644 --- a/scene/gui/center_container.cpp +++ b/scene/gui/center_container.cpp @@ -36,16 +36,10 @@ Size2 CenterContainer::get_minimum_size() const { } Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { - continue; - } Size2 minsize = c->get_combined_minimum_size(); ms = ms.max(minsize); } @@ -81,14 +75,10 @@ void CenterContainer::_notification(int p_what) { case NOTIFICATION_SORT_CHILDREN: { Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - Size2 minsize = c->get_combined_minimum_size(); Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor(); fit_child_in_rect(c, Rect2(ofs, minsize)); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 848a598ebb..245a086dda 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -95,8 +95,8 @@ void ColorPicker::_notification(int p_what) { for (int i = 0; i < MODE_BUTTON_COUNT; i++) { mode_btns[i]->begin_bulk_theme_override(); - mode_btns[i]->add_theme_style_override(SNAME("pressed"), theme_cache.mode_button_pressed); - mode_btns[i]->add_theme_style_override(SNAME("normal"), theme_cache.mode_button_normal); + mode_btns[i]->add_theme_style_override(SceneStringName(pressed), theme_cache.mode_button_pressed); + mode_btns[i]->add_theme_style_override(CoreStringName(normal), theme_cache.mode_button_normal); mode_btns[i]->add_theme_style_override(SNAME("hover"), theme_cache.mode_button_hover); mode_btns[i]->end_bulk_theme_override(); } @@ -420,18 +420,18 @@ void ColorPicker::create_slider(GridContainer *gc, int idx) { LineEdit *vle = val->get_line_edit(); vle->connect("text_changed", callable_mp(this, &ColorPicker::_text_changed)); - vle->connect("gui_input", callable_mp(this, &ColorPicker::_line_edit_input)); + vle->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_line_edit_input)); vle->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT); - val->connect("gui_input", callable_mp(this, &ColorPicker::_slider_or_spin_input)); + val->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_slider_or_spin_input)); slider->set_h_size_flags(SIZE_EXPAND_FILL); slider->connect("drag_started", callable_mp(this, &ColorPicker::_slider_drag_started)); slider->connect("value_changed", callable_mp(this, &ColorPicker::_slider_value_changed).unbind(1)); slider->connect("drag_ended", callable_mp(this, &ColorPicker::_slider_drag_ended).unbind(1)); - slider->connect("draw", callable_mp(this, &ColorPicker::_slider_draw).bind(idx)); - slider->connect("gui_input", callable_mp(this, &ColorPicker::_slider_or_spin_input)); + slider->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_slider_draw).bind(idx)); + slider->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_slider_or_spin_input)); if (idx < SLIDER_COUNT) { sliders[idx] = slider; @@ -458,8 +458,8 @@ void ColorPicker::set_editor_settings(Object *p_editor_settings) { } } - for (int i = 0; i < preset_cache.size(); i++) { - presets.push_back(preset_cache[i]); + for (const Color &preset : preset_cache) { + presets.push_back(preset); } if (recent_preset_cache.is_empty()) { @@ -469,8 +469,8 @@ void ColorPicker::set_editor_settings(Object *p_editor_settings) { } } - for (int i = 0; i < recent_preset_cache.size(); i++) { - recent_presets.push_back(recent_preset_cache[i]); + for (const Color &preset : recent_preset_cache) { + recent_presets.push_back(preset); } _update_presets(); @@ -660,8 +660,8 @@ void ColorPicker::_update_presets() { for (int i = 1; i < preset_container->get_child_count(); i++) { preset_container->get_child(i)->queue_free(); } - for (int i = 0; i < preset_cache.size(); i++) { - _add_preset_button(preset_size, preset_cache[i]); + for (const Color &preset : preset_cache) { + _add_preset_button(preset_size, preset); } _notification(NOTIFICATION_VISIBILITY_CHANGED); } @@ -677,13 +677,13 @@ void ColorPicker::_update_recent_presets() { } recent_presets.clear(); - for (int i = 0; i < recent_preset_cache.size(); i++) { - recent_presets.push_back(recent_preset_cache[i]); + for (const Color &preset : recent_preset_cache) { + recent_presets.push_back(preset); } int preset_size = _get_preset_size(); - for (int i = 0; i < recent_presets.size(); i++) { - _add_recent_preset_button(preset_size, recent_presets[i]); + for (const Color &preset : recent_presets) { + _add_recent_preset_button(preset_size, preset); } _notification(NOTIFICATION_VISIBILITY_CHANGED); @@ -761,7 +761,7 @@ void ColorPicker::_add_preset_button(int p_size, const Color &p_color) { btn_preset_new->set_button_group(preset_group); preset_container->add_child(btn_preset_new); btn_preset_new->set_pressed(true); - btn_preset_new->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input).bind(p_color)); + btn_preset_new->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_preset_input).bind(p_color)); } void ColorPicker::_add_recent_preset_button(int p_size, const Color &p_color) { @@ -937,8 +937,9 @@ void ColorPicker::erase_recent_preset(const Color &p_color) { PackedColorArray ColorPicker::get_presets() const { PackedColorArray arr; arr.resize(presets.size()); - for (int i = 0; i < presets.size(); i++) { - arr.set(i, presets[i]); + int i = 0; + for (List<Color>::ConstIterator itr = presets.begin(); itr != presets.end(); ++itr, ++i) { + arr.set(i, *itr); } return arr; } @@ -946,8 +947,9 @@ PackedColorArray ColorPicker::get_presets() const { PackedColorArray ColorPicker::get_recent_presets() const { PackedColorArray arr; arr.resize(recent_presets.size()); - for (int i = 0; i < recent_presets.size(); i++) { - arr.set(i, recent_presets[i]); + int i = 0; + for (List<Color>::ConstIterator itr = recent_presets.begin(); itr != recent_presets.end(); ++itr, ++i) { + arr.set(i, *itr); } return arr; } @@ -1508,7 +1510,7 @@ void ColorPicker::_pick_button_pressed() { if (!picker_window) { picker_window = memnew(Popup); picker_window->set_size(Vector2i(1, 1)); - picker_window->connect("visibility_changed", callable_mp(this, &ColorPicker::_pick_finished)); + picker_window->connect(SceneStringName(visibility_changed), callable_mp(this, &ColorPicker::_pick_finished)); add_child(picker_window, false, INTERNAL_MODE_FRONT); } picker_window->popup(); @@ -1544,7 +1546,7 @@ void ColorPicker::_pick_button_pressed_legacy() { picker_texture_rect->set_anchors_preset(Control::PRESET_FULL_RECT); picker_window->add_child(picker_texture_rect); picker_texture_rect->set_default_cursor_shape(CURSOR_POINTING_HAND); - picker_texture_rect->connect("gui_input", callable_mp(this, &ColorPicker::_picker_texture_input)); + picker_texture_rect->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_picker_texture_input)); picker_preview = memnew(Panel); picker_preview->set_anchors_preset(Control::PRESET_CENTER_TOP); @@ -1821,11 +1823,11 @@ ColorPicker::ColorPicker() { uv_edit = memnew(Control); hb_edit->add_child(uv_edit); - uv_edit->connect("gui_input", callable_mp(this, &ColorPicker::_uv_input).bind(uv_edit)); + uv_edit->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_uv_input).bind(uv_edit)); uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_h_size_flags(SIZE_EXPAND_FILL); uv_edit->set_v_size_flags(SIZE_EXPAND_FILL); - uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw).bind(0, uv_edit)); + uv_edit->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_hsv_draw).bind(0, uv_edit)); sample_hbc = memnew(HBoxContainer); real_vbox->add_child(sample_hbc); @@ -1834,18 +1836,18 @@ ColorPicker::ColorPicker() { sample_hbc->add_child(btn_pick); if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SCREEN_CAPTURE)) { btn_pick->set_tooltip_text(ETR("Pick a color from the screen.")); - btn_pick->connect(SNAME("pressed"), callable_mp(this, &ColorPicker::_pick_button_pressed)); + btn_pick->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_pick_button_pressed)); } else { // On unsupported platforms, use a legacy method for color picking. btn_pick->set_tooltip_text(ETR("Pick a color from the application window.")); - btn_pick->connect(SNAME("pressed"), callable_mp(this, &ColorPicker::_pick_button_pressed_legacy)); + btn_pick->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_pick_button_pressed_legacy)); } sample = memnew(TextureRect); sample_hbc->add_child(sample); sample->set_h_size_flags(SIZE_EXPAND_FILL); - sample->connect("gui_input", callable_mp(this, &ColorPicker::_sample_input)); - sample->connect("draw", callable_mp(this, &ColorPicker::_sample_draw)); + sample->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_sample_input)); + sample->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_sample_draw)); btn_shape = memnew(MenuButton); btn_shape->set_flat(false); @@ -1881,7 +1883,7 @@ ColorPicker::ColorPicker() { mode_btns[i]->set_toggle_mode(true); mode_btns[i]->set_text(modes[i]->get_name()); mode_btns[i]->set_button_group(mode_group); - mode_btns[i]->connect("pressed", callable_mp(this, &ColorPicker::set_color_mode).bind((ColorModeType)i)); + mode_btns[i]->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::set_color_mode).bind((ColorModeType)i)); } mode_btns[0]->set_pressed(true); @@ -1934,7 +1936,7 @@ ColorPicker::ColorPicker() { text_type->set_text("#"); text_type->set_tooltip_text(RTR("Switch between hexadecimal and code values.")); if (Engine::get_singleton()->is_editor_hint()) { - text_type->connect("pressed", callable_mp(this, &ColorPicker::_text_type_toggled)); + text_type->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_text_type_toggled)); } else { text_type->set_flat(true); text_type->set_mouse_filter(MOUSE_FILTER_IGNORE); @@ -1948,7 +1950,7 @@ ColorPicker::ColorPicker() { c_text->set_placeholder(ETR("Hex code or named color")); c_text->connect("text_submitted", callable_mp(this, &ColorPicker::_html_submitted)); c_text->connect("text_changed", callable_mp(this, &ColorPicker::_text_changed)); - c_text->connect("focus_exited", callable_mp(this, &ColorPicker::_html_focus_exit)); + c_text->connect(SceneStringName(focus_exited), callable_mp(this, &ColorPicker::_html_focus_exit)); wheel_edit = memnew(AspectRatioContainer); wheel_edit->set_h_size_flags(SIZE_EXPAND_FILL); @@ -1967,19 +1969,19 @@ ColorPicker::ColorPicker() { wheel = memnew(Control); wheel_margin->add_child(wheel); wheel->set_mouse_filter(MOUSE_FILTER_PASS); - wheel->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw).bind(2, wheel)); + wheel->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_hsv_draw).bind(2, wheel)); wheel_uv = memnew(Control); wheel_margin->add_child(wheel_uv); - wheel_uv->connect("gui_input", callable_mp(this, &ColorPicker::_uv_input).bind(wheel_uv)); - wheel_uv->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw).bind(0, wheel_uv)); + wheel_uv->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_uv_input).bind(wheel_uv)); + wheel_uv->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_hsv_draw).bind(0, wheel_uv)); w_edit = memnew(Control); hb_edit->add_child(w_edit); w_edit->set_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); - w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input)); - w_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw).bind(1, w_edit)); + w_edit->connect(SceneStringName(gui_input), callable_mp(this, &ColorPicker::_w_input)); + w_edit->connect(SceneStringName(draw), callable_mp(this, &ColorPicker::_hsv_draw).bind(1, w_edit)); _update_controls(); updating = false; @@ -2024,7 +2026,7 @@ ColorPicker::ColorPicker() { btn_add_preset = memnew(Button); btn_add_preset->set_icon_alignment(HORIZONTAL_ALIGNMENT_CENTER); btn_add_preset->set_tooltip_text(ETR("Add current color as a preset.")); - btn_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed)); + btn_add_preset->connect(SceneStringName(pressed), callable_mp(this, &ColorPicker::_add_preset_pressed)); preset_container->add_child(btn_add_preset); } @@ -2169,7 +2171,7 @@ void ColorPickerButton::_update_picker() { picker->connect("color_changed", callable_mp(this, &ColorPickerButton::_color_changed)); popup->connect("about_to_popup", callable_mp(this, &ColorPickerButton::_about_to_popup)); popup->connect("popup_hide", callable_mp(this, &ColorPickerButton::_modal_closed)); - picker->connect("minimum_size_changed", callable_mp((Window *)popup, &Window::reset_size)); + picker->connect(SceneStringName(minimum_size_changed), callable_mp((Window *)popup, &Window::reset_size)); picker->set_pick_color(color); picker->set_edit_alpha(edit_alpha); picker->set_display_old_color(true); diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index c6e66c95c6..f1faf3e899 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -30,8 +30,6 @@ #include "container.h" -#include "scene/scene_string_names.h" - void Container::_child_minsize_changed() { update_minimum_size(); queue_sort(); @@ -45,9 +43,9 @@ void Container::add_child_notify(Node *p_child) { return; } - control->connect(SNAME("size_flags_changed"), callable_mp(this, &Container::queue_sort)); - control->connect(SNAME("minimum_size_changed"), callable_mp(this, &Container::_child_minsize_changed)); - control->connect(SNAME("visibility_changed"), callable_mp(this, &Container::_child_minsize_changed)); + control->connect(SceneStringName(size_flags_changed), callable_mp(this, &Container::queue_sort)); + control->connect(SceneStringName(minimum_size_changed), callable_mp(this, &Container::_child_minsize_changed)); + control->connect(SceneStringName(visibility_changed), callable_mp(this, &Container::_child_minsize_changed)); update_minimum_size(); queue_sort(); @@ -72,9 +70,9 @@ void Container::remove_child_notify(Node *p_child) { return; } - control->disconnect("size_flags_changed", callable_mp(this, &Container::queue_sort)); - control->disconnect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed)); - control->disconnect("visibility_changed", callable_mp(this, &Container::_child_minsize_changed)); + control->disconnect(SceneStringName(size_flags_changed), callable_mp(this, &Container::queue_sort)); + control->disconnect(SceneStringName(minimum_size_changed), callable_mp(this, &Container::_child_minsize_changed)); + control->disconnect(SceneStringName(visibility_changed), callable_mp(this, &Container::_child_minsize_changed)); update_minimum_size(); queue_sort(); @@ -86,10 +84,10 @@ void Container::_sort_children() { } notification(NOTIFICATION_PRE_SORT_CHILDREN); - emit_signal(SceneStringNames::get_singleton()->pre_sort_children); + emit_signal(SceneStringName(pre_sort_children)); notification(NOTIFICATION_SORT_CHILDREN); - emit_signal(SceneStringNames::get_singleton()->sort_children); + emit_signal(SceneStringName(sort_children)); pending_sort = false; } @@ -141,6 +139,14 @@ void Container::queue_sort() { pending_sort = true; } +Control *Container::as_sortable_control(Node *p_node) const { + Control *c = Object::cast_to<Control>(p_node); + if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { + return nullptr; + } + return c; +} + Vector<int> Container::get_allowed_size_flags_horizontal() const { Vector<int> flags; if (GDVIRTUAL_CALL(_get_allowed_size_flags_horizontal, flags)) { diff --git a/scene/gui/container.h b/scene/gui/container.h index 94c3c540d7..405220cee6 100644 --- a/scene/gui/container.h +++ b/scene/gui/container.h @@ -42,6 +42,8 @@ class Container : public Control { protected: void queue_sort(); + Control *as_sortable_control(Node *p_node) const; + virtual void add_child_notify(Node *p_child) override; virtual void move_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 7ac7ceb6bc..1c175f9f95 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -42,7 +42,6 @@ #include "scene/gui/panel.h" #include "scene/main/canvas_layer.h" #include "scene/main/window.h" -#include "scene/scene_string_names.h" #include "scene/theme/theme_db.h" #include "scene/theme/theme_owner.h" #include "servers/rendering_server.h" @@ -208,28 +207,42 @@ void Control::set_root_layout_direction(int p_root_dir) { #ifdef TOOLS_ENABLED void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { ERR_READ_THREAD_GUARD; - CanvasItem::get_argument_options(p_function, p_idx, r_options); - if (p_idx == 0) { - List<StringName> sn; const String pf = p_function; + Theme::DataType type = Theme::DATA_TYPE_MAX; + if (pf == "add_theme_color_override" || pf == "has_theme_color" || pf == "has_theme_color_override" || pf == "get_theme_color") { - ThemeDB::get_singleton()->get_default_theme()->get_color_list(get_class(), &sn); - } else if (pf == "add_theme_style_override" || pf == "has_theme_style" || pf == "has_theme_style_override" || pf == "get_theme_style") { - ThemeDB::get_singleton()->get_default_theme()->get_stylebox_list(get_class(), &sn); + type = Theme::DATA_TYPE_COLOR; + } else if (pf == "add_theme_constant_override" || pf == "has_theme_constant" || pf == "has_theme_constant_override" || pf == "get_theme_constant") { + type = Theme::DATA_TYPE_CONSTANT; } else if (pf == "add_theme_font_override" || pf == "has_theme_font" || pf == "has_theme_font_override" || pf == "get_theme_font") { - ThemeDB::get_singleton()->get_default_theme()->get_font_list(get_class(), &sn); + type = Theme::DATA_TYPE_FONT; } else if (pf == "add_theme_font_size_override" || pf == "has_theme_font_size" || pf == "has_theme_font_size_override" || pf == "get_theme_font_size") { - ThemeDB::get_singleton()->get_default_theme()->get_font_size_list(get_class(), &sn); - } else if (pf == "add_theme_constant_override" || pf == "has_theme_constant" || pf == "has_theme_constant_override" || pf == "get_theme_constant") { - ThemeDB::get_singleton()->get_default_theme()->get_constant_list(get_class(), &sn); + type = Theme::DATA_TYPE_FONT_SIZE; + } else if (pf == "add_theme_icon_override" || pf == "has_theme_icon" || pf == "has_theme_icon_override" || pf == "get_theme_icon") { + type = Theme::DATA_TYPE_ICON; + } else if (pf == "add_theme_style_override" || pf == "has_theme_style" || pf == "has_theme_style_override" || pf == "get_theme_style") { + type = Theme::DATA_TYPE_STYLEBOX; } - sn.sort_custom<StringName::AlphCompare>(); - for (const StringName &name : sn) { - r_options->push_back(String(name).quote()); + if (type != Theme::DATA_TYPE_MAX) { + List<ThemeDB::ThemeItemBind> theme_items; + ThemeDB::get_singleton()->get_class_items(get_class_name(), &theme_items, true, type); + + List<StringName> sn; + for (const ThemeDB::ThemeItemBind &E : theme_items) { + if (E.data_type == type) { + sn.push_back(E.item_name); + } + } + + sn.sort_custom<StringName::AlphCompare>(); + for (const StringName &name : sn) { + r_options->push_back(String(name).quote()); + } } } + CanvasItem::get_argument_options(p_function, p_idx, r_options); } #endif @@ -1383,6 +1396,15 @@ void Control::_set_position(const Point2 &p_point) { void Control::set_position(const Point2 &p_point, bool p_keep_offsets) { ERR_MAIN_THREAD_GUARD; + +#ifdef TOOLS_ENABLED + // Can't compute anchors, set position directly and return immediately. + if (saving && !is_inside_tree()) { + data.pos_cache = p_point; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor); } else { @@ -1441,6 +1463,14 @@ void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { new_size.y = min.y; } +#ifdef TOOLS_ENABLED + // Can't compute anchors, set size directly and return immediately. + if (saving && !is_inside_tree()) { + data.size_cache = new_size; + return; + } +#endif + if (p_keep_offsets) { _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor); } else { @@ -1575,7 +1605,7 @@ void Control::_update_minimum_size() { if (minsize != data.last_minimum_size) { data.last_minimum_size = minsize; _size_changed(); - emit_signal(SceneStringNames::get_singleton()->minimum_size_changed); + emit_signal(SceneStringName(minimum_size_changed)); } } @@ -1739,7 +1769,7 @@ void Control::set_h_size_flags(BitField<SizeFlags> p_flags) { return; } data.h_size_flags = p_flags; - emit_signal(SceneStringNames::get_singleton()->size_flags_changed); + emit_signal(SceneStringName(size_flags_changed)); } BitField<Control::SizeFlags> Control::get_h_size_flags() const { @@ -1753,7 +1783,7 @@ void Control::set_v_size_flags(BitField<SizeFlags> p_flags) { return; } data.v_size_flags = p_flags; - emit_signal(SceneStringNames::get_singleton()->size_flags_changed); + emit_signal(SceneStringName(size_flags_changed)); } BitField<Control::SizeFlags> Control::get_v_size_flags() const { @@ -1768,7 +1798,7 @@ void Control::set_stretch_ratio(real_t p_ratio) { } data.expand = p_ratio; - emit_signal(SceneStringNames::get_singleton()->size_flags_changed); + emit_signal(SceneStringName(size_flags_changed)); } real_t Control::get_stretch_ratio() const { @@ -1780,7 +1810,7 @@ real_t Control::get_stretch_ratio() const { void Control::_call_gui_input(const Ref<InputEvent> &p_event) { if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) { - emit_signal(SceneStringNames::get_singleton()->gui_input, p_event); // Signal should be first, so it's possible to override an event (and then accept it). + emit_signal(SceneStringName(gui_input), p_event); // Signal should be first, so it's possible to override an event (and then accept it). } if (!is_inside_tree() || get_viewport()->is_input_handled()) { return; // Input was handled, abort. @@ -3140,6 +3170,14 @@ Control *Control::make_custom_tooltip(const String &p_text) const { void Control::_notification(int p_notification) { ERR_MAIN_THREAD_GUARD; switch (p_notification) { +#ifdef TOOLS_ENABLED + case NOTIFICATION_EDITOR_PRE_SAVE: { + saving = true; + } break; + case NOTIFICATION_EDITOR_POST_SAVE: { + saving = false; + } break; +#endif case NOTIFICATION_POSTINITIALIZE: { data.initialized = true; @@ -3184,7 +3222,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_READY: { #ifdef DEBUG_ENABLED - connect("ready", callable_mp(this, &Control::_clear_size_warning), CONNECT_DEFERRED | CONNECT_ONE_SHOT); + connect(SceneStringName(ready), callable_mp(this, &Control::_clear_size_warning), CONNECT_DEFERRED | CONNECT_ONE_SHOT); #endif } break; @@ -3223,7 +3261,7 @@ void Control::_notification(int p_notification) { data.parent_canvas_item = get_parent_item(); if (data.parent_canvas_item) { - data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); + data.parent_canvas_item->connect(SceneStringName(item_rect_changed), callable_mp(this, &Control::_size_changed)); } else { // Connect viewport. Viewport *viewport = get_viewport(); @@ -3234,7 +3272,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_EXIT_CANVAS: { if (data.parent_canvas_item) { - data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed)); + data.parent_canvas_item->disconnect(SceneStringName(item_rect_changed), callable_mp(this, &Control::_size_changed)); data.parent_canvas_item = nullptr; } else { // Disconnect viewport. @@ -3260,7 +3298,7 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_RESIZED: { - emit_signal(SceneStringNames::get_singleton()->resized); + emit_signal(SceneStringName(resized)); } break; case NOTIFICATION_DRAW: { @@ -3270,25 +3308,25 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_MOUSE_ENTER: { - emit_signal(SceneStringNames::get_singleton()->mouse_entered); + emit_signal(SceneStringName(mouse_entered)); } break; case NOTIFICATION_MOUSE_EXIT: { - emit_signal(SceneStringNames::get_singleton()->mouse_exited); + emit_signal(SceneStringName(mouse_exited)); } break; case NOTIFICATION_FOCUS_ENTER: { - emit_signal(SceneStringNames::get_singleton()->focus_entered); + emit_signal(SceneStringName(focus_entered)); queue_redraw(); } break; case NOTIFICATION_FOCUS_EXIT: { - emit_signal(SceneStringNames::get_singleton()->focus_exited); + emit_signal(SceneStringName(focus_exited)); queue_redraw(); } break; case NOTIFICATION_THEME_CHANGED: { - emit_signal(SceneStringNames::get_singleton()->theme_changed); + emit_signal(SceneStringName(theme_changed)); _invalidate_theme_cache(); _update_theme_item_cache(); diff --git a/scene/gui/control.h b/scene/gui/control.h index bdb908e089..c784d4330d 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -47,6 +47,10 @@ class ThemeContext; class Control : public CanvasItem { GDCLASS(Control, CanvasItem); +#ifdef TOOLS_ENABLED + bool saving = false; +#endif + public: enum Anchor { ANCHOR_BEGIN = 0, diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 4d2080dda2..58961d370c 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -68,11 +68,11 @@ void AcceptDialog::_notification(int p_what) { parent_visible = get_parent_visible_window(); if (parent_visible) { - parent_visible->connect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->connect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); } } else { if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } } @@ -89,7 +89,7 @@ void AcceptDialog::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } } break; @@ -126,7 +126,7 @@ void AcceptDialog::_ok_pressed() { void AcceptDialog::_cancel_pressed() { Window *parent_window = parent_visible; if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } @@ -308,7 +308,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } button->set_meta("__right_spacer", right_spacer); - button->connect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed).bind(button)); + button->connect(SceneStringName(visibility_changed), callable_mp(this, &AcceptDialog::_custom_button_visibility_changed).bind(button)); child_controls_changed(); if (is_visible()) { @@ -316,7 +316,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } if (!p_action.is_empty()) { - button->connect("pressed", callable_mp(this, &AcceptDialog::_custom_action).bind(p_action)); + button->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action).bind(p_action)); } return button; @@ -330,7 +330,7 @@ Button *AcceptDialog::add_cancel_button(const String &p_cancel) { Button *b = swap_cancel_ok ? add_button(c, true) : add_button(c); - b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); + b->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed)); return b; } @@ -345,12 +345,12 @@ void AcceptDialog::remove_button(Button *p_button) { ERR_FAIL_COND_MSG(right_spacer->get_parent() != buttons_hbox, vformat("Cannot remove button %s as its associated spacer does not belong to this dialog.", p_button->get_name())); } - p_button->disconnect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed)); - if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_custom_action))) { - p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_custom_action)); + p_button->disconnect(SceneStringName(visibility_changed), callable_mp(this, &AcceptDialog::_custom_button_visibility_changed)); + if (p_button->is_connected(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action))) { + p_button->disconnect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action)); } - if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed))) { - p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); + if (p_button->is_connected(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed))) { + p_button->disconnect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed)); } if (right_spacer) { @@ -433,7 +433,7 @@ AcceptDialog::AcceptDialog() { buttons_hbox->add_child(ok_button); buttons_hbox->add_spacer(); - ok_button->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed)); + ok_button->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_ok_pressed)); set_title(ETR("Alert!")); } diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 97a2917dc1..0c146ce173 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -1344,6 +1344,7 @@ void FileDialog::_bind_methods() { Option defaults; base_property_helper.set_prefix("option_"); + base_property_helper.set_array_length_getter(&FileDialog::get_option_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "name"), defaults.name, &FileDialog::set_option_name, &FileDialog::get_option_name); base_property_helper.register_property(PropertyInfo(Variant::PACKED_STRING_ARRAY, "values"), defaults.values, &FileDialog::set_option_values, &FileDialog::get_option_values); base_property_helper.register_property(PropertyInfo(Variant::INT, "default"), defaults.default_idx, &FileDialog::set_option_default, &FileDialog::get_option_default); @@ -1408,9 +1409,9 @@ FileDialog::FileDialog() { hbc->add_child(dir_prev); hbc->add_child(dir_next); hbc->add_child(dir_up); - dir_prev->connect("pressed", callable_mp(this, &FileDialog::_go_back)); - dir_next->connect("pressed", callable_mp(this, &FileDialog::_go_forward)); - dir_up->connect("pressed", callable_mp(this, &FileDialog::_go_up)); + dir_prev->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_back)); + dir_next->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_forward)); + dir_up->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_go_up)); hbc->add_child(memnew(Label(ETR("Path:")))); @@ -1429,7 +1430,7 @@ FileDialog::FileDialog() { refresh = memnew(Button); refresh->set_theme_type_variation("FlatButton"); refresh->set_tooltip_text(ETR("Refresh files.")); - refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); + refresh->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::update_file_list)); hbc->add_child(refresh); show_hidden = memnew(Button); @@ -1446,7 +1447,7 @@ FileDialog::FileDialog() { makedir = memnew(Button); makedir->set_theme_type_variation("FlatButton"); makedir->set_tooltip_text(ETR("Create a new folder.")); - makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir)); + makedir->connect(SceneStringName(pressed), callable_mp(this, &FileDialog::_make_dir)); hbc->add_child(makedir); vbox->add_child(hbc); diff --git a/scene/gui/flow_container.cpp b/scene/gui/flow_container.cpp index 9f79da2905..ceffd9d103 100644 --- a/scene/gui/flow_container.cpp +++ b/scene/gui/flow_container.cpp @@ -38,6 +38,7 @@ struct _LineData { int min_line_length = 0; int stretch_avail = 0; float stretch_ratio_total = 0; + bool is_filled = false; }; void FlowContainer::_resort() { @@ -58,14 +59,12 @@ void FlowContainer::_resort() { float line_stretch_ratio_total = 0; int current_container_size = vertical ? get_rect().size.y : get_rect().size.x; int children_in_current_line = 0; + Control *last_child = nullptr; // First pass for line wrapping and minimum size calculation. for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to<Control>(get_child(i)); - if (!child || !child->is_visible()) { - continue; - } - if (child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } @@ -77,7 +76,7 @@ void FlowContainer::_resort() { } if (ofs.y + child_msc.y > current_container_size) { line_length = ofs.y - theme_cache.v_separation; - lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total }); + lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total, true }); // Move in new column (vertical line). ofs.x += line_height + theme_cache.h_separation; @@ -99,7 +98,7 @@ void FlowContainer::_resort() { } if (ofs.x + child_msc.x > current_container_size) { line_length = ofs.x - theme_cache.h_separation; - lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total }); + lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total, true }); // Move in new line. ofs.y += line_height + theme_cache.v_separation; @@ -116,11 +115,16 @@ void FlowContainer::_resort() { ofs.x += child_msc.x; } + last_child = child; children_minsize_cache[child] = child_msc; children_in_current_line++; } line_length = vertical ? (ofs.y) : (ofs.x); - lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total }); + bool is_filled = false; + if (last_child != nullptr) { + is_filled = vertical ? (ofs.y + last_child->get_combined_minimum_size().y > current_container_size ? true : false) : (ofs.x + last_child->get_combined_minimum_size().x > current_container_size ? true : false); + } + lines_data.push_back(_LineData{ children_in_current_line, line_height, line_length, current_container_size - line_length, line_stretch_ratio_total, is_filled }); // Second pass for in-line expansion and alignment. @@ -131,11 +135,8 @@ void FlowContainer::_resort() { ofs.y = 0; for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to<Control>(get_child(i)); - if (!child || !child->is_visible()) { - continue; - } - if (child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } Size2i child_size = children_minsize_cache[child]; @@ -158,17 +159,43 @@ void FlowContainer::_resort() { // but only if the line doesn't contain a child that expands. if (child_idx_in_line == 0 && Math::is_equal_approx(line_data.stretch_ratio_total, 0)) { int alignment_ofs = 0; + bool is_not_first_line_and_not_filled = current_line_idx != 0 && !line_data.is_filled; + float prior_stretch_avail = is_not_first_line_and_not_filled ? lines_data[current_line_idx - 1].stretch_avail : 0.0; switch (alignment) { - case ALIGNMENT_CENTER: - alignment_ofs = line_data.stretch_avail / 2; - break; - case ALIGNMENT_END: - alignment_ofs = line_data.stretch_avail; - break; + case ALIGNMENT_BEGIN: { + if (last_wrap_alignment != LAST_WRAP_ALIGNMENT_INHERIT && is_not_first_line_and_not_filled) { + if (last_wrap_alignment == LAST_WRAP_ALIGNMENT_END) { + alignment_ofs = line_data.stretch_avail - prior_stretch_avail; + } else if (last_wrap_alignment == LAST_WRAP_ALIGNMENT_CENTER) { + alignment_ofs = (line_data.stretch_avail - prior_stretch_avail) * 0.5; + } + } + } break; + case ALIGNMENT_CENTER: { + if (last_wrap_alignment != LAST_WRAP_ALIGNMENT_INHERIT && last_wrap_alignment != LAST_WRAP_ALIGNMENT_CENTER && is_not_first_line_and_not_filled) { + if (last_wrap_alignment == LAST_WRAP_ALIGNMENT_END) { + alignment_ofs = line_data.stretch_avail - (prior_stretch_avail * 0.5); + } else { // Is LAST_WRAP_ALIGNMENT_BEGIN + alignment_ofs = prior_stretch_avail * 0.5; + } + } else { + alignment_ofs = line_data.stretch_avail * 0.5; + } + } break; + case ALIGNMENT_END: { + if (last_wrap_alignment != LAST_WRAP_ALIGNMENT_INHERIT && last_wrap_alignment != LAST_WRAP_ALIGNMENT_END && is_not_first_line_and_not_filled) { + if (last_wrap_alignment == LAST_WRAP_ALIGNMENT_BEGIN) { + alignment_ofs = prior_stretch_avail; + } else { // Is LAST_WRAP_ALIGNMENT_CENTER + alignment_ofs = prior_stretch_avail + (line_data.stretch_avail - prior_stretch_avail) * 0.5; + } + } else { + alignment_ofs = line_data.stretch_avail; + } + } break; default: break; } - if (vertical) { /* VERTICAL */ ofs.y += alignment_ofs; } else { /* HORIZONTAL */ @@ -223,17 +250,10 @@ Size2 FlowContainer::get_minimum_size() const { Size2i minimum; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } - - if (!c->is_visible()) { - continue; - } Size2i size = c->get_combined_minimum_size(); @@ -314,6 +334,18 @@ FlowContainer::AlignmentMode FlowContainer::get_alignment() const { return alignment; } +void FlowContainer::set_last_wrap_alignment(LastWrapAlignmentMode p_last_wrap_alignment) { + if (last_wrap_alignment == p_last_wrap_alignment) { + return; + } + last_wrap_alignment = p_last_wrap_alignment; + _resort(); +} + +FlowContainer::LastWrapAlignmentMode FlowContainer::get_last_wrap_alignment() const { + return last_wrap_alignment; +} + void FlowContainer::set_vertical(bool p_vertical) { ERR_FAIL_COND_MSG(is_fixed, "Can't change orientation of " + get_class() + "."); vertical = p_vertical; @@ -346,6 +378,8 @@ void FlowContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_alignment", "alignment"), &FlowContainer::set_alignment); ClassDB::bind_method(D_METHOD("get_alignment"), &FlowContainer::get_alignment); + ClassDB::bind_method(D_METHOD("set_last_wrap_alignment", "last_wrap_alignment"), &FlowContainer::set_last_wrap_alignment); + ClassDB::bind_method(D_METHOD("get_last_wrap_alignment"), &FlowContainer::get_last_wrap_alignment); ClassDB::bind_method(D_METHOD("set_vertical", "vertical"), &FlowContainer::set_vertical); ClassDB::bind_method(D_METHOD("is_vertical"), &FlowContainer::is_vertical); ClassDB::bind_method(D_METHOD("set_reverse_fill", "reverse_fill"), &FlowContainer::set_reverse_fill); @@ -354,8 +388,13 @@ void FlowContainer::_bind_methods() { BIND_ENUM_CONSTANT(ALIGNMENT_BEGIN); BIND_ENUM_CONSTANT(ALIGNMENT_CENTER); BIND_ENUM_CONSTANT(ALIGNMENT_END); + BIND_ENUM_CONSTANT(LAST_WRAP_ALIGNMENT_INHERIT); + BIND_ENUM_CONSTANT(LAST_WRAP_ALIGNMENT_BEGIN); + BIND_ENUM_CONSTANT(LAST_WRAP_ALIGNMENT_CENTER); + BIND_ENUM_CONSTANT(LAST_WRAP_ALIGNMENT_END); ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), "set_alignment", "get_alignment"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "last_wrap_alignment", PROPERTY_HINT_ENUM, "Inherit,Begin,Center,End"), "set_last_wrap_alignment", "get_last_wrap_alignment"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vertical"), "set_vertical", "is_vertical"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reverse_fill"), "set_reverse_fill", "is_reverse_fill"); diff --git a/scene/gui/flow_container.h b/scene/gui/flow_container.h index 90da73aaab..65ebc89c78 100644 --- a/scene/gui/flow_container.h +++ b/scene/gui/flow_container.h @@ -42,6 +42,12 @@ public: ALIGNMENT_CENTER, ALIGNMENT_END }; + enum LastWrapAlignmentMode { + LAST_WRAP_ALIGNMENT_INHERIT, + LAST_WRAP_ALIGNMENT_BEGIN, + LAST_WRAP_ALIGNMENT_CENTER, + LAST_WRAP_ALIGNMENT_END + }; private: int cached_size = 0; @@ -50,6 +56,7 @@ private: bool vertical = false; bool reverse_fill = false; AlignmentMode alignment = ALIGNMENT_BEGIN; + LastWrapAlignmentMode last_wrap_alignment = LAST_WRAP_ALIGNMENT_INHERIT; struct ThemeCache { int h_separation = 0; @@ -71,6 +78,9 @@ public: void set_alignment(AlignmentMode p_alignment); AlignmentMode get_alignment() const; + void set_last_wrap_alignment(LastWrapAlignmentMode p_last_wrap_alignment); + LastWrapAlignmentMode get_last_wrap_alignment() const; + void set_vertical(bool p_vertical); bool is_vertical() const; @@ -102,5 +112,6 @@ public: }; VARIANT_ENUM_CAST(FlowContainer::AlignmentMode); +VARIANT_ENUM_CAST(FlowContainer::LastWrapAlignmentMode); #endif // FLOW_CONTAINER_H diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 646e45b27a..d5ad258df8 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -601,7 +601,7 @@ void GraphEdit::add_child_notify(Node *p_child) { GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element); if (graph_node) { graph_node->connect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated).bind(graph_element)); - graph_node->connect("item_rect_changed", callable_mp(this, &GraphEdit::_graph_node_rect_changed).bind(graph_node)); + graph_node->connect(SceneStringName(item_rect_changed), callable_mp(this, &GraphEdit::_graph_node_rect_changed).bind(graph_node)); _ensure_node_order_from(graph_node); } @@ -618,8 +618,8 @@ void GraphEdit::add_child_notify(Node *p_child) { } graph_element->connect("raise_request", callable_mp(this, &GraphEdit::_ensure_node_order_from).bind(graph_element)); graph_element->connect("resize_request", callable_mp(this, &GraphEdit::_graph_element_resize_request).bind(graph_element)); - graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw)); - graph_element->connect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw)); + graph_element->connect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)connections_layer, &CanvasItem::queue_redraw)); + graph_element->connect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw)); graph_element->set_scale(Vector2(zoom, zoom)); _graph_element_moved(graph_element); @@ -651,7 +651,7 @@ void GraphEdit::remove_child_notify(Node *p_child) { GraphNode *graph_node = Object::cast_to<GraphNode>(graph_element); if (graph_node) { graph_node->disconnect("slot_updated", callable_mp(this, &GraphEdit::_graph_node_slot_updated)); - graph_node->disconnect("item_rect_changed", callable_mp(this, &GraphEdit::_graph_node_rect_changed)); + graph_node->disconnect(SceneStringName(item_rect_changed), callable_mp(this, &GraphEdit::_graph_node_rect_changed)); // Invalidate all adjacent connections, so that they are removed before the next redraw. for (const Ref<Connection> &conn : connection_map[graph_node->get_name()]) { @@ -692,7 +692,7 @@ void GraphEdit::remove_child_notify(Node *p_child) { // In case of the whole GraphEdit being destroyed these references can already be freed. if (minimap != nullptr && minimap->is_inside_tree()) { - graph_element->disconnect("item_rect_changed", callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw)); + graph_element->disconnect(SceneStringName(item_rect_changed), callable_mp((CanvasItem *)minimap, &GraphEditMinimap::queue_redraw)); } } } @@ -1059,7 +1059,7 @@ void GraphEdit::_top_connection_layer_input(const Ref<InputEvent> &p_ev) { port_size.height = MAX(port_size.height, child ? child->get_size().y : 0); int type = graph_node->get_output_port_type(j); - if ((type == connecting_type || + if ((type == connecting_type || graph_node->is_ignoring_valid_connection_type() || valid_connection_types.has(ConnectionType(type, connecting_type))) && is_in_output_hotzone(graph_node, j, mpos, port_size)) { if (!is_node_hover_valid(graph_node->get_name(), j, connecting_from_node, connecting_from_port_index)) { @@ -1084,7 +1084,7 @@ void GraphEdit::_top_connection_layer_input(const Ref<InputEvent> &p_ev) { port_size.height = MAX(port_size.height, child ? child->get_size().y : 0); int type = graph_node->get_input_port_type(j); - if ((type == connecting_type || valid_connection_types.has(ConnectionType(connecting_type, type))) && + if ((type == connecting_type || graph_node->is_ignoring_valid_connection_type() || valid_connection_types.has(ConnectionType(connecting_type, type))) && is_in_input_hotzone(graph_node, j, mpos, port_size)) { if (!is_node_hover_valid(connecting_from_node, connecting_from_port_index, graph_node->get_name(), j)) { continue; @@ -1117,6 +1117,8 @@ void GraphEdit::_top_connection_layer_input(const Ref<InputEvent> &p_ev) { emit_signal(SNAME("connection_from_empty"), connecting_from_node, connecting_from_port_index, mb->get_position()); } } + } else { + set_selected(get_node_or_null(NodePath(connecting_from_node))); } if (connecting) { @@ -1636,12 +1638,12 @@ void GraphEdit::_draw_grid() { void GraphEdit::set_selected(Node *p_child) { for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *graph_node = Object::cast_to<GraphNode>(get_child(i)); - if (!graph_node) { + GraphElement *graph_element = Object::cast_to<GraphElement>(get_child(i)); + if (!graph_element) { continue; } - graph_node->set_selected(graph_node == p_child); + graph_element->set_selected(graph_element == p_child); } } @@ -2755,12 +2757,12 @@ GraphEdit::GraphEdit() { add_child(top_layer, false, INTERNAL_MODE_BACK); top_layer->set_mouse_filter(MOUSE_FILTER_IGNORE); top_layer->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - top_layer->connect("draw", callable_mp(this, &GraphEdit::_top_layer_draw)); - top_layer->connect("focus_exited", callable_mp(panner.ptr(), &ViewPanner::release_pan_key)); + top_layer->connect(SceneStringName(draw), callable_mp(this, &GraphEdit::_top_layer_draw)); + top_layer->connect(SceneStringName(focus_exited), callable_mp(panner.ptr(), &ViewPanner::release_pan_key)); connections_layer = memnew(Control); add_child(connections_layer, false); - connections_layer->connect("draw", callable_mp(this, &GraphEdit::_update_connections)); + connections_layer->connect(SceneStringName(draw), callable_mp(this, &GraphEdit::_update_connections)); connections_layer->set_name("_connection_layer"); connections_layer->set_disable_visibility_clip(true); // Necessary, so it can draw freely and be offset. connections_layer->set_mouse_filter(MOUSE_FILTER_IGNORE); @@ -2772,7 +2774,7 @@ GraphEdit::GraphEdit() { top_connection_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_connection_layer->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); - top_connection_layer->connect("gui_input", callable_mp(this, &GraphEdit::_top_connection_layer_input)); + top_connection_layer->connect(SceneStringName(gui_input), callable_mp(this, &GraphEdit::_top_connection_layer_input)); dragged_connection_line = memnew(Line2D); dragged_connection_line->set_texture_mode(Line2D::LINE_TEXTURE_STRETCH); @@ -2822,7 +2824,7 @@ GraphEdit::GraphEdit() { zoom_minus_button->set_tooltip_text(ETR("Zoom Out")); zoom_minus_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(zoom_minus_button); - zoom_minus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus)); + zoom_minus_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_zoom_minus)); zoom_reset_button = memnew(Button); zoom_reset_button->set_theme_type_variation("FlatButton"); @@ -2830,7 +2832,7 @@ GraphEdit::GraphEdit() { zoom_reset_button->set_tooltip_text(ETR("Zoom Reset")); zoom_reset_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(zoom_reset_button); - zoom_reset_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset)); + zoom_reset_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_zoom_reset)); zoom_plus_button = memnew(Button); zoom_plus_button->set_theme_type_variation("FlatButton"); @@ -2838,7 +2840,7 @@ GraphEdit::GraphEdit() { zoom_plus_button->set_tooltip_text(ETR("Zoom In")); zoom_plus_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(zoom_plus_button); - zoom_plus_button->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus)); + zoom_plus_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_zoom_plus)); // Grid controls. @@ -2850,7 +2852,7 @@ GraphEdit::GraphEdit() { toggle_grid_button->set_tooltip_text(ETR("Toggle the visual grid.")); toggle_grid_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(toggle_grid_button); - toggle_grid_button->connect("pressed", callable_mp(this, &GraphEdit::_show_grid_toggled)); + toggle_grid_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_show_grid_toggled)); toggle_snapping_button = memnew(Button); toggle_snapping_button->set_theme_type_variation("FlatButton"); @@ -2860,7 +2862,7 @@ GraphEdit::GraphEdit() { toggle_snapping_button->set_pressed(snapping_enabled); toggle_snapping_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(toggle_snapping_button); - toggle_snapping_button->connect("pressed", callable_mp(this, &GraphEdit::_snapping_toggled)); + toggle_snapping_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_snapping_toggled)); snapping_distance_spinbox = memnew(SpinBox); snapping_distance_spinbox->set_visible(show_grid_buttons); @@ -2882,12 +2884,12 @@ GraphEdit::GraphEdit() { minimap_button->set_pressed(show_grid); minimap_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(minimap_button); - minimap_button->connect("pressed", callable_mp(this, &GraphEdit::_minimap_toggled)); + minimap_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::_minimap_toggled)); arrange_button = memnew(Button); arrange_button->set_theme_type_variation("FlatButton"); arrange_button->set_visible(show_arrange_button); - arrange_button->connect("pressed", callable_mp(this, &GraphEdit::arrange_nodes)); + arrange_button->connect(SceneStringName(pressed), callable_mp(this, &GraphEdit::arrange_nodes)); arrange_button->set_focus_mode(FOCUS_NONE); menu_hbox->add_child(arrange_button); arrange_button->set_tooltip_text(ETR("Automatically arrange selected nodes.")); @@ -2909,7 +2911,7 @@ GraphEdit::GraphEdit() { minimap->set_offset(Side::SIDE_TOP, -minimap_size.height - MINIMAP_OFFSET); minimap->set_offset(Side::SIDE_RIGHT, -MINIMAP_OFFSET); minimap->set_offset(Side::SIDE_BOTTOM, -MINIMAP_OFFSET); - minimap->connect("draw", callable_mp(this, &GraphEdit::_minimap_draw)); + minimap->connect(SceneStringName(draw), callable_mp(this, &GraphEdit::_minimap_draw)); set_clip_contents(true); diff --git a/scene/gui/graph_element.cpp b/scene/gui/graph_element.cpp index 9c13a3ad9e..e231b05d7f 100644 --- a/scene/gui/graph_element.cpp +++ b/scene/gui/graph_element.cpp @@ -49,14 +49,10 @@ void GraphElement::_resort() { Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *child = Object::cast_to<Control>(get_child(i)); - if (!child || !child->is_visible_in_tree()) { - continue; - } - if (child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i)); + if (!child) { continue; } - fit_child_in_rect(child, Rect2(Point2(), size)); } } @@ -65,10 +61,7 @@ Size2 GraphElement::get_minimum_size() const { Size2 minsize; for (int i = 0; i < get_child_count(); i++) { Control *child = Object::cast_to<Control>(get_child(i)); - if (!child) { - continue; - } - if (child->is_set_as_top_level()) { + if (!child || child->is_set_as_top_level()) { continue; } diff --git a/scene/gui/graph_frame.cpp b/scene/gui/graph_frame.cpp index ca9f7e6fcf..8cd7dbbeb5 100644 --- a/scene/gui/graph_frame.cpp +++ b/scene/gui/graph_frame.cpp @@ -160,14 +160,10 @@ void GraphFrame::_resort() { Point2 offset = Point2(sb_panel->get_margin(SIDE_LEFT), sb_panel->get_margin(SIDE_TOP) + titlebar_min_size.height + sb_titlebar->get_minimum_size().height); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - if (!child || !child->is_visible_in_tree()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } - if (child->is_set_as_top_level()) { - continue; - } - fit_child_in_rect(child, Rect2(offset, size)); } } @@ -325,8 +321,8 @@ Size2 GraphFrame::get_minimum_size() const { Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size(); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - if (!child || !child->is_visible() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index d035515b51..d804f83e1c 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -175,9 +175,8 @@ void GraphNode::_resort() { HashMap<Control *, _MinSizeCache> min_size_cache; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -218,8 +217,8 @@ void GraphNode::_resort() { bool refit_successful = true; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -256,8 +255,8 @@ void GraphNode::_resort() { int width = new_size.width - sb_panel->get_minimum_size().width; int valid_children_idx = 0; for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -605,6 +604,14 @@ void GraphNode::set_slot_draw_stylebox(int p_slot_index, bool p_enable) { emit_signal(SNAME("slot_updated"), p_slot_index); } +void GraphNode::set_ignore_invalid_connection_type(bool p_ignore) { + ignore_invalid_connection_type = p_ignore; +} + +bool GraphNode::is_ignoring_valid_connection_type() const { + return ignore_invalid_connection_type; +} + Size2 GraphNode::get_minimum_size() const { Ref<StyleBox> sb_panel = theme_cache.panel; Ref<StyleBox> sb_titlebar = theme_cache.titlebar; @@ -614,8 +621,8 @@ Size2 GraphNode::get_minimum_size() const { Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size(); for (int i = 0; i < get_child_count(false); i++) { - Control *child = Object::cast_to<Control>(get_child(i, false)); - if (!child || !child->is_visible() || child->is_set_as_top_level()) { + Control *child = as_sortable_control(get_child(i, false)); + if (!child) { continue; } @@ -860,6 +867,9 @@ void GraphNode::_bind_methods() { ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox); ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox); + ClassDB::bind_method(D_METHOD("set_ignore_invalid_connection_type", "ignore"), &GraphNode::set_ignore_invalid_connection_type); + ClassDB::bind_method(D_METHOD("is_ignoring_valid_connection_type"), &GraphNode::is_ignoring_valid_connection_type); + ClassDB::bind_method(D_METHOD("get_input_port_count"), &GraphNode::get_input_port_count); ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position); ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type); @@ -875,6 +885,8 @@ void GraphNode::_bind_methods() { GDVIRTUAL_BIND(_draw_port, "slot_index", "position", "left", "color") ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type"); + ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index"))); BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel); diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index 71cc322baa..27af3192c8 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -95,6 +95,8 @@ class GraphNode : public GraphElement { bool port_pos_dirty = true; + bool ignore_invalid_connection_type = false; + void _port_pos_update(); protected: @@ -147,6 +149,9 @@ public: bool is_slot_draw_stylebox(int p_slot_index) const; void set_slot_draw_stylebox(int p_slot_index, bool p_enable); + void set_ignore_invalid_connection_type(bool p_ignore); + bool is_ignoring_valid_connection_type() const; + int get_input_port_count(); Vector2 get_input_port_position(int p_port_idx); int get_input_port_type(int p_port_idx); diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index a4baf3bb8d..a67bba786b 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -44,11 +44,8 @@ void GridContainer::_notification(int p_what) { // Compute the per-column/per-row data. int valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -186,8 +183,8 @@ void GridContainer::_notification(int p_what) { valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } int row = valid_controls_index / columns; @@ -282,8 +279,8 @@ Size2 GridContainer::get_minimum_size() const { int valid_controls_index = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } int row = valid_controls_index / columns; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 8376ef48b6..cfb46aebc8 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1882,6 +1882,7 @@ void ItemList::_bind_methods() { Item defaults(true); base_property_helper.set_prefix("item_"); + base_property_helper.set_array_length_getter(&ItemList::get_item_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "text"), defaults.text, &ItemList::set_item_text, &ItemList::get_item_text); base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &ItemList::set_item_icon, &ItemList::get_item_icon); base_property_helper.register_property(PropertyInfo(Variant::BOOL, "selectable"), defaults.selectable, &ItemList::set_item_selectable, &ItemList::is_item_selectable); @@ -1893,7 +1894,7 @@ ItemList::ItemList() { add_child(scroll_bar, false, INTERNAL_MODE_FRONT); scroll_bar->connect("value_changed", callable_mp(this, &ItemList::_scroll_changed)); - connect("mouse_exited", callable_mp(this, &ItemList::_mouse_exited)); + connect(SceneStringName(mouse_exited), callable_mp(this, &ItemList::_mouse_exited)); set_focus_mode(FOCUS_ALL); set_clip_contents(true); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ddfe202c13..729e219825 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1805,7 +1805,6 @@ void LineEdit::clear_internal() { } Size2 LineEdit::get_minimum_size() const { - Ref<StyleBox> style = theme_cache.normal; Ref<Font> font = theme_cache.font; int font_size = theme_cache.font_size; @@ -1834,7 +1833,8 @@ Size2 LineEdit::get_minimum_size() const { } min_size.width += icon_max_width; - return style->get_minimum_size() + min_size; + Size2 style_min_size = theme_cache.normal->get_minimum_size().max(theme_cache.read_only->get_minimum_size()); + return style_min_size + min_size; } void LineEdit::deselect() { @@ -2473,8 +2473,8 @@ void LineEdit::_generate_context_menu() { menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); - menu->connect(SNAME("focus_entered"), callable_mp(this, &LineEdit::_validate_caret_can_draw)); - menu->connect(SNAME("focus_exited"), callable_mp(this, &LineEdit::_validate_caret_can_draw)); + menu->connect(SceneStringName(focus_entered), callable_mp(this, &LineEdit::_validate_caret_can_draw)); + menu->connect(SceneStringName(focus_exited), callable_mp(this, &LineEdit::_validate_caret_can_draw)); } void LineEdit::_update_context_menu() { diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 6d331afbb5..06e4a7cc13 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -37,13 +37,7 @@ Size2 MarginContainer::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) { - continue; - } - if (c->is_set_as_top_level()) { - continue; - } - if (!c->is_visible()) { + if (!c || !c->is_visible() || c->is_set_as_top_level()) { continue; } @@ -103,13 +97,10 @@ void MarginContainer::_notification(int p_what) { Size2 s = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } int w = s.width - theme_cache.margin_left - theme_cache.margin_right; int h = s.height - theme_cache.margin_top - theme_cache.margin_bottom; diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index e83d9c7c1b..998f99b2f9 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -190,6 +190,7 @@ void MenuButton::_bind_methods() { PopupMenu::Item defaults(true); base_property_helper.set_prefix("popup/item_"); + base_property_helper.set_array_length_getter(&MenuButton::get_item_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "text"), defaults.text); base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon); base_property_helper.register_property(PropertyInfo(Variant::INT, "checkable", PROPERTY_HINT_ENUM, "No,As Checkbox,As Radio Button"), defaults.checkable_type); diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp index e2ae824e60..f9181d2a2d 100644 --- a/scene/gui/nine_patch_rect.cpp +++ b/scene/gui/nine_patch_rect.cpp @@ -30,7 +30,6 @@ #include "nine_patch_rect.h" -#include "scene/scene_string_names.h" #include "servers/rendering_server.h" void NinePatchRect::_notification(int p_what) { @@ -111,7 +110,7 @@ void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) { queue_redraw(); update_minimum_size(); - emit_signal(SceneStringNames::get_singleton()->texture_changed); + emit_signal(SceneStringName(texture_changed)); } Ref<Texture2D> NinePatchRect::get_texture() const { diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 509c6aca99..0f161a014a 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -571,6 +571,7 @@ void OptionButton::_bind_methods() { PopupMenu::Item defaults(true); base_property_helper.set_prefix("popup/item_"); + base_property_helper.set_array_length_getter(&OptionButton::get_item_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "text"), defaults.text, &OptionButton::_dummy_setter, &OptionButton::get_item_text); base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &OptionButton::_dummy_setter, &OptionButton::get_item_icon); base_property_helper.register_property(PropertyInfo(Variant::INT, "id", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), defaults.id, &OptionButton::_dummy_setter, &OptionButton::get_item_id); diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index ef85919859..76fde26b26 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -35,11 +35,8 @@ Size2 PanelContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } @@ -87,11 +84,8 @@ void PanelContainer::_notification(int p_what) { } for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible_in_tree()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 87383283fd..1d45a10d2a 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -51,8 +51,8 @@ void Popup::_initialize_visible_parents() { parent_window = parent_window->get_parent_visible_window(); if (parent_window) { visible_parents.push_back(parent_window); - parent_window->connect("focus_entered", callable_mp(this, &Popup::_parent_focused)); - parent_window->connect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents)); + parent_window->connect(SceneStringName(focus_entered), callable_mp(this, &Popup::_parent_focused)); + parent_window->connect(SceneStringName(tree_exited), callable_mp(this, &Popup::_deinitialize_visible_parents)); } } } @@ -61,8 +61,8 @@ void Popup::_initialize_visible_parents() { void Popup::_deinitialize_visible_parents() { if (is_embedded()) { for (Window *parent_window : visible_parents) { - parent_window->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); - parent_window->disconnect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents)); + parent_window->disconnect(SceneStringName(focus_entered), callable_mp(this, &Popup::_parent_focused)); + parent_window->disconnect(SceneStringName(tree_exited), callable_mp(this, &Popup::_deinitialize_visible_parents)); } visible_parents.clear(); @@ -77,6 +77,9 @@ void Popup::_notification(int p_what) { _initialize_visible_parents(); } else { _deinitialize_visible_parents(); + if (hide_reason == HIDE_REASON_NONE) { + hide_reason = HIDE_REASON_CANCELED; + } emit_signal(SNAME("popup_hide")); popped_up = false; } @@ -87,6 +90,7 @@ void Popup::_notification(int p_what) { if (!is_in_edited_scene_root()) { if (has_focus()) { popped_up = true; + hide_reason = HIDE_REASON_NONE; } } } break; @@ -100,6 +104,7 @@ void Popup::_notification(int p_what) { case NOTIFICATION_WM_CLOSE_REQUEST: { if (!is_in_edited_scene_root()) { + hide_reason = HIDE_REASON_UNFOCUSED; _close_pressed(); } } break; @@ -114,6 +119,7 @@ void Popup::_notification(int p_what) { void Popup::_parent_focused() { if (popped_up && get_flag(FLAG_POPUP)) { + hide_reason = HIDE_REASON_UNFOCUSED; _close_pressed(); } } diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 48818686f7..69a81ad98c 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -43,6 +43,16 @@ class Popup : public Window { LocalVector<Window *> visible_parents; bool popped_up = false; +public: + enum HideReason { + HIDE_REASON_NONE, + HIDE_REASON_CANCELED, // E.g., because of rupture of UI flow (app unfocused). Includes closed programmatically. + HIDE_REASON_UNFOCUSED, // E.g., user clicked outside. + }; + +private: + HideReason hide_reason = HIDE_REASON_NONE; + void _initialize_visible_parents(); void _deinitialize_visible_parents(); @@ -60,6 +70,8 @@ protected: virtual void _post_popup() override; public: + HideReason get_hide_reason() const { return hide_reason; } + Popup(); ~Popup(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 9b991972be..dbf1137bd6 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -2808,6 +2808,7 @@ void PopupMenu::_bind_methods() { Item defaults(true); base_property_helper.set_prefix("item_"); + base_property_helper.set_array_length_getter(&PopupMenu::get_item_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "text"), defaults.text, &PopupMenu::set_item_text, &PopupMenu::get_item_text); base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &PopupMenu::set_item_icon, &PopupMenu::get_item_icon); base_property_helper.register_property(PropertyInfo(Variant::INT, "checkable", PROPERTY_HINT_ENUM, "No,As checkbox,As radio button"), defaults.checkable_type, &PopupMenu::_set_item_checkable_type, &PopupMenu::_get_item_checkable_type); @@ -2873,7 +2874,7 @@ PopupMenu::PopupMenu() { control->set_h_size_flags(Control::SIZE_EXPAND_FILL); control->set_v_size_flags(Control::SIZE_EXPAND_FILL); scroll_container->add_child(control, false, INTERNAL_MODE_FRONT); - control->connect("draw", callable_mp(this, &PopupMenu::_draw_items)); + control->connect(SceneStringName(draw), callable_mp(this, &PopupMenu::_draw_items)); submenu_timer = memnew(Timer); submenu_timer->set_wait_time(0.3); diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 236dfcc864..00f4a1089a 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -60,7 +60,7 @@ void Range::Shared::emit_value_changed() { } void Range::_changed_notify(const char *p_what) { - emit_signal(SNAME("changed")); + emit_signal(CoreStringName(changed)); queue_redraw(); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 19b02f33c6..5122b0a155 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -39,7 +39,6 @@ #include "scene/gui/label.h" #include "scene/gui/rich_text_effect.h" #include "scene/resources/atlas_texture.h" -#include "scene/scene_string_names.h" #include "scene/theme/theme_db.h" #include "servers/display_server.h" @@ -2993,7 +2992,7 @@ void RichTextLabel::_process_line_caches() { if (fit_content) { update_minimum_size(); } - emit_signal(SNAME("finished")); + emit_signal(SceneStringName(finished)); } void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) { diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index b35c4e9308..af9f08e389 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -310,15 +310,15 @@ void ScrollBar::_notification(int p_what) { } if (drag_node) { - drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); - drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT); + drag_node->connect(SceneStringName(gui_input), callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->connect(SceneStringName(tree_exiting), callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT); } } break; case NOTIFICATION_EXIT_TREE: { if (drag_node) { - drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); - drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit)); + drag_node->disconnect(SceneStringName(gui_input), callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &ScrollBar::_drag_node_exit)); } drag_node = nullptr; @@ -522,7 +522,7 @@ float ScrollBar::get_custom_step() const { void ScrollBar::_drag_node_exit() { if (drag_node) { - drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->disconnect(SceneStringName(gui_input), callable_mp(this, &ScrollBar::_drag_node_input)); } drag_node = nullptr; } @@ -591,8 +591,8 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { void ScrollBar::set_drag_node(const NodePath &p_path) { if (is_inside_tree()) { if (drag_node) { - drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); - drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit)); + drag_node->disconnect(SceneStringName(gui_input), callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &ScrollBar::_drag_node_exit)); } } @@ -606,8 +606,8 @@ void ScrollBar::set_drag_node(const NodePath &p_path) { } if (drag_node) { - drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); - drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT); + drag_node->connect(SceneStringName(gui_input), callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->connect(SceneStringName(tree_exiting), callable_mp(this, &ScrollBar::_drag_node_exit), CONNECT_ONE_SHOT); } } } diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 4f49f60d70..6f5d0cdcfb 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -43,11 +43,8 @@ Size2 ScrollContainer::get_minimum_size() const { largest_child_min_size = Size2(); for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } if (c == h_scroll || c == v_scroll) { @@ -308,11 +305,8 @@ void ScrollContainer::_reposition_children() { } for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i)); + if (!c) { continue; } if (c == h_scroll || c == v_scroll) { @@ -542,13 +536,10 @@ PackedStringArray ScrollContainer::get_configuration_warnings() const { int found = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); + Control *c = as_sortable_control(get_child(i)); if (!c) { continue; } - if (c->is_set_as_top_level()) { - continue; - } if (c == h_scroll || c == v_scroll) { continue; } diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 70acaf7adf..bfea7b0fbe 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -409,9 +409,9 @@ SpinBox::SpinBox() { line_edit->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); line_edit->connect("text_submitted", callable_mp(this, &SpinBox::_text_submitted), CONNECT_DEFERRED); - line_edit->connect("focus_entered", callable_mp(this, &SpinBox::_line_edit_focus_enter), CONNECT_DEFERRED); - line_edit->connect("focus_exited", callable_mp(this, &SpinBox::_line_edit_focus_exit), CONNECT_DEFERRED); - line_edit->connect("gui_input", callable_mp(this, &SpinBox::_line_edit_input)); + line_edit->connect(SceneStringName(focus_entered), callable_mp(this, &SpinBox::_line_edit_focus_enter), CONNECT_DEFERRED); + line_edit->connect(SceneStringName(focus_exited), callable_mp(this, &SpinBox::_line_edit_focus_exit), CONNECT_DEFERRED); + line_edit->connect(SceneStringName(gui_input), callable_mp(this, &SpinBox::_line_edit_input)); range_click_timer = memnew(Timer); range_click_timer->connect("timeout", callable_mp(this, &SpinBox::_range_click_timeout)); diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 5f4586a6d5..925600756a 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -39,7 +39,7 @@ void SplitContainerDragger::gui_input(const Ref<InputEvent> &p_event) { SplitContainer *sc = Object::cast_to<SplitContainer>(get_parent()); - if (sc->collapsed || !sc->get_containable_child(0) || !sc->get_containable_child(1) || sc->dragger_visibility != SplitContainer::DRAGGER_VISIBLE) { + if (sc->collapsed || !sc->_get_sortable_child(0) || !sc->_get_sortable_child(1) || sc->dragger_visibility != SplitContainer::DRAGGER_VISIBLE) { return; } @@ -122,15 +122,12 @@ void SplitContainerDragger::_notification(int p_what) { } } -Control *SplitContainer::get_containable_child(int p_idx) const { +Control *SplitContainer::_get_sortable_child(int p_idx) const { int idx = 0; for (int i = 0; i < get_child_count(false); i++) { - Control *c = Object::cast_to<Control>(get_child(i, false)); - if (!c || !c->is_visible()) { - continue; - } - if (c->is_set_as_top_level()) { + Control *c = as_sortable_control(get_child(i, false)); + if (!c) { continue; } @@ -157,8 +154,8 @@ Ref<Texture2D> SplitContainer::_get_grabber_icon() const { } void SplitContainer::_compute_middle_sep(bool p_clamp) { - Control *first = get_containable_child(0); - Control *second = get_containable_child(1); + Control *first = _get_sortable_child(0); + Control *second = _get_sortable_child(1); // Determine expanded children. bool first_expanded = (vertical ? first->get_v_size_flags() : first->get_h_size_flags()) & SIZE_EXPAND; @@ -199,8 +196,8 @@ void SplitContainer::_compute_middle_sep(bool p_clamp) { } void SplitContainer::_resort() { - Control *first = get_containable_child(0); - Control *second = get_containable_child(1); + Control *first = _get_sortable_child(0); + Control *second = _get_sortable_child(1); // If we have only one element. if (!first || !second) { @@ -261,7 +258,7 @@ Size2 SplitContainer::get_minimum_size() const { int sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(theme_cache.separation, vertical ? g->get_height() : g->get_width()) : 0; for (int i = 0; i < 2; i++) { - if (!get_containable_child(i)) { + if (!_get_sortable_child(i)) { break; } @@ -273,7 +270,7 @@ Size2 SplitContainer::get_minimum_size() const { } } - Size2 ms = get_containable_child(i)->get_combined_minimum_size(); + Size2 ms = _get_sortable_child(i)->get_combined_minimum_size(); if (vertical) { minimum.height += ms.height; @@ -325,7 +322,7 @@ int SplitContainer::get_split_offset() const { } void SplitContainer::clamp_split_offset() { - if (!get_containable_child(0) || !get_containable_child(1)) { + if (!_get_sortable_child(0) || !_get_sortable_child(1)) { return; } diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index 0f45ef166d..95f26f5e0b 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -82,12 +82,11 @@ private: Ref<Texture2D> _get_grabber_icon() const; void _compute_middle_sep(bool p_clamp); void _resort(); + Control *_get_sortable_child(int p_idx) const; protected: bool is_fixed = false; - Control *get_containable_child(int p_idx) const; - void _notification(int p_what); void _validate_property(PropertyInfo &p_property) const; static void _bind_methods(); diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 0e130d60af..ddc757c452 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -1868,6 +1868,7 @@ void TabBar::_bind_methods() { Tab defaults(true); base_property_helper.set_prefix("tab_"); + base_property_helper.set_array_length_getter(&TabBar::get_tab_count); base_property_helper.register_property(PropertyInfo(Variant::STRING, "title"), defaults.text, &TabBar::set_tab_title, &TabBar::get_tab_title); base_property_helper.register_property(PropertyInfo(Variant::STRING, "tooltip"), defaults.tooltip, &TabBar::set_tab_tooltip, &TabBar::get_tab_tooltip); base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &TabBar::set_tab_icon, &TabBar::get_tab_icon); @@ -1877,7 +1878,7 @@ void TabBar::_bind_methods() { TabBar::TabBar() { set_size(Size2(get_size().width, get_minimum_size().height)); set_focus_mode(FOCUS_ALL); - connect("mouse_exited", callable_mp(this, &TabBar::_on_mouse_exited)); + connect(SceneStringName(mouse_exited), callable_mp(this, &TabBar::_on_mouse_exited)); property_helper.setup_for_instance(base_property_helper, this); } diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index dc53cf82e6..d0c3f3d65e 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -554,7 +554,7 @@ void TabContainer::add_child_notify(Node *p_child) { } p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); - p_child->connect(SNAME("visibility_changed"), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c)); + p_child->connect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c)); // TabBar won't emit the "tab_changed" signal when not inside the tree. if (!is_inside_tree()) { @@ -607,7 +607,7 @@ void TabContainer::remove_child_notify(Node *p_child) { p_child->remove_meta("_tab_index"); p_child->remove_meta("_tab_name"); p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); - p_child->disconnect(SNAME("visibility_changed"), callable_mp(this, &TabContainer::_on_tab_visibility_changed)); + p_child->disconnect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed)); // TabBar won't emit the "tab_changed" signal when not inside the tree. if (!is_inside_tree()) { @@ -1121,5 +1121,5 @@ TabContainer::TabContainer() { tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed)); tab_bar->connect("active_tab_rearranged", callable_mp(this, &TabContainer::_on_active_tab_rearranged)); - connect("mouse_exited", callable_mp(this, &TabContainer::_on_mouse_exited)); + connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_on_mouse_exited)); } diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp index bbe5ddf1c3..dc48945d9b 100644 --- a/scene/gui/texture_progress_bar.cpp +++ b/scene/gui/texture_progress_bar.cpp @@ -526,7 +526,7 @@ void TextureProgressBar::_notification(int p_what) { Vector<Point2> points; for (const float &f : pts) { Point2 uv = unit_val_to_uv(f); - if (uvs.find(uv) >= 0) { + if (uvs.has(uv)) { continue; } points.push_back(progress_offset + Point2(uv.x * s.x, uv.y * s.y)); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 376ace2fe2..133515754b 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2828,7 +2828,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int return -1; } - if (!p_item->disable_folding && !hide_folding && p_item->first_child && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + theme_cache.item_margin))) { + if (!p_item->disable_folding && !hide_folding && p_item->first_child && (p_pos.x < (x_ofs + theme_cache.item_margin))) { if (enable_recursive_folding && p_mod->is_shift_pressed()) { p_item->set_collapsed_recursive(!p_item->is_collapsed()); } else { @@ -3152,9 +3152,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int } void Tree::_text_editor_popup_modal_close() { - if (Input::get_singleton()->is_key_pressed(Key::ESCAPE) || - Input::get_singleton()->is_key_pressed(Key::KP_ENTER) || - Input::get_singleton()->is_key_pressed(Key::ENTER)) { + if (popup_editor->get_hide_reason() == Popup::HIDE_REASON_CANCELED) { return; } @@ -5797,7 +5795,7 @@ Tree::Tree() { h_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); v_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); line_editor->connect("text_submitted", callable_mp(this, &Tree::_line_editor_submit)); - text_editor->connect("gui_input", callable_mp(this, &Tree::_text_editor_gui_input)); + text_editor->connect(SceneStringName(gui_input), callable_mp(this, &Tree::_text_editor_gui_input)); popup_editor->connect("popup_hide", callable_mp(this, &Tree::_text_editor_popup_modal_close)); popup_menu->connect("id_pressed", callable_mp(this, &Tree::popup_select)); value_editor->connect("value_changed", callable_mp(this, &Tree::value_editor_changed)); diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp index 687a9e46a0..0b521f926d 100644 --- a/scene/gui/video_stream_player.cpp +++ b/scene/gui/video_stream_player.cpp @@ -31,7 +31,6 @@ #include "video_stream_player.h" #include "core/os/os.h" -#include "scene/scene_string_names.h" #include "servers/audio_server.h" int VideoStreamPlayer::sp_get_channel_count() const { @@ -163,7 +162,7 @@ void VideoStreamPlayer::_notification(int p_notification) { play(); return; } - emit_signal(SceneStringNames::get_singleton()->finished); + emit_signal(SceneStringName(finished)); } } break; @@ -460,7 +459,7 @@ StringName VideoStreamPlayer::get_bus() const { return bus; } } - return SceneStringNames::get_singleton()->Master; + return SceneStringName(Master); } void VideoStreamPlayer::_validate_property(PropertyInfo &p_property) const { |
