miggor-StreamGraph/port_drawer.gd

54 lines
957 B
GDScript3
Raw Normal View History

extends HBoxContainer
@onready var left_slot: ColorRect = $LeftSlot
@onready var right_slot: ColorRect = $RightSlot
var text: String
signal button_pressed
func set_input_enabled(enabled: bool) -> void:
left_slot.visible = enabled
func set_output_enabled(enabled: bool) -> void:
right_slot.visible = enabled
func add_label(text: String) -> void:
var l := Label.new()
add_child(l)
l.text = text
move_child(l, 1)
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
func add_field() -> void:
var le := LineEdit.new()
add_child(le)
move_child(le, 1)
le.size_flags_horizontal = Control.SIZE_EXPAND_FILL
le.text_changed.connect(
func(new_text: String):
text = new_text
)
func get_text() -> String:
return text
func add_button(text: String) -> void:
var b := Button.new()
b.text = text
add_child(b)
move_child(b, 1)
b.size_flags_horizontal = Control.SIZE_EXPAND_FILL
b.pressed.connect(
func():
button_pressed.emit()
)