From ac79dbd0e9300e0921fea7908e106f9a37fd3235 Mon Sep 17 00:00:00 2001 From: Mew Pur Pur <85438892+MewPurPur@users.noreply.github.com> Date: Wed, 12 Feb 2025 07:11:01 +0200 Subject: [PATCH] Disable process functions when not used (#1146) --- .github/workflows/export-optimized.yml | 4 ++-- src/ui_parts/display.tscn | 2 +- src/ui_parts/element_container.gd | 11 ++++++++--- src/ui_parts/tab_bar.gd | 16 +++++++++------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/export-optimized.yml b/.github/workflows/export-optimized.yml index a54ae533..444e36b8 100644 --- a/.github/workflows/export-optimized.yml +++ b/.github/workflows/export-optimized.yml @@ -11,11 +11,11 @@ env: # Which godot version to use for exporting. GODOT_VERSION: 4.4 # Which godot release to use for exporting. (stable/rc/beta/alpha) - GODOT_RELEASE: beta1 + GODOT_RELEASE: beta3 # Used in the editor config file name. Do not change this for patch releases. GODOT_FEATURE_VERSION: 4.4 # Commit hash - GODOT_COMMIT_HASH: d33da79d3 + GODOT_COMMIT_HASH: 06acfccf89 PROJECT_NAME: GodSVG GODOT_REPO: https://github.com/godotengine/godot.git BUILD_OPTIONS: target=template_release lto=full production=yes deprecated=no minizip=no brotli=no vulkan=no openxr=no use_volk=no disable_3d=yes modules_enabled_by_default=no module_freetype_enabled=yes module_gdscript_enabled=yes module_svg_enabled=yes module_jpg_enabled=yes module_text_server_adv_enabled=yes graphite=no module_webp_enabled=yes diff --git a/src/ui_parts/display.tscn b/src/ui_parts/display.tscn index 968c995c..116bf88b 100644 --- a/src/ui_parts/display.tscn +++ b/src/ui_parts/display.tscn @@ -116,7 +116,7 @@ unique_name_in_owner = true disable_3d = true handle_input_locally = false gui_snap_controls_to_pixels = false -size = Vector2i(1040, 595) +size = Vector2i(450, 2) size_2d_override_stretch = true render_target_update_mode = 4 script = ExtResource("9_4xrk7") diff --git a/src/ui_parts/element_container.gd b/src/ui_parts/element_container.gd index 02194480..3c54fb8f 100644 --- a/src/ui_parts/element_container.gd +++ b/src/ui_parts/element_container.gd @@ -10,6 +10,11 @@ const autoscroll_speed = 1500.0 func _ready(): State.requested_scroll_to_element_editor.connect(scroll_to_view_element_editor) + set_dragging(false) + +func set_dragging(new_state: bool) -> void: + covering_rect.visible = new_state + set_process(new_state) func _process(delta: float) -> void: if State.proposed_drop_xid.is_empty(): @@ -76,10 +81,10 @@ func update_proposed_xid() -> void: func _notification(what: int) -> void: if is_inside_tree() and HandlerGUI.menu_stack.is_empty(): if what == NOTIFICATION_DRAG_BEGIN: - covering_rect.show() - update_proposed_xid() + set_dragging(true) + update_proposed_xid() elif what == NOTIFICATION_DRAG_END: - covering_rect.hide() + set_dragging(false) State.set_selection_dragged(false) State.clear_proposed_drop_xid() diff --git a/src/ui_parts/tab_bar.gd b/src/ui_parts/tab_bar.gd index 153bf26a..2048b8a5 100644 --- a/src/ui_parts/tab_bar.gd +++ b/src/ui_parts/tab_bar.gd @@ -16,7 +16,7 @@ var scrolling_backwards := false var scrolling_forwards := false var active_controls: Array[Control] = [] -var is_dragging := false +# Processing is enabled only when dragging. var proposed_drop_idx := -1: set(new_value): if proposed_drop_idx != new_value: @@ -36,6 +36,7 @@ func _ready() -> void: Configs.language_changed.connect(queue_redraw) mouse_entered.connect(_on_mouse_entered) mouse_exited.connect(_on_mouse_exited) + set_process(false) func _draw() -> void: var background_stylebox: StyleBoxFlat =\ @@ -225,18 +226,19 @@ func _gui_input(event: InputEvent) -> void: scrolling_backwards = false scrolling_forwards = false +# Autoscroll when the dragged tab is hovered beyond the tabs area. func _process(_delta: float) -> void: var mouse_pos := get_local_mouse_position() var scroll_forwards_area_rect := get_scroll_forwards_area_rect() if ((scrolling_forwards and scroll_forwards_area_rect.has_point(mouse_pos)) or\ - (is_dragging and mouse_pos.x > size.x - get_add_button_rect().size.x -\ + (mouse_pos.x > size.x - get_add_button_rect().size.x -\ scroll_forwards_area_rect.size.x)) and scroll_forwards_area_rect.has_area(): scroll_forwards() return var scroll_backwards_area_rect := get_scroll_backwards_area_rect() if ((scrolling_backwards and scroll_backwards_area_rect.has_point(mouse_pos)) or\ - (is_dragging and mouse_pos.x < scroll_backwards_area_rect.size.x)) and\ + (mouse_pos.x < scroll_backwards_area_rect.size.x)) and\ scroll_backwards_area_rect.has_area(): scroll_backwards() return @@ -461,7 +463,7 @@ func get_drop_index_at(pos: Vector2) -> int: if not tab_rect.has_area() or tab_width * (idx + 0.5) - current_scroll +\ scroll_backwards_button_width > pos.x: return idx - return -1 + return Configs.savedata.get_tab_count() func _get_drag_data(at_position: Vector2) -> Variant: var tab_index_at_position := get_tab_index_at(at_position) @@ -484,7 +486,7 @@ func _get_drag_data(at_position: Vector2) -> Variant: label.size.x = tab_width - 8 set_drag_preview(preview) - is_dragging = true + set_process(true) return TabDropData.new(tab_index_at_position) func _can_drop_data(at_position: Vector2, data: Variant) -> bool: @@ -502,10 +504,10 @@ func _can_drop_data(at_position: Vector2, data: Variant) -> bool: func _drop_data(at_position: Vector2, data: Variant) -> void: if not data is TabDropData: return - is_dragging = false + set_process(false) Configs.savedata.move_tab(data.index, get_drop_index_at(at_position)) func _notification(what: int) -> void: if what == NOTIFICATION_DRAG_END: - is_dragging = false + set_process(false) proposed_drop_idx = -1