27 lines
774 B
GDScript
27 lines
774 B
GDScript
@tool
|
|
extends Container
|
|
class_name PopupContainer
|
|
@export var put_pos:Vector2:
|
|
set(val):
|
|
put_pos=val
|
|
fit_children()
|
|
##对子节点进行适配
|
|
func fit_children()->void:
|
|
for i in get_children():
|
|
if i is Control:
|
|
var mini_size:Vector2=i.get_combined_minimum_size()
|
|
|
|
var real_pos:Vector2=put_pos.clamp(Vector2.ZERO,size)
|
|
var real_size:Vector2=mini_size
|
|
if real_pos.x+mini_size.x>size.x:
|
|
real_pos.x=size.x-mini_size.x
|
|
if real_pos.y+mini_size.y>size.y:
|
|
real_pos.y=size.y-mini_size.y
|
|
real_pos=real_pos.clamp(Vector2.ZERO,size)
|
|
real_size=real_size.clamp(Vector2.ZERO,size)
|
|
var rect:Rect2=Rect2(real_pos,real_size)
|
|
fit_child_in_rect(i,rect)
|
|
func _gui_input(event: InputEvent) -> void:
|
|
if event is InputEventMouseButton:
|
|
self.hide()
|