Re-add global column header

This commit is contained in:
kobewi 2022-09-25 20:35:51 +02:00
parent 6cc3548fdd
commit a8600d4621
6 changed files with 106 additions and 45 deletions

View File

@ -0,0 +1,32 @@
[gd_scene format=2]
[node name="Header" type="HBoxContainer"]
margin_right = 392.0
margin_bottom = 24.0
[node name="DragPanel" type="Panel" parent="."]
margin_right = 20.0
margin_bottom = 24.0
rect_min_size = Vector2( 20, 0 )
mouse_default_cursor_shape = 13
[node name="Name" type="LineEdit" parent="."]
margin_left = 24.0
margin_right = 344.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "Column name"
[node name="Counter" type="Label" parent="."]
margin_left = 348.0
margin_top = 5.0
margin_right = 376.0
margin_bottom = 19.0
rect_min_size = Vector2( 28, 0 )
text = "0"
align = 1
[node name="Minimize" type="Button" parent="."]
margin_left = 380.0
margin_right = 392.0
margin_bottom = 24.0

View File

@ -89,7 +89,7 @@ func load_data():
for section in data.get_sections(): for section in data.get_sections():
var column = todo_screen.add_column() var column = todo_screen.add_column()
column.name_edit.text = section column.set_name(section)
for item in data.get_section_keys(section): for item in data.get_section_keys(section):
if item == "__none__": if item == "__none__":

View File

@ -1,8 +1,11 @@
tool tool
extends Control extends Control
onready var column_container = $VBoxContainer/ScrollContainer/Columns onready var column_container = $"%Columns"
onready var vbox_container = $VBoxContainer onready var vbox_container = $VBoxContainer
onready var column_mirror = $"%ColumnMirror"
onready var scroll_container = $"%ScrollContainer"
var item_placement_holder: Panel var item_placement_holder: Panel
var undo_redo: UndoRedo var undo_redo: UndoRedo
@ -10,6 +13,15 @@ func _ready() -> void:
item_placement_holder = create_drag_placement_holder() item_placement_holder = create_drag_placement_holder()
undo_redo = UndoRedo.new() undo_redo = UndoRedo.new()
scroll_container.get_v_scrollbar().connect("value_changed", self, "update_mirror")
func update_mirror(v: float):
column_mirror.visible = v > column_mirror.get_child(0).rect_size.y
func connect_scrollbar(to_object, to_method):
scroll_container.get_h_scrollbar().connect("value_changed", to_object, to_method)
scroll_container.get_v_scrollbar().connect("value_changed", to_object, to_method)
func create_drag_placement_holder() -> Panel: func create_drag_placement_holder() -> Panel:
var new_holder = preload("res://addons/SimpleTODO/ItemPlacementHolder.tscn").instance() var new_holder = preload("res://addons/SimpleTODO/ItemPlacementHolder.tscn").instance()
@ -50,3 +62,7 @@ func delete_column(column):
func request_save() -> void: func request_save() -> void:
get_tree().get_nodes_in_group("__todo_plugin__").front().save_data() get_tree().get_nodes_in_group("__todo_plugin__").front().save_data()
func refresh_mirrors():
for column in column_container.get_children():
column.call_deferred("update_mirror", 0)

View File

@ -23,24 +23,39 @@ __meta__ = {
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 34.0 margin_bottom = 34.0
[node name="Button" type="Button" parent="VBoxContainer/PanelContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/PanelContainer"]
margin_left = 467.0 margin_left = 7.0
margin_top = 7.0 margin_top = 7.0
margin_right = 556.0 margin_right = 1017.0
margin_bottom = 27.0 margin_bottom = 27.0
[node name="Button" type="Button" parent="VBoxContainer/PanelContainer/VBoxContainer"]
margin_left = 460.0
margin_right = 549.0
margin_bottom = 20.0
size_flags_horizontal = 4 size_flags_horizontal = 4
text = "Add column" text = "Add column"
[node name="ColumnMirror" type="Control" parent="VBoxContainer/PanelContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
margin_top = 24.0
margin_right = 1010.0
margin_bottom = 54.0
rect_min_size = Vector2( 0, 30 )
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"] [node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 38.0 margin_top = 38.0
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 600.0 margin_bottom = 600.0
size_flags_vertical = 3 size_flags_vertical = 3
[node name="Columns" type="HBoxContainer" parent="VBoxContainer/ScrollContainer"] [node name="Columns" type="HBoxContainer" parent="VBoxContainer/ScrollContainer"]
unique_name_in_owner = true
margin_right = 1024.0 margin_right = 1024.0
margin_bottom = 562.0 margin_bottom = 562.0
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
[connection signal="pressed" from="VBoxContainer/PanelContainer/Button" to="." method="add_column" binds= [ true ]] [connection signal="pressed" from="VBoxContainer/PanelContainer/VBoxContainer/Button" to="." method="add_column" binds= [ true ]]

View File

@ -1,15 +1,15 @@
tool tool
extends PanelContainer extends PanelContainer
onready var head = $VBoxContainer/Head onready var header = $VBoxContainer/Header
onready var minimize_button = header.get_node("Minimize")
onready var name_edit = header.get_node("Name")
onready var counter = header.get_node("Counter")
onready var top_separator = $VBoxContainer/TopSeparator onready var top_separator = $VBoxContainer/TopSeparator
onready var bottom_separator = $VBoxContainer/BottomSeparator onready var bottom_separator = $VBoxContainer/BottomSeparator
onready var scroll_container = $VBoxContainer/ScrollContainer onready var scroll_container = $VBoxContainer/ScrollContainer
onready var actions = $VBoxContainer/Actions onready var actions = $VBoxContainer/Actions
onready var minimize_button = $VBoxContainer/Head/Minimize
onready var name_edit = $VBoxContainer/Head/Name
onready var item_container = $VBoxContainer/ScrollContainer/Items onready var item_container = $VBoxContainer/ScrollContainer/Items
onready var counter = $VBoxContainer/Head/Counter
onready var delete_button = $VBoxContainer/Actions/DeleteColumn onready var delete_button = $VBoxContainer/Actions/DeleteColumn
onready var timer = $Timer onready var timer = $Timer
@ -21,11 +21,15 @@ var is_dragging = false
var initial_item_index = 0 var initial_item_index = 0
var current_drag_item_index = 0 var current_drag_item_index = 0
var item_margin = 20 var item_margin = 20
var mirror_header
var mirror_counter
func set_minimized(val): func set_minimized(val):
minimized = val minimized = val
minimize_button.icon = get_icon("ArrowDown" if minimized else "ArrowUp", "EditorIcons") minimize_button.icon = get_icon("ArrowDown" if minimized else "ArrowUp", "EditorIcons")
if mirror_header:
mirror_header.get_node("Minimize").icon = get_icon("ArrowDown" if minimized else "ArrowUp", "EditorIcons")
top_separator.visible = !val top_separator.visible = !val
scroll_container.visible = !val scroll_container.visible = !val
@ -40,8 +44,30 @@ func _ready() -> void:
delete_button.icon = get_icon("Remove", "EditorIcons") delete_button.icon = get_icon("Remove", "EditorIcons")
counter.rect_min_size.x = delete_button.get_minimum_size().x counter.rect_min_size.x = delete_button.get_minimum_size().x
set_minimized(false) set_minimized(false)
mirror_header = PanelContainer.new()
main.column_mirror.add_child(mirror_header)
mirror_header.add_stylebox_override("panel", get_stylebox("panel"))
mirror_header.add_child(preload("res://addons/SimpleTODO/ColumnHeader.tscn").instance())
mirror_header.get_child(0).get_node("Minimize").icon = get_icon("ArrowDown" if minimized else "ArrowUp", "EditorIcons")
mirror_header.get_child(0).get_node("Name").editable = false
mirror_counter = mirror_header.get_child(0).get_node("Counter")
main.connect_scrollbar(self, "update_mirror")
header.get_node("DragPanel").connect("gui_input", self, "_on_DragPanel_gui_input")
mirror_header.get_child(0).get_node("DragPanel").connect("gui_input", self, "_on_DragPanel_gui_input")
update_mirror(0)
func _process(_delta): func set_name(column_name):
name_edit.text = column_name
mirror_header.get_child(0).get_node("Name").text = column_name
func update_mirror(v):
mirror_header.rect_min_size = Vector2(rect_size.x, header.rect_size.y)
mirror_header.rect_global_position.x = rect_global_position.x
func _process(delta):
if is_dragging: if is_dragging:
var mouse_position = main.get_local_mouse_position() var mouse_position = main.get_local_mouse_position()
@ -84,11 +110,13 @@ func delete_column() -> void:
func update_counter() -> void: func update_counter() -> void:
counter.text = str(item_container.get_child_count()) counter.text = str(item_container.get_child_count())
mirror_counter.text = str(item_container.get_child_count())
func request_save() -> void: func request_save() -> void:
get_tree().get_nodes_in_group("__todo_plugin__").front().save_data() get_tree().get_nodes_in_group("__todo_plugin__").front().save_data()
func name_changed(_new_text: String) -> void: func name_changed(_new_text: String) -> void:
mirror_header.get_child(0).get_node("Name").text = _new_text
timer.start() timer.start()
func _on_Minimize_pressed(): func _on_Minimize_pressed():
@ -148,6 +176,7 @@ func _input(event):
current_drag_item_index = 0 current_drag_item_index = 0
initial_item_index = 0 initial_item_index = 0
main.refresh_mirrors()
func move_column(index): func move_column(index):
undo_redo.create_action("Move Column") undo_redo.create_action("Move Column")

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=2] [gd_scene load_steps=6 format=2]
[ext_resource path="res://addons/SimpleTODO/TODOColumn.gd" type="Script" id=1] [ext_resource path="res://addons/SimpleTODO/TODOColumn.gd" type="Script" id=1]
[ext_resource path="res://addons/SimpleTODO/ColumnHeader.tscn" type="PackedScene" id=2]
[sub_resource type="StyleBoxFlat" id=3] [sub_resource type="StyleBoxFlat" id=3]
content_margin_left = 4.0 content_margin_left = 4.0
@ -43,36 +44,7 @@ margin_right = 396.0
margin_bottom = 74.0 margin_bottom = 74.0
rect_min_size = Vector2( 200, 0 ) rect_min_size = Vector2( 200, 0 )
[node name="Head" type="HBoxContainer" parent="VBoxContainer"] [node name="Header" parent="VBoxContainer" instance=ExtResource( 2 )]
margin_right = 392.0
margin_bottom = 24.0
[node name="DragPanel" type="Panel" parent="VBoxContainer/Head"]
margin_right = 20.0
margin_bottom = 24.0
rect_min_size = Vector2( 20, 0 )
mouse_default_cursor_shape = 13
[node name="Name" type="LineEdit" parent="VBoxContainer/Head"]
margin_left = 24.0
margin_right = 344.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "Column name"
[node name="Counter" type="Label" parent="VBoxContainer/Head"]
margin_left = 348.0
margin_top = 5.0
margin_right = 376.0
margin_bottom = 19.0
rect_min_size = Vector2( 28, 0 )
text = "0"
align = 1
[node name="Minimize" type="Button" parent="VBoxContainer/Head"]
margin_left = 380.0
margin_right = 392.0
margin_bottom = 24.0
[node name="TopSeparator" type="HSeparator" parent="VBoxContainer"] [node name="TopSeparator" type="HSeparator" parent="VBoxContainer"]
margin_top = 28.0 margin_top = 28.0
@ -120,9 +92,6 @@ icon = SubResource( 5 )
wait_time = 0.5 wait_time = 0.5
one_shot = true one_shot = true
[connection signal="gui_input" from="VBoxContainer/Head/DragPanel" to="." method="_on_DragPanel_gui_input"]
[connection signal="text_changed" from="VBoxContainer/Head/Name" to="." method="name_changed"]
[connection signal="pressed" from="VBoxContainer/Head/Minimize" to="." method="_on_Minimize_pressed"]
[connection signal="child_entered_tree" from="VBoxContainer/ScrollContainer/Items" to="." method="_on_Items_child_entered_tree"] [connection signal="child_entered_tree" from="VBoxContainer/ScrollContainer/Items" to="." method="_on_Items_child_entered_tree"]
[connection signal="child_exiting_tree" from="VBoxContainer/ScrollContainer/Items" to="." method="_on_Items_child_exited_tree"] [connection signal="child_exiting_tree" from="VBoxContainer/ScrollContainer/Items" to="." method="_on_Items_child_exited_tree"]
[connection signal="pressed" from="VBoxContainer/Actions/AddItem" to="." method="add_item" binds= [ true ]] [connection signal="pressed" from="VBoxContainer/Actions/AddItem" to="." method="add_item" binds= [ true ]]