miggor-StreamGraph/port_drawer.gd

55 lines
1,016 B
GDScript3
Raw Permalink 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
2023-06-10 20:23:57 +02:00
func add_field(placeholder: String = "") -> void:
var le := LineEdit.new()
add_child(le)
move_child(le, 1)
le.size_flags_horizontal = Control.SIZE_EXPAND_FILL
2023-06-10 20:23:57 +02:00
le.placeholder_text = placeholder
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()
)