From eabf8f5edf6dc3346bd6a6e771e382f1a20a5c29 Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sat, 20 Nov 2021 11:04:57 +0300 Subject: Added `reset_size` method to `Control` and `Window` classes --- doc/classes/Control.xml | 6 +++++ doc/classes/Window.xml | 6 +++++ editor/connections_dialog.cpp | 2 +- editor/debugger/script_editor_debugger.cpp | 2 +- editor/dependency_editor.cpp | 4 ++-- editor/editor_file_dialog.cpp | 6 ++--- editor/editor_inspector.cpp | 4 ++-- editor/editor_node.cpp | 4 ++-- editor/editor_spin_slider.cpp | 2 +- editor/filesystem_dock.cpp | 8 +++---- editor/import/dynamicfont_import_settings.cpp | 4 ++-- .../plugins/animation_blend_tree_editor_plugin.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 4 ++-- editor/plugins/curve_editor_plugin.cpp | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 4 ++-- editor/plugins/script_editor_plugin.cpp | 2 +- editor/plugins/script_text_editor.cpp | 6 ++--- editor/plugins/shader_editor_plugin.cpp | 2 +- editor/plugins/text_editor.cpp | 2 +- .../plugins/tiles/tile_proxies_manager_dialog.cpp | 2 +- editor/plugins/visual_shader_editor_plugin.cpp | 26 +++++++++++----------- editor/property_editor.cpp | 2 +- editor/scene_tree_dock.cpp | 12 +++++----- .../visual_script/editor/visual_script_editor.cpp | 12 +++++----- scene/gui/control.cpp | 5 +++++ scene/gui/control.h | 1 + scene/gui/line_edit.cpp | 4 ++-- scene/gui/text_edit.cpp | 4 ++-- scene/main/window.cpp | 5 +++++ scene/main/window.h | 1 + 30 files changed, 85 insertions(+), 61 deletions(-) diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index f6bb812070..8abaff741a 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -714,6 +714,12 @@ Removes a local override for a theme [StyleBox] with the specified [code]name[/code] previously added by [method add_theme_stylebox_override] or via the Inspector dock. + + + + Resets the size to [method get_combined_minimum_size]. This is equivalent to calling [code]set_size(Vector2())[/code] (or any size below the minimum). + + diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index f36b926bef..3fee1feae8 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -230,6 +230,12 @@ + + + + Resets the size to the minimum size, which is the max of [member min_size] and (if [member wrap_controls] is enabled) [method get_contents_minimum_size]. This is equivalent to calling [code]set_size(Vector2i())[/code] (or any size below the minimum). + + diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index c773f51342..b954c87476 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -378,7 +378,7 @@ void ConnectDialog::_advanced_pressed() { error_label->hide(); } else { set_min_size(Size2(600, 500) * EDSCALE); - set_size(Size2()); + reset_size(); connect_to_label->set_text(TTR("Connect to Script:")); tree->set_connect_to_script_mode(true); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index e0d32756ca..b18c225f23 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1420,7 +1420,7 @@ void ScriptEditorDebugger::_clear_errors_list() { // Right click on specific file(s) or folder(s). void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) { item_menu->clear(); - item_menu->set_size(Size2(1, 1)); + item_menu->reset_size(); if (error_tree->is_anything_selected()) { item_menu->add_icon_item(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), TTR("Copy Error"), ACTION_COPY_ERROR); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index d07d77c112..f18284638f 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -270,7 +270,7 @@ DependencyEditor::DependencyEditor() { ///////////////////////////////////// void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos) { file_options->clear(); - file_options->set_size(Size2(1, 1)); + file_options->reset_size(); if (p_item >= 0) { file_options->add_item(TTR("Open"), FILE_OPEN); } @@ -464,7 +464,7 @@ void DependencyRemoveDialog::show(const Vector &p_folders, const Vector< if (removed_deps.is_empty()) { owners->hide(); text->set_text(TTR("Remove the selected files from the project? (Cannot be undone.)\nDepending on your filesystem configuration, the files will either be moved to the system trash or deleted permanently.")); - set_size(Size2()); + reset_size(); popup_centered(); } else { _build_removed_dependency_tree(removed_deps); diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 021ab8b93b..2d7c31b64c 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -576,7 +576,7 @@ void EditorFileDialog::_item_dc_selected(int p_item) { void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p_pos) { // Right click on specific file(s) or folder(s). item_menu->clear(); - item_menu->set_size(Size2(1, 1)); + item_menu->reset_size(); // Allow specific actions only on one item. bool single_item_selected = item_list->get_selected_items().size() == 1; @@ -620,7 +620,7 @@ void EditorFileDialog::_item_list_rmb_clicked(const Vector2 &p_pos) { } item_menu->clear(); - item_menu->set_size(Size2(1, 1)); + item_menu->reset_size(); if (can_create_dir) { item_menu->add_icon_item(item_list->get_theme_icon(SNAME("folder"), SNAME("FileDialog")), TTR("New Folder..."), ITEM_MENU_NEW_FOLDER, KeyModifierMask::CMD | Key::N); @@ -1117,7 +1117,7 @@ void EditorFileDialog::_delete_items() { } } if (folders.size() + files.size() > 0) { - remove_dialog->set_size(Size2(1, 1)); + remove_dialog->reset_size(); remove_dialog->show(folders, files); } } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 07e505adb4..2729b1eb3b 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -650,7 +650,7 @@ void EditorProperty::gui_input(const Ref &p_event) { } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) { _update_popup(); menu->set_position(get_screen_position() + get_local_mouse_position()); - menu->set_size(Vector2(1, 1)); + menu->reset_size(); menu->popup(); select(); return; @@ -1556,7 +1556,7 @@ void EditorInspectorArray::_panel_gui_input(Ref p_event, int p_index rmb_popup->set_item_disabled(OPTION_MOVE_UP, popup_array_index_pressed == 0); rmb_popup->set_item_disabled(OPTION_MOVE_DOWN, popup_array_index_pressed == count - 1); rmb_popup->set_position(mb->get_global_position()); - rmb_popup->set_size(Vector2()); + rmb_popup->reset_size(); rmb_popup->popup(); } } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 368b7e6ab3..12142048f0 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4903,7 +4903,7 @@ void EditorNode::_update_layouts_menu() { editor_layouts->clear(); overridden_default_layout = -1; - editor_layouts->set_size(Vector2()); + editor_layouts->reset_size(); editor_layouts->add_shortcut(ED_SHORTCUT("layout/save", TTR("Save Layout")), SETTINGS_LAYOUT_SAVE); editor_layouts->add_shortcut(ED_SHORTCUT("layout/delete", TTR("Delete Layout")), SETTINGS_LAYOUT_DELETE); editor_layouts->add_separator(); @@ -5030,7 +5030,7 @@ void EditorNode::_scene_tab_input(const Ref &p_input) { if (mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) { // context menu scene_tabs_context_menu->clear(); - scene_tabs_context_menu->set_size(Size2(1, 1)); + scene_tabs_context_menu->reset_size(); scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/new_scene"), FILE_NEW_SCENE); if (scene_tabs->get_hovered_tab() >= 0) { diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 2942ece409..f07a5ab523 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -409,7 +409,7 @@ void EditorSpinSlider::_draw_spin_slider() { Vector2 scale = get_global_transform_with_canvas().get_scale(); grabber->set_scale(scale); - grabber->set_size(Size2(0, 0)); + grabber->reset_size(); grabber->set_position(get_global_position() + (grabber_rect.get_center() - grabber->get_size() * 0.5) * scale); if (mousewheel_over_grabber) { diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 1dde157527..7ae3dcd44f 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2507,7 +2507,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { // Popup. if (!paths.is_empty()) { - tree_popup->set_size(Size2(1, 1)); + tree_popup->reset_size(); _file_and_folders_fill_popup(tree_popup, paths); tree_popup->set_position(tree->get_screen_position() + p_pos); tree_popup->popup(); @@ -2518,7 +2518,7 @@ void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) { // Right click is pressed in the empty space of the tree. path = "res://"; tree_popup->clear(); - tree_popup->set_size(Size2(1, 1)); + tree_popup->reset_size(); tree_popup->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("New Folder..."), FILE_NEW_FOLDER); tree_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE); tree_popup->add_icon_item(get_theme_icon(SNAME("Script"), SNAME("EditorIcons")), TTR("New Script..."), FILE_NEW_SCRIPT); @@ -2549,7 +2549,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { // Popup. if (!paths.is_empty()) { file_list_popup->clear(); - file_list_popup->set_size(Size2(1, 1)); + file_list_popup->reset_size(); _file_and_folders_fill_popup(file_list_popup, paths, searched_string.length() == 0); file_list_popup->set_position(files->get_global_position() + p_pos); file_list_popup->popup(); @@ -2563,7 +2563,7 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { } file_list_popup->clear(); - file_list_popup->set_size(Size2(1, 1)); + file_list_popup->reset_size(); file_list_popup->add_icon_item(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons")), TTR("New Folder..."), FILE_NEW_FOLDER); file_list_popup->add_icon_item(get_theme_icon(SNAME("PackedScene"), SNAME("EditorIcons")), TTR("New Scene..."), FILE_NEW_SCENE); diff --git a/editor/import/dynamicfont_import_settings.cpp b/editor/import/dynamicfont_import_settings.cpp index 474c9d5296..45937e20bc 100644 --- a/editor/import/dynamicfont_import_settings.cpp +++ b/editor/import/dynamicfont_import_settings.cpp @@ -1160,7 +1160,7 @@ void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) { void DynamicFontImportSettings::_lang_add() { menu_langs->set_position(lang_list->get_screen_transform().xform(lang_list->get_local_mouse_position())); - menu_langs->set_size(Vector2(1, 1)); + menu_langs->reset_size(); menu_langs->popup(); } @@ -1187,7 +1187,7 @@ void DynamicFontImportSettings::_lang_remove(Object *p_item, int p_column, int p void DynamicFontImportSettings::_script_add() { menu_scripts->set_position(script_list->get_screen_transform().xform(script_list->get_local_mouse_position())); - menu_scripts->set_size(Vector2(1, 1)); + menu_scripts->reset_size(); menu_scripts->popup(); } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 55ffbf9477..2aded41810 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -68,7 +68,7 @@ void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref