Skip to content

Commit

Permalink
Update the dockable_container addon to 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
OverloadedOrama committed Nov 9, 2022
1 parent 20bce81 commit 927e4f4
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 118 deletions.
2 changes: 1 addition & 1 deletion addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Files extracted from source:
## godot-dockable-container

- Upstream: https://github.com/gilzoide/godot-dockable-container
- Version: custom
- Version: Based on git commit e5df60ed1d53246e03dba36053ff009846ba5174 with a modification on dockable_container.gd (lines 187-191).
- License: [CC0-1.0](https://github.com/gilzoide/godot-dockable-container/blob/main/LICENSE)
34 changes: 23 additions & 11 deletions addons/dockable_container/dockable_container.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extends Container

const SplitHandle = preload("split_handle.gd")
const DockablePanel = preload("dockable_panel.gd")
const ReferenceControl = preload("dockable_panel_reference_control.gd")
const DragNDropPanel = preload("drag_n_drop_panel.gd")
const Layout = preload("layout.gd")

Expand Down Expand Up @@ -60,10 +61,10 @@ func _notification(what: int) -> void:
what == NOTIFICATION_DRAG_BEGIN
and _can_handle_drag_data(get_viewport().gui_get_drag_data())
):
_drag_n_drop_panel.visible = true
_drag_n_drop_panel.set_enabled(true, not _layout.root.empty())
set_process_input(true)
elif what == NOTIFICATION_DRAG_END:
_drag_n_drop_panel.visible = false
_drag_n_drop_panel.set_enabled(false)
set_process_input(false)


Expand Down Expand Up @@ -107,17 +108,22 @@ func can_drop_data_fw(_position: Vector2, data, from_control) -> bool:
func drop_data_fw(_position: Vector2, data, from_control) -> void:
assert(from_control == _drag_n_drop_panel, "FIXME")

var from_node: DockablePanel = get_node(data.from_path)
if _drag_panel == null or (from_node == _drag_panel and _drag_panel.get_child_count() == 1):
var from_node: TabContainer = get_node(data.from_path)
if from_node == _drag_panel and _drag_panel.get_child_count() == 1:
return

var moved_tab = from_node.get_tab_control(data.tabc_element)
var moved_reference = moved_tab.reference_to
if moved_tab is ReferenceControl:
moved_tab = moved_tab.reference_to
if not _is_managed_node(moved_tab):
moved_tab.get_parent().remove_child(moved_tab)
add_child(moved_tab)

var margin = _drag_n_drop_panel.get_hover_margin()
_layout.split_leaf_with_node(_drag_panel.leaf, moved_reference, margin)
_layout_dirty = true
if _drag_panel != null:
var margin = _drag_n_drop_panel.get_hover_margin()
_layout.split_leaf_with_node(_drag_panel.leaf, moved_tab, margin)

_layout_dirty = true
queue_sort()


Expand Down Expand Up @@ -239,7 +245,8 @@ func _can_handle_drag_data(data):

func _is_managed_node(node: Node) -> bool:
return (
node != _panel_container
node.get_parent() == self
and node != _panel_container
and node != _drag_n_drop_panel
and node is Control
and not node.is_set_as_toplevel()
Expand Down Expand Up @@ -415,8 +422,13 @@ static func _untrack_children_after(node, idx: int) -> void:
func _on_panel_tab_layout_changed(tab: int, panel: DockablePanel) -> void:
"""Handler for `DockablePanel.tab_layout_changed`, update its LayoutPanel"""
_layout_dirty = true
var tab_reference = panel.get_tab_control(tab)
_layout.move_node_to_leaf(tab_reference.reference_to, panel.leaf, tab)
var control = panel.get_tab_control(tab)
if control is ReferenceControl:
control = control.reference_to
if not _is_managed_node(control):
control.get_parent().remove_child(control)
add_child(control)
_layout.move_node_to_leaf(control, panel.leaf, tab)
queue_sort()


Expand Down
5 changes: 4 additions & 1 deletion addons/dockable_container/dockable_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ func _on_tab_selected(tab: int) -> void:
func _on_tab_changed(tab: int) -> void:
if not _leaf:
return
var tab_name = get_tab_control(tab).name
var control = get_tab_control(tab)
if not control:
return
var tab_name = control.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)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ tool
extends Container
# Control that mimics its own visibility and rect into another Control.

signal moved_in_parent(control)

var reference_to: Control setget set_reference_to, get_reference_to

var _reference_to: Control = null
Expand All @@ -30,11 +28,11 @@ func set_reference_to(control: Control) -> void:
_reference_to.disconnect("renamed", self, "_on_reference_to_renamed")
_reference_to.disconnect("minimum_size_changed", self, "minimum_size_changed")
_reference_to = control
_reference_to.connect("minimum_size_changed", self, "minimum_size_changed")
minimum_size_changed()
if not _reference_to:
return
_reference_to.connect("renamed", self, "_on_reference_to_renamed")
_reference_to.connect("minimum_size_changed", self, "minimum_size_changed")
_reference_to.visible = visible


Expand Down
44 changes: 29 additions & 15 deletions addons/dockable_container/drag_n_drop_panel.gd
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
tool
extends Control

const MARGIN_NONE = -1
const DRAW_NOTHING = -1
const DRAW_CENTERED = -2

var _hover_margin = MARGIN_NONE
var _draw_margin = DRAW_NOTHING
var _should_split = false


func _notification(what: int) -> void:
if what == NOTIFICATION_MOUSE_EXIT:
_hover_margin = MARGIN_NONE
elif what == NOTIFICATION_DRAG_BEGIN:
_hover_margin = MARGIN_NONE
_draw_margin = DRAW_NOTHING
update()
elif what == NOTIFICATION_MOUSE_ENTER and not _should_split:
_draw_margin = DRAW_CENTERED
update()


func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
_find_hover_margin(event.position)
if _should_split and event is InputEventMouseMotion:
_draw_margin = _find_hover_margin(event.position)
update()


func _draw() -> void:
var rect
if _hover_margin == MARGIN_NONE:
if _draw_margin == DRAW_NOTHING:
return
elif _hover_margin == MARGIN_LEFT:
elif _draw_margin == DRAW_CENTERED:
rect = Rect2(Vector2.ZERO, rect_size)
elif _draw_margin == MARGIN_LEFT:
rect = Rect2(0, 0, rect_size.x * 0.5, rect_size.y)
elif _hover_margin == MARGIN_TOP:
elif _draw_margin == MARGIN_TOP:
rect = Rect2(0, 0, rect_size.x, rect_size.y * 0.5)
elif _hover_margin == MARGIN_RIGHT:
elif _draw_margin == MARGIN_RIGHT:
var half_width = rect_size.x * 0.5
rect = Rect2(half_width, 0, half_width, rect_size.y)
elif _hover_margin == MARGIN_BOTTOM:
elif _draw_margin == MARGIN_BOTTOM:
var half_height = rect_size.y * 0.5
rect = Rect2(0, half_height, rect_size.x, half_height)
var stylebox = get_stylebox("panel", "TooltipPanel")
draw_style_box(stylebox, rect)


func set_enabled(enabled: bool, should_split: bool = true) -> void:
visible = enabled
_should_split = should_split
if enabled:
_draw_margin = DRAW_NOTHING
update()


func get_hover_margin() -> int:
return _hover_margin
return _draw_margin


func _find_hover_margin(point: Vector2):
func _find_hover_margin(point: Vector2) -> int:
var half_size = rect_size * 0.5

var left = point.distance_squared_to(Vector2(0, half_size.y))
Expand All @@ -62,4 +76,4 @@ func _find_hover_margin(point: Vector2):
if lesser > bottom:
#lesser = bottom # unused result
lesser_margin = MARGIN_BOTTOM
_hover_margin = lesser_margin
return lesser_margin
9 changes: 4 additions & 5 deletions addons/dockable_container/layout.gd
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ func update_nodes(names: PoolStringArray) -> void:
func move_node_to_leaf(node: Node, leaf: LayoutPanel, relative_position: int) -> void:
var node_name = node.name
var previous_leaf = _leaf_by_node_name.get(node_name)
if not previous_leaf:
return
previous_leaf.remove_node(node)
if previous_leaf.empty():
_remove_leaf(previous_leaf)
if previous_leaf:
previous_leaf.remove_node(node)
if previous_leaf.empty():
_remove_leaf(previous_leaf)

leaf.insert_node(relative_position, node)
_leaf_by_node_name[node_name] = leaf
Expand Down
2 changes: 1 addition & 1 deletion addons/dockable_container/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Layout information is stored in Resource objects, so they can be saved/loaded fr
This plugin also offers a replica of the Container layout to be edited directly in the inspector."
author="gilzoide"
version="0.4.0"
version="1.1.1"
script="plugin.gd"
2 changes: 1 addition & 1 deletion addons/dockable_container/samples/TestScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends VBoxContainer

const SAVED_LAYOUT_PATH = "user://layout.tres"

onready var _container = $DockableContainer
onready var _container = $DockableContainers/DockableContainer
onready var _clone_control = $HBoxContainer/ControlPrefab
onready var _checkbox_container = $HBoxContainer

Expand Down
Loading

0 comments on commit 927e4f4

Please sign in to comment.