extends Control

@onready var _items = $Items

signal item_clicked(idx, text)

func _process(delta):
	_process_items_font_size()

func _process_items_font_size():
	var default_font_size = _items.get_theme_default_font_size()
	var font_size = _items.get_theme_font_size("font_size")
	var new_font_size = get_viewport_rect().size.y/30
	if font_size != new_font_size:
		_items.add_theme_font_size_override("font_size", new_font_size)

func _ready():
	_connect_signals()

func _connect_signals():
	_items.item_clicked.connect(_on_item_clicked)

func add_item(text: String):
	_items.add_item(text)

func clear():
	_items.clear()

func select(idx):
	_items.select(idx)

func deselect_all():
	_items.deselect_all()

func _on_item_clicked(index, at_position, mouse_button_index):
	var text = _items.get_item_text(index)
	item_clicked.emit(index, text)
