1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00
Pixelorama/addons/dockable_container/dockable_panel.gd
Manolis Papadeas e2bb0b8440
New UI system using Dockable Containers (#640)
* Add dockable container plugin

Experimenting with it, also added a tabs_visible property to the DockableContainer. Removed some code about Tallscreen from Main.gd, but not all of it.

* Add a panel behind the UI, temporarily restore the dark theme

* Remove tallscreen code

* Add edit mode, toggles DockableContainer's tab visibility on and off

* Split tool options into color pickers, left and right tool options

* Remove alternate_transparent_background

* Re-order tool buttons on resize

* Clip content in timeline

* Changes to the tool panel

* Removed some old unused node variables

* Restore Zen mode

* Set tabs_visible = false by default

* Better way to set tabs_visible = false by default

* Added the license of godot-dockable-container

* Remove unneeded lines

* Update README.md

* Restore window transparency with the canvas

It makes all of the TabContainers transparent however, which may not be what we actually want.

* Change tab names of the UI elements

* Remove unneeded nodes from ColorPickers.tscn

* Update default.tres

* Let the user hide elements individually

* Add some checks in HandleThemes

* Center tool icons

* Remove unneeded custom panel in SplashDialog

* Bump version to v0.10-dev and some other minor changes

* Fix crash on Zen Mode

* Added a hacky way to fix the issue with the palette panel size
2022-01-30 00:47:25 +02:00

81 lines
2.1 KiB
GDScript

tool
extends TabContainer
signal tab_layout_changed(tab)
const ReferenceControl = preload("dockable_panel_reference_control.gd")
const Layout = preload("layout.gd")
var leaf: Layout.LayoutPanel setget set_leaf, get_leaf
var _leaf: Layout.LayoutPanel
func _ready() -> void:
drag_to_rearrange_enabled = true
func _enter_tree() -> void:
connect("tab_selected", self, "_on_tab_selected")
connect("tab_changed", self, "_on_tab_changed")
func _exit_tree() -> void:
disconnect("tab_selected", self, "_on_tab_selected")
disconnect("tab_changed", self, "_on_tab_changed")
func track_nodes(nodes: Array, new_leaf: Layout.LayoutPanel) -> void:
_leaf = null # avoid using previous leaf in tab_changed signals
var min_size = min(nodes.size(), get_child_count())
# remove spare children
for i in range(min_size, get_child_count()):
var child = get_child(min_size)
child.reference_to = null
remove_child(child)
child.queue_free()
# add missing children
for i in range(min_size, nodes.size()):
var ref_control = ReferenceControl.new()
add_child(ref_control)
assert(nodes.size() == get_child_count(), "FIXME")
# setup children
for i in nodes.size():
var ref_control: ReferenceControl = get_child(i)
ref_control.reference_to = nodes[i]
set_tab_title(i, nodes[i].name)
set_leaf(new_leaf)
func get_child_rect() -> Rect2:
var control = get_current_tab_control()
return Rect2(rect_position + control.rect_position, control.rect_size)
func set_leaf(value: Layout.LayoutPanel) -> void:
if get_tab_count() > 0 and value:
current_tab = clamp(value.current_tab, 0, get_tab_count() - 1)
_leaf = value
func get_leaf() -> Layout.LayoutPanel:
return _leaf
func get_layout_minimum_size() -> Vector2:
return get_combined_minimum_size()
func _on_tab_selected(tab: int) -> void:
if _leaf:
_leaf.current_tab = tab
func _on_tab_changed(tab: int) -> void:
if not _leaf:
return
var tab_name = get_tab_control(tab).name
var name_index_in_leaf = _leaf.find_name(tab_name)
if name_index_in_leaf != tab: # NOTE: this handles added tabs (index == -1)
emit_signal("tab_layout_changed", tab)