@@ -23,6 +23,14 @@ signal nonchild_focused
2323 else :
2424 toggled_off .emit ()
2525 toggled .emit (is_toggled )
26+ if not grower :
27+ return
28+ effect_in_progress = true
29+ if is_toggled :
30+ await grower .effect_finished
31+ else :
32+ await grower .shrink_finished
33+ effect_in_progress = false
2634
2735@onready var header_container := $% HeaderContainer as VBoxContainer
2836@onready var label := $% SectionLabel as Label
@@ -32,6 +40,7 @@ signal nonchild_focused
3240@onready var smooth_scroll := $ SmoothScrollEffect as SmoothScrollEffect
3341@onready var grower := $ GrowerEffect as GrowerEffect
3442
43+ var effect_in_progress := false
3544var focus_group : FocusGroup
3645var logger := Log .get_logger ("QBCard" , Log .LEVEL .INFO )
3746
@@ -47,7 +56,6 @@ func _ready() -> void:
4756 var on_focus_exited := func ():
4857 self ._on_unfocus .call_deferred ()
4958 focus_exited .connect (on_focus_exited )
50- focus_entered .connect (_on_focus )
5159 button_up .connect (_on_button_up )
5260 theme_changed .connect (_on_theme_changed )
5361
@@ -139,14 +147,6 @@ func _find_child_focus_group(nodes: Array[Node]) -> FocusGroup:
139147 return null
140148
141149
142- func _on_focus () -> void :
143- # If the card gets focused, and its already expanded, that means we've
144- # the user has focused outside the card, and we should shrink to hide the
145- # content
146- if is_toggled :
147- _on_button_up ()
148-
149-
150150func _on_unfocus () -> void :
151151 # Get the new focus owner
152152 var focus_owner := get_viewport ().gui_get_focus_owner ()
@@ -186,39 +186,42 @@ func _on_focus_change(focused: Control) -> void:
186186
187187func _on_button_up () -> void :
188188 is_toggled = ! is_toggled
189- if is_toggled :
190- toggled_on .emit ()
191- else :
192- toggled_off .emit ()
193-
194- toggled .emit (is_toggled )
195189
196190
197191func _gui_input (event : InputEvent ) -> void :
198- var is_valid := [event is InputEventAction , event is InputEventKey ]
192+ var is_valid := [
193+ event is InputEventAction and event .is_action ("ui_accept" ),
194+ event is InputEventKey and event .is_action ("ui_accept" ),
195+ event is InputEventMouseButton and (event as InputEventMouseButton ).button_index == MOUSE_BUTTON_LEFT ,
196+ ]
199197 if not true in is_valid :
200198 return
201- if event .is_action ("ui_accept" ):
202- if event .is_pressed ():
203- button_down .emit ()
204- pressed .emit ()
205- else :
206- button_up .emit ()
199+ # Mouse input changes focus on button down, which can cause the
200+ # card to toggle off on focus change before the "button_up" event.
201+ # To get around this, ignore mouse events if the grow/shrink effect
202+ # is in progress.
203+ if event is InputEventMouseButton and effect_in_progress :
204+ return
205+ if event .is_pressed ():
206+ button_down .emit ()
207+ pressed .emit ()
208+ else :
209+ button_up .emit ()
207210
208211
209212func _input (event : InputEvent ) -> void :
210213 if not is_toggled :
211214 return
212- if not event .is_action ("ogui_east" ):
215+ var is_valid := [
216+ event .is_action ("ogui_east" ),
217+ event .is_action ("ogui_back" ),
218+ event .is_action ("ui_cancel" )
219+ ]
220+ if not true in is_valid :
213221 return
214222 if not event .is_released ():
215223 return
216224
217- # Only process input if a child node has focus
218- # var focus_owner := get_viewport().gui_get_focus_owner()
219- # if not self.is_ancestor_of(focus_owner):
220- # return
221-
222225 # Handle back input
223226 is_toggled = false
224227
0 commit comments