Skip to content

Improve zoom performance in Script and Shader editors #106117

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4808,7 +4808,7 @@ void EditorNode::_update_recent_scenes() {
recent_scenes->clear();

if (rc.size() == 0) {
recent_scenes->add_item(TTR("No Recent Scenes"), -1);
recent_scenes->add_item(TTRC("No Recent Scenes"), -1);
recent_scenes->set_item_disabled(-1, true);
} else {
String path;
Expand Down
23 changes: 10 additions & 13 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,8 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col,
CodeTextEditor *cte = se->get_code_editor();
if (cte) {
cte->set_zoom_factor(zoom_factor);
cte->connect("zoomed", callable_mp(this, &ScriptEditor::_set_zoom_factor));
cte->connect("zoomed", callable_mp(this, &ScriptEditor::_set_script_zoom_factor));
cte->connect(SceneStringName(visibility_changed), callable_mp(this, &ScriptEditor::_update_code_editor_zoom_factor).bind(cte));
}

//test for modification, maybe the script was not edited but was loaded
Expand Down Expand Up @@ -3558,7 +3559,7 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
}
}

_set_zoom_factor(p_layout->get_value("ScriptEditor", "zoom_factor", 1.0f));
_set_script_zoom_factor(p_layout->get_value("ScriptEditor", "zoom_factor", 1.0f));

restoring_layout = false;

Expand Down Expand Up @@ -4057,21 +4058,17 @@ void ScriptEditor::_on_find_in_files_modified_files(const PackedStringArray &pat
_update_modified_scripts_for_external_editor();
}

void ScriptEditor::_set_zoom_factor(float p_zoom_factor) {
void ScriptEditor::_set_script_zoom_factor(float p_zoom_factor) {
if (zoom_factor == p_zoom_factor) {
return;
}

zoom_factor = p_zoom_factor;
for (int i = 0; i < tab_container->get_tab_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i));
if (se) {
CodeTextEditor *cte = se->get_code_editor();
if (cte) {
if (zoom_factor != cte->get_zoom_factor()) {
cte->set_zoom_factor(zoom_factor);
}
}
}
}

void ScriptEditor::_update_code_editor_zoom_factor(CodeTextEditor *p_code_text_editor) {
if (p_code_text_editor) {
p_code_text_editor->set_zoom_factor(zoom_factor);
}
}

Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ class ScriptEditor : public PanelContainer {
void _on_find_in_files_modified_files(const PackedStringArray &paths);
void _on_find_in_files_close_button_clicked();

void _set_zoom_factor(float p_zoom_factor);
void _set_script_zoom_factor(float p_zoom_factor);
void _update_code_editor_zoom_factor(CodeTextEditor *p_code_text_editor);

void _window_changed(bool p_visible);

Expand Down
22 changes: 11 additions & 11 deletions editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void ShaderEditorPlugin::edit(Object *p_object) {
if (cte) {
cte->set_zoom_factor(text_shader_zoom_factor);
cte->connect("zoomed", callable_mp(this, &ShaderEditorPlugin::_set_text_shader_zoom_factor));
cte->connect(SceneStringName(visibility_changed), callable_mp(this, &ShaderEditorPlugin::_update_shader_editor_zoom_factor).bind(cte));
}

if (text_shader_editor->get_top_bar()) {
Expand Down Expand Up @@ -768,17 +769,16 @@ void ShaderEditorPlugin::_window_changed(bool p_visible) {
}

void ShaderEditorPlugin::_set_text_shader_zoom_factor(float p_zoom_factor) {
if (text_shader_zoom_factor != p_zoom_factor) {
text_shader_zoom_factor = p_zoom_factor;
for (const EditedShader &edited_shader : edited_shaders) {
TextShaderEditor *text_shader_editor = Object::cast_to<TextShaderEditor>(edited_shader.shader_editor);
if (text_shader_editor) {
CodeTextEditor *cte = text_shader_editor->get_code_editor();
if (cte && cte->get_zoom_factor() != text_shader_zoom_factor) {
cte->set_zoom_factor(text_shader_zoom_factor);
}
}
}
if (text_shader_zoom_factor == p_zoom_factor) {
return;
}

text_shader_zoom_factor = p_zoom_factor;
}

void ShaderEditorPlugin::_update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const {
if (p_shader_editor) {
p_shader_editor->set_zoom_factor(text_shader_zoom_factor);
}
}

Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/shader_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "editor/plugins/editor_plugin.h"

class CodeTextEditor;
class HSplitContainer;
class ItemList;
class MenuButton;
Expand Down Expand Up @@ -125,6 +126,8 @@ class ShaderEditorPlugin : public EditorPlugin {
void _window_changed(bool p_visible);

void _set_text_shader_zoom_factor(float p_zoom_factor);
void _update_shader_editor_zoom_factor(CodeTextEditor *p_shader_editor) const;

void _switch_to_editor(ShaderEditor *p_editor);

protected:
Expand Down