2018-08-27 17:22:57 +02:00
|
|
|
tool
|
|
|
|
extends Panel
|
|
|
|
|
|
|
|
var current_tab = -1 setget set_current_tab
|
|
|
|
|
|
|
|
signal tab_changed
|
|
|
|
signal no_more_tabs
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func add_child(control, legible_unique_name = false) -> void:
|
2018-11-04 15:43:02 +01:00
|
|
|
.add_child(control, legible_unique_name)
|
2018-08-27 17:22:57 +02:00
|
|
|
if !(control is Tabs):
|
|
|
|
$Tabs.add_tab(control.name)
|
|
|
|
move_child(control, $Tabs.get_tab_count()-1)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func close_tab(tab = null) -> void:
|
2018-08-27 17:22:57 +02:00
|
|
|
if tab == null:
|
|
|
|
tab = $Tabs.get_current_tab()
|
|
|
|
get_child(tab).queue_free()
|
|
|
|
$Tabs.remove_tab(tab)
|
|
|
|
var control = get_child(tab)
|
|
|
|
remove_child(control)
|
|
|
|
control.free()
|
|
|
|
current_tab = -1
|
|
|
|
if $Tabs.get_tab_count() == 0:
|
|
|
|
emit_signal("no_more_tabs")
|
|
|
|
else:
|
|
|
|
set_current_tab(0)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func move_active_tab_to(idx_to) -> void:
|
2018-08-27 17:22:57 +02:00
|
|
|
$Tabs.move_tab(current_tab, idx_to)
|
|
|
|
move_child(get_child(current_tab), idx_to)
|
|
|
|
set_current_tab(idx_to)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_current_tab(t) -> void:
|
2018-10-13 17:31:37 +02:00
|
|
|
if t == current_tab or t < 0 or t >= $Tabs.get_tab_count():
|
2018-08-27 17:22:57 +02:00
|
|
|
return
|
|
|
|
var node
|
|
|
|
if current_tab >= 0 && current_tab < $Tabs.get_tab_count():
|
|
|
|
node = get_child(current_tab)
|
|
|
|
node.visible = false
|
|
|
|
current_tab = t
|
2018-10-13 17:31:37 +02:00
|
|
|
node = get_child(current_tab)
|
|
|
|
node.visible = true
|
|
|
|
node.rect_position = Vector2(0, $Tabs.rect_size.y)
|
|
|
|
node.rect_size = rect_size - node.rect_position
|
2018-08-27 17:22:57 +02:00
|
|
|
$Tabs.current_tab = current_tab
|
|
|
|
emit_signal("tab_changed", current_tab)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_tab_title(index, title) -> void:
|
2018-08-27 17:22:57 +02:00
|
|
|
$Tabs.set_tab_title(index, title)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_current_tab_control() -> Node:
|
2018-08-27 17:22:57 +02:00
|
|
|
return get_child(current_tab)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_Tabs_tab_changed(tab) -> void:
|
2018-08-27 17:22:57 +02:00
|
|
|
set_current_tab(tab)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_Projects_resized() -> void:
|
2018-08-27 17:22:57 +02:00
|
|
|
$Tabs.rect_size.x = rect_size.x
|