Skip to content

Commit

Permalink
Added panel undocking
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Nov 30, 2023
1 parent e27a239 commit 2717840
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 181 deletions.
437 changes: 272 additions & 165 deletions addons/flexible_layout/flexible_layout.gd

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions addons/flexible_layout/flexible_overlay.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extends ColorRect


var flex_layout

var arrow_icon = preload("res://addons/flexible_layout/arrow.svg")
var tab_icon = preload("res://addons/flexible_layout/tab.svg")

Expand All @@ -12,19 +14,21 @@ func find_position_from_target(at_position, target):
return POSITIONS[pos_x+3*pos_y]

func _drop_data(at_position, data):
var target = get_parent().get_flexnode_at(at_position)
at_position /= get_window().content_scale_factor
var target = flex_layout.get_flexnode_at(at_position)
if target:
var destination = find_position_from_target(at_position, target)
if destination != -1:
get_parent().move_panel(data, target, destination)
flex_layout.move_panel(data, target, destination)

func _can_drop_data(at_position, data):
var target = get_parent().get_flexnode_at(at_position)
at_position /= get_window().content_scale_factor
var target = flex_layout.get_flexnode_at(at_position)
if target:
var rect : Rect2 = target.rect
match find_position_from_target(at_position, target):
0:
if data.flex_node == target:
if data.flex_panel.get_meta("flex_node") == target:
$Arrow.visible = false
return false
$Arrow.visible = true
Expand Down
12 changes: 8 additions & 4 deletions addons/flexible_layout/flexible_tab.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ func init(fp : Control):
func _draw():
var is_current : bool = (get_index() == get_parent().get_parent().current)
draw_style_box(get_theme_stylebox("tab_selected" if is_current else "tab_unselected", "TabBar"), Rect2(Vector2(), size))
#$Container/Undock.visible = is_current
$Container/Undock.visible = is_current
$Container/Close.visible = is_current

func _on_undock_pressed():
var flex_tab = get_parent().get_parent().get_flex_tab()
flex_tab.flexible_layout.undock(flex_panel)

func _on_close_pressed():
var flex_tab = get_parent().get_parent().get_flex_tab()
flex_tab.remove(flex_panel)
Expand All @@ -27,6 +31,6 @@ func _gui_input(event):
get_parent().get_parent().set_current(get_index())

func _get_drag_data(_position):
var flex_tab = get_parent().get_parent().get_flex_tab()
var flexible_layout = flex_tab.flexible_layout
return flexible_layout.PanelInfo.new(flex_tab, flex_panel)
return preload("res://addons/flexible_layout/flexible_layout.gd").PanelInfo.new(flex_panel)


7 changes: 3 additions & 4 deletions addons/flexible_layout/flexible_tab.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://e06xegp2tp3f"]

[ext_resource type="Script" path="res://addons/flexible_layout/flexible_tab.gd" id="1"]

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_b47q6"]
size = Vector2(16, 16)
[ext_resource type="Texture2D" uid="uid://c5br5opw6gmyp" path="res://addons/flexible_layout/undock.svg" id="2_ln5tf"]

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_bok24"]
size = Vector2(16, 16)
Expand Down Expand Up @@ -36,7 +34,7 @@ visible = false
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4
texture_normal = SubResource("PlaceholderTexture2D_b47q6")
texture_normal = ExtResource("2_ln5tf")

[node name="Close" type="TextureButton" parent="Container"]
visible = false
Expand All @@ -45,4 +43,5 @@ size_flags_horizontal = 4
size_flags_vertical = 4
texture_normal = SubResource("PlaceholderTexture2D_bok24")

[connection signal="pressed" from="Container/Undock" to="." method="_on_undock_pressed"]
[connection signal="pressed" from="Container/Close" to="." method="_on_close_pressed"]
5 changes: 3 additions & 2 deletions addons/flexible_layout/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ extends Control
func _ready():
get_window().borderless = false
get_window().size = Vector2i(1024, 768)
#await get_tree().process_frame
var file : FileAccess = FileAccess.open("res://addons/flexible_layout/layout.json", FileAccess.READ)
if file:
var layout : Dictionary = JSON.parse_string(file.get_as_text())
$FlexibleLayout.layout(layout)
var layout = JSON.parse_string(file.get_as_text())
$FlexibleLayout.layout(layout as Dictionary if layout else null)

func _on_tree_exiting():
var file : FileAccess = FileAccess.open("res://addons/flexible_layout/layout.json", FileAccess.WRITE)
Expand Down
51 changes: 51 additions & 0 deletions addons/flexible_layout/undock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions addons/flexible_layout/undock.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://c5br5opw6gmyp"
path="res://.godot/imported/undock.svg-0e462ba8ce32a7b4dbda8774c1ab8185.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/flexible_layout/undock.svg"
dest_files=["res://.godot/imported/undock.svg-0e462ba8ce32a7b4dbda8774c1ab8185.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
3 changes: 1 addition & 2 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func _ready() -> void:
get_window().borderless = false
get_window().transparent = false
get_window().move_to_foreground()
#get_window().gui_embed_subwindows = false
get_window().gui_embed_subwindows = false

get_window().close_requested.connect(self.on_close_requested)

Expand Down Expand Up @@ -161,7 +161,6 @@ func _ready() -> void:
if f.ends_with(".ptex"):
print(f)
dir.copy("res://material_maker/examples/"+f, "/examples/"+f)
print("Done")

# Set a minimum window size to prevent UI elements from collapsing on each other.
get_window().min_size = Vector2(1024, 600)
Expand Down

0 comments on commit 2717840

Please sign in to comment.