mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
fa5e9997ef
here we go Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/2 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
84 lines
2 KiB
GDScript
84 lines
2 KiB
GDScript
extends VBoxContainer
|
|
class_name TabContainerCustom
|
|
|
|
@onready var tab_bar: TabBar = %TabBar
|
|
@onready var add_tab_button: Button = %Button
|
|
@onready var content_container: MarginContainer = %ContentContainer
|
|
|
|
|
|
signal add_button_pressed
|
|
signal tab_changed(tab: int)
|
|
signal tab_closed(tab: int)
|
|
signal tab_close_requested(tab: int)
|
|
signal tab_rearranged(old: int, new: int)
|
|
|
|
var _previous_active_tab: int = -1
|
|
|
|
|
|
func _ready() -> void:
|
|
tab_bar.tab_selected.connect(
|
|
func(tab: int):
|
|
if _previous_active_tab == tab:
|
|
return
|
|
|
|
if _previous_active_tab > -1:
|
|
content_container.get_child(_previous_active_tab).visible = false
|
|
content_container.get_child(tab).visible = true
|
|
|
|
tab_changed.emit(tab)
|
|
_previous_active_tab = tab
|
|
)
|
|
|
|
tab_bar.tab_close_pressed.connect(func(tab: int): tab_close_requested.emit(tab))
|
|
|
|
add_tab_button.pressed.connect(
|
|
func():
|
|
add_button_pressed.emit()
|
|
)
|
|
|
|
tab_bar.active_tab_rearranged.connect(
|
|
func(idx_to: int):
|
|
tab_rearranged.emit(_previous_active_tab, idx_to)
|
|
content_container.move_child(content_container.get_child(_previous_active_tab), idx_to)
|
|
_previous_active_tab = idx_to
|
|
)
|
|
|
|
|
|
func add_content(c: Node, tab_title: String) -> void:
|
|
tab_bar.add_tab(tab_title)
|
|
content_container.add_child(c)
|
|
tab_bar.set_current_tab(tab_bar.tab_count - 1)
|
|
|
|
|
|
func get_tab_count() -> int:
|
|
return tab_bar.tab_count
|
|
|
|
|
|
func is_empty() -> bool:
|
|
return get_tab_count() == 0
|
|
|
|
|
|
func close_tab(tab: int) -> void:
|
|
content_container.get_child(tab).queue_free()
|
|
if !tab_bar.select_previous_available():
|
|
tab_bar.select_next_available()
|
|
tab_bar.remove_tab(tab)
|
|
tab_closed.emit(tab)
|
|
if tab_bar.tab_count == 0:
|
|
_previous_active_tab = -1
|
|
|
|
|
|
func get_current_tab() -> int:
|
|
return tab_bar.current_tab
|
|
|
|
|
|
func get_content(idx: int) -> Control:
|
|
return content_container.get_child(idx)
|
|
|
|
|
|
func set_tab_metadata(tab: int, metadata: Variant) -> void:
|
|
tab_bar.set_tab_metadata(tab, metadata)
|
|
|
|
|
|
func get_tab_metadata(tab: int) -> Variant:
|
|
return tab_bar.get_tab_metadata(tab)
|