From dbc57a53af35b1216722e0dbabe099603c0b620a Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sun, 7 Apr 2024 08:24:32 +0800 Subject: [PATCH] Add ability to set default 2D ruler state --- doc/classes/EditorSettings.xml | 3 +++ editor/editor_settings.cpp | 1 + editor/plugins/canvas_item_editor_plugin.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml index 573171b7e1d2..4499c6bb374a 100644 --- a/doc/classes/EditorSettings.xml +++ b/doc/classes/EditorSettings.xml @@ -255,6 +255,9 @@ The guides color to use in the 2D editor. Guides can be created by dragging the mouse cursor from the rulers. + + If [code]true[/code], the 2D editor will show rulers by default. + The color to use when drawing smart snapping lines in the 2D editor. The smart snapping lines will automatically display when moving 2D nodes if smart snapping is enabled in the Snapping Options menu at the top of the 2D editor viewport. diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 32d581a26e91..af1f86aa4c40 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -744,6 +744,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "editors/2d/bone_outline_size", 2.0, "0.01,8,0.01,or_greater") _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4)); _initial_set("editors/2d/use_integer_zoom_by_default", false); + _initial_set("editors/2d/show_rulers_by_default", true); // Panning // Enum should be in sync with ControlScheme in ViewPanner. diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 41e5eee486e5..48744f218de6 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5002,7 +5002,6 @@ void CanvasItemEditor::clear() { view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen. - _update_scrollbars(); grid_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_offset", Vector2()); grid_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "grid_step", Vector2(8, 8)); @@ -5010,6 +5009,12 @@ void CanvasItemEditor::clear() { snap_rotation_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_step", Math::deg_to_rad(15.0)); snap_rotation_offset = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_rotation_offset", 0.0); snap_scale_step = EditorSettings::get_singleton()->get_project_metadata("2d_editor", "snap_scale_step", 0.1); + + show_rulers = EDITOR_GET("editors/2d/show_rulers_by_default"); + int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS); + view_menu->get_popup()->set_item_checked(idx, show_rulers); + + _update_scrollbars(); } void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {