Skip to content

Commit 82f925b

Browse files
committed
block_category_display: Make categories buttons to show/hide blocks
When all the categories are shown, you may need to do quite a bit of scrolling to find the block you want or just to discover what's there. This changes the category display so that each category is a button that can show or hide its blocks. All blocks are initially hidden to be able to see all the available categories. The expander is implemented as a flat button with a icon. Godot does provide the Tree class with similar functionality, but it's a bit complex to use. More importantly TreeItems are their own class that don't derive from Node. That would break the current Block usage. The Tree arrow icons are reused, though. To give a little more indication that the category can be expanded, the color is lightened relative to the expanded state. https://phabricator.endlessm.com/T35507
1 parent 7c520fb commit 82f925b

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

addons/block_code/ui/picker/categories/block_category_display.gd

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,53 @@
22
class_name BlockCategoryDisplay
33
extends MarginContainer
44

5+
signal category_expanded(value: bool)
6+
57
var category: BlockCategory
68

7-
@onready var _label := %Label
9+
@onready var _button := %Button
10+
@onready var _blocks_container := %BlocksContainer
811
@onready var _blocks := %Blocks
912
@onready var _background := %Background
1013

14+
@onready var _icon_collapsed := EditorInterface.get_editor_theme().get_icon("GuiTreeArrowRight", "EditorIcons")
15+
@onready var _icon_expanded := EditorInterface.get_editor_theme().get_icon("GuiTreeArrowDown", "EditorIcons")
1116

12-
func _ready():
13-
if category:
14-
_label.text = category.name
15-
_background.color = category.color.darkened(0.7)
17+
var expanded: bool:
18+
set = _set_expanded
19+
20+
21+
func _set_expanded(value: bool):
22+
expanded = value
23+
24+
_blocks_container.visible = expanded
25+
if expanded:
26+
_button.icon = _icon_expanded
27+
_background.color = category.color.darkened(0.5)
28+
_background.color.a = 0.3
29+
else:
30+
_button.icon = _icon_collapsed
31+
_background.color = category.color.darkened(0.2)
1632
_background.color.a = 0.3
1733

18-
for _block in category.block_list:
19-
var block: Block = _block as Block
34+
category_expanded.emit(expanded)
35+
36+
37+
func _ready():
38+
if not category:
39+
category = BlockCategory.new()
40+
41+
_button.text = category.name
42+
43+
for _block in category.block_list:
44+
var block: Block = _block as Block
45+
46+
block.color = category.color
47+
48+
_blocks.add_child(block)
49+
50+
expanded = false
2051

21-
block.color = category.color
2252

23-
_blocks.add_child(block)
53+
func _on_button_toggled(toggled_on):
54+
expanded = toggled_on

addons/block_code/ui/picker/categories/block_category_display.tscn

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,39 @@ theme_override_constants/margin_right = 10
2424
theme_override_constants/margin_bottom = 4
2525

2626
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
27+
custom_minimum_size = Vector2(400, 0)
2728
layout_mode = 2
2829

2930
[node name="Spacer" type="Control" parent="MarginContainer/VBoxContainer"]
3031
custom_minimum_size = Vector2(0, 4)
3132
layout_mode = 2
3233

33-
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
34+
[node name="Button" type="Button" parent="MarginContainer/VBoxContainer"]
3435
unique_name_in_owner = true
3536
layout_mode = 2
3637
theme_override_font_sizes/font_size = 16
38+
toggle_mode = true
3739
text = "Category"
40+
flat = true
41+
alignment = 0
42+
icon_alignment = 2
3843

39-
[node name="Spacer2" type="Control" parent="MarginContainer/VBoxContainer"]
44+
[node name="BlocksContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
45+
unique_name_in_owner = true
46+
visible = false
47+
layout_mode = 2
48+
49+
[node name="Spacer2" type="Control" parent="MarginContainer/VBoxContainer/BlocksContainer"]
4050
custom_minimum_size = Vector2(0, 4)
4151
layout_mode = 2
4252

43-
[node name="Blocks" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
53+
[node name="Blocks" type="VBoxContainer" parent="MarginContainer/VBoxContainer/BlocksContainer"]
4454
unique_name_in_owner = true
4555
layout_mode = 2
4656
theme_override_constants/separation = 14
4757

48-
[node name="Spacer3" type="Control" parent="MarginContainer/VBoxContainer"]
58+
[node name="Spacer3" type="Control" parent="MarginContainer/VBoxContainer/BlocksContainer"]
4959
custom_minimum_size = Vector2(0, 50)
5060
layout_mode = 2
61+
62+
[connection signal="toggled" from="MarginContainer/VBoxContainer/Button" to="." method="_on_button_toggled"]

0 commit comments

Comments
 (0)