From cd12b1b1b39288b9c67c5908a80888369bd19ae9 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Wed, 11 Jan 2023 19:37:52 +0200 Subject: [PATCH] Animate the collapsible container arrow when the button is clicked --- src/UI/Nodes/CollapsibleContainer.gd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/UI/Nodes/CollapsibleContainer.gd b/src/UI/Nodes/CollapsibleContainer.gd index f25f8c650..edb27742e 100644 --- a/src/UI/Nodes/CollapsibleContainer.gd +++ b/src/UI/Nodes/CollapsibleContainer.gd @@ -5,6 +5,8 @@ extends VBoxContainer export var text := "" setget _set_text export var visible_content := false setget _set_visible_content +onready var texture_rect: TextureRect = $Button/TextureRect + func _ready() -> void: _set_visible($Button.pressed) @@ -29,10 +31,9 @@ func _on_Button_toggled(button_pressed: bool) -> void: func _set_visible(pressed: bool) -> void: - if pressed: - $Button/TextureRect.rect_rotation = 0 - else: - $Button/TextureRect.rect_rotation = -90 + var angle := 0.0 if pressed else -90.0 + var tween := create_tween() + tween.tween_property(texture_rect, "rect_rotation", angle, 0.05) for child in get_children(): if not child is CanvasItem or child == $Button: continue