39 lines
		
	
	
		
			894 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			894 B
		
	
	
	
		
			GDScript
		
	
	
	
	
	
| extends SplitContainer
 | |
| 
 | |
| #############
 | |
| # overrides #
 | |
| #############
 | |
| func add_child(child : Node, legible_unique_name := false) -> void:
 | |
| 	.add_child(child, legible_unique_name)
 | |
| 	
 | |
| 	child.connect("tree_exited", self, "_on_child_tree_exited")
 | |
| 
 | |
| #################
 | |
| # private stuff #
 | |
| #################
 | |
| func __try_collapse() -> void:
 | |
| 	var count := get_child_count()
 | |
| 	if count == 0: # nothing left? I can go now
 | |
| 		self.queue_free()
 | |
| 		return
 | |
| 	elif count > 1: # more than one? I have to stay
 | |
| 		return
 | |
| 	
 | |
| 	# exactly one? replace me with them
 | |
| 	var child := get_child(0)
 | |
| 	remove_child(child)
 | |
| 	
 | |
| 	get_parent().add_child_below_node(self, child)
 | |
| 	GDBUIUtility.copy_size(child, self)
 | |
| 	self.queue_free()
 | |
| 
 | |
| ###################
 | |
| # signal handlers #
 | |
| ###################
 | |
| func _on_child_tree_exited() -> void:
 | |
| 	if !get_tree():
 | |
| 		return
 | |
| 	
 | |
| 	yield(get_tree(), "idle_frame") # wait until child is actually gone
 | |
| 	__try_collapse()
 |