From d6bfbab92aab142f05c5f1e28bc9c43115d4f687 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 19 Oct 2019 00:37:12 +0200 Subject: [PATCH] Improve filtering in the library The filter box is now located at the top of the library tree, as most search boxes are placed above the elements they search in. Pressing Ctrl + F will now focus the filter box as well. --- addons/material_maker/library.gd | 5 +++++ addons/material_maker/library.tscn | 29 ++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/addons/material_maker/library.gd b/addons/material_maker/library.gd index 190013c..1a9ae69 100644 --- a/addons/material_maker/library.gd +++ b/addons/material_maker/library.gd @@ -4,6 +4,7 @@ extends VBoxContainer var libraries = [] onready var tree : Tree = $Tree +onready var filter_line_edit : LineEdit = $HBoxContainer/Filter func _ready(): tree.set_column_expand(0, true) @@ -15,6 +16,10 @@ func _ready(): add_library("user://library/user.json") update_tree() +func _unhandled_input(event : InputEvent) -> void: + if event is InputEventKey and event.pressed and event.command and event.scancode == KEY_F: + filter_line_edit.grab_focus() + func get_selected_item_name(): var tree_item : TreeItem = tree.get_selected() var rv = "" diff --git a/addons/material_maker/library.tscn b/addons/material_maker/library.tscn index 9c333b3..4700ba4 100644 --- a/addons/material_maker/library.tscn +++ b/addons/material_maker/library.tscn @@ -7,22 +7,13 @@ margin_right = 352.0 margin_bottom = 423.0 script = ExtResource( 1 ) - -[node name="Tree" type="Tree" parent="."] -margin_right = 352.0 -margin_bottom = 395.0 -rect_min_size = Vector2( 100, 100 ) -size_flags_horizontal = 3 -size_flags_vertical = 3 -columns = 2 -hide_root = true -select_mode = 1 -script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} [node name="HBoxContainer" type="HBoxContainer" parent="."] -margin_top = 399.0 margin_right = 352.0 -margin_bottom = 423.0 +margin_bottom = 24.0 size_flags_horizontal = 3 [node name="FilterLabel" type="Label" parent="HBoxContainer"] @@ -36,4 +27,16 @@ margin_left = 41.0 margin_right = 352.0 margin_bottom = 24.0 size_flags_horizontal = 3 + +[node name="Tree" type="Tree" parent="."] +margin_top = 28.0 +margin_right = 352.0 +margin_bottom = 423.0 +rect_min_size = Vector2( 100, 100 ) +size_flags_horizontal = 3 +size_flags_vertical = 3 +columns = 2 +hide_root = true +select_mode = 1 +script = ExtResource( 2 ) [connection signal="text_changed" from="HBoxContainer/Filter" to="." method="_on_Filter_text_changed"]