yagvm/UI/Components/RenameLineEdit.gd

28 lines
647 B
GDScript3
Raw Normal View History

2023-03-05 11:03:08 +00:00
extends LineEdit
class_name RenameLineEdit
signal canceled
func _init(initial_text: String) -> void:
set_text(initial_text)
select_all()
clear_button_enabled = true
text_submitted.connect(queue_free.unbind(1))
# delete self if clicked outside
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton && !(event as InputEventMouseButton).pressed:
if !get_global_rect().has_point((event as InputEventMouseButton).global_position):
canceled.emit()
queue_free()
# delete self if pressed escape
func _gui_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel"):
canceled.emit()
queue_free()