From 129bd920bf5979338495ad0e3a10525fac2541ed Mon Sep 17 00:00:00 2001 From: allkhor Date: Thu, 6 Jan 2022 00:23:06 +0600 Subject: [PATCH 1/2] fix: revealer animation folding --- ui/components/Revealer.gd | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ui/components/Revealer.gd b/ui/components/Revealer.gd index d46f4c809..997225ccc 100644 --- a/ui/components/Revealer.gd +++ b/ui/components/Revealer.gd @@ -32,7 +32,6 @@ func _ready() -> void: _button.pressed = is_expanded _button.connect("toggled", self, "set_is_expanded") - _tween.connect("tween_completed", self, "_on_tween_completed") for child in get_children(): if child == _button or not child is Control: @@ -112,12 +111,12 @@ func update_min_size() -> void: var rect_size_x := min(rect_size.x, _parent.rect_size.x) _button.rect_size.x = rect_size_x if use_animations and _tween.is_inside_tree(): - _tween.stop(self, "rect_min_size:y") - _tween.interpolate_property( - self, "rect_min_size:y", rect_min_size.y, _height, ANIM_DURATION - ) + _tween.stop(self) + _animate_height("rect_min_size:y", rect_min_size.y) + _animate_height("rect_size:y", rect_size.y) else: rect_min_size.y = _height + rect_size.y = _height func sort_children() -> void: @@ -142,6 +141,10 @@ func set_text_color(value: Color) -> void: _button.add_color_override("font_color", text_color) +func _animate_height(property: String, from: float) -> void: + _tween.interpolate_property(self, property, from, _height, ANIM_DURATION) + + func _rotate_chevron(rotation_degrees: float, time := ANIM_DURATION) -> void: if not use_animations or not _tween.is_inside_tree(): _chevron.rect_rotation = rotation_degrees @@ -171,10 +174,3 @@ func _fit_child(control: Control, top := 0.0, node_padding := 0.0) -> float: fit_child_in_rect(control, rect) control.rect_size.x = size.x return top + height - - -func _on_tween_completed(object: Object, key: NodePath) -> void: - if object != self or key != ":rect_min_size:y": - return - - rect_size.y = rect_min_size.y From f20b2ec9967e8d822a79a5ff848890660a9731c7 Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Wed, 5 Jan 2022 14:02:27 -0600 Subject: [PATCH 2/2] refactor: simplify code --- ui/components/Revealer.gd | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ui/components/Revealer.gd b/ui/components/Revealer.gd index 997225ccc..f196a8116 100644 --- a/ui/components/Revealer.gd +++ b/ui/components/Revealer.gd @@ -31,13 +31,12 @@ onready var _tween: Tween = $Tween func _ready() -> void: _button.pressed = is_expanded _button.connect("toggled", self, "set_is_expanded") - - + for child in get_children(): if child == _button or not child is Control: continue _add_content_child(child) - + # Through the constructor setter call, the _contents variable will be empty, # so we need to call this again. set_is_expanded(is_expanded) @@ -52,7 +51,7 @@ func add_child(node: Node, _legible_unique_name := false) -> void: .add_child(node) if node is Control: _add_content_child(node) - + set_is_expanded(is_expanded) update_min_size() @@ -60,7 +59,7 @@ func add_child(node: Node, _legible_unique_name := false) -> void: func clear_contents() -> void: for node in _contents: _remove_content_child(node) - + _contents = [] @@ -107,13 +106,15 @@ func set_revealer_height(new_revealer_height: float) -> void: func update_min_size() -> void: if not is_instance_valid(_parent) or _parent == null: return - + var rect_size_x := min(rect_size.x, _parent.rect_size.x) _button.rect_size.x = rect_size_x if use_animations and _tween.is_inside_tree(): _tween.stop(self) - _animate_height("rect_min_size:y", rect_min_size.y) - _animate_height("rect_size:y", rect_size.y) + _tween.interpolate_property( + self, "rect_min_size:y", rect_min_size.y, _height, ANIM_DURATION + ) + _tween.interpolate_property(self, "rect_size:y", rect_size.y, _height, ANIM_DURATION) else: rect_min_size.y = _height rect_size.y = _height @@ -141,15 +142,11 @@ func set_text_color(value: Color) -> void: _button.add_color_override("font_color", text_color) -func _animate_height(property: String, from: float) -> void: - _tween.interpolate_property(self, property, from, _height, ANIM_DURATION) - - func _rotate_chevron(rotation_degrees: float, time := ANIM_DURATION) -> void: if not use_animations or not _tween.is_inside_tree(): _chevron.rect_rotation = rotation_degrees return - + _tween.stop_all() _tween.interpolate_property( _chevron, "rect_rotation", _chevron.rect_rotation, rotation_degrees, time