mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
skip collapsed categories in add node menu keyboard navigation (#7)
Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/7 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
parent
a427535ff5
commit
09deeccb60
1 changed files with 36 additions and 14 deletions
|
@ -94,13 +94,7 @@ func _on_search_line_edit_gui_input(event: InputEvent) -> void:
|
||||||
# reached the end of items in the current category
|
# reached the end of items in the current category
|
||||||
category.unhighlight_all()
|
category.unhighlight_all()
|
||||||
|
|
||||||
var nc: Category
|
var nc := get_next_visible_category(category.get_index())
|
||||||
if category.get_index() + 1 == scroll_content_container.get_child_count():
|
|
||||||
# reached the end, get the first category
|
|
||||||
nc = scroll_content_container.get_child(0)
|
|
||||||
else:
|
|
||||||
# there is another category after this
|
|
||||||
nc = scroll_content_container.get_child(category.get_index() + 1)
|
|
||||||
nc.highlight_item(0)
|
nc.highlight_item(0)
|
||||||
scroll_container.ensure_control_visible(nc.get_child(0))
|
scroll_container.ensure_control_visible(nc.get_child(0))
|
||||||
return
|
return
|
||||||
|
@ -120,13 +114,7 @@ func _on_search_line_edit_gui_input(event: InputEvent) -> void:
|
||||||
# reached the beginning of items in the current category
|
# reached the beginning of items in the current category
|
||||||
category.unhighlight_all()
|
category.unhighlight_all()
|
||||||
|
|
||||||
var nc: Category
|
var nc := get_previous_visible_category(category.get_index())
|
||||||
if category.get_index() - 1 == -1:
|
|
||||||
# reached the beginning, get the last category
|
|
||||||
nc = scroll_content_container.get_child(scroll_content_container.get_child_count() - 1)
|
|
||||||
else:
|
|
||||||
# there is another category before this
|
|
||||||
nc = scroll_content_container.get_child(category.get_index() - 1)
|
|
||||||
nc.highlight_item(nc.get_item_count() - 1)
|
nc.highlight_item(nc.get_item_count() - 1)
|
||||||
scroll_container.ensure_control_visible(nc.get_child(nc.get_item_count() - 1))
|
scroll_container.ensure_control_visible(nc.get_child(nc.get_item_count() - 1))
|
||||||
return
|
return
|
||||||
|
@ -135,6 +123,36 @@ func _on_search_line_edit_gui_input(event: InputEvent) -> void:
|
||||||
scroll_container.ensure_control_visible(category.get_child(item - 1))
|
scroll_container.ensure_control_visible(category.get_child(item - 1))
|
||||||
|
|
||||||
|
|
||||||
|
## Returns the next uncollapsed category, starting from index [code]at[/code], wrapping around if no other
|
||||||
|
## categories are uncollapsed.
|
||||||
|
func get_next_visible_category(at: int) -> Category:
|
||||||
|
var i := at
|
||||||
|
var s := 0
|
||||||
|
|
||||||
|
while s < scroll_content_container.get_child_count():
|
||||||
|
i = (i + 1) % scroll_content_container.get_child_count()
|
||||||
|
if !(scroll_content_container.get_child(i) as Category).is_collapsed():
|
||||||
|
return scroll_content_container.get_child(i)
|
||||||
|
s += 1
|
||||||
|
|
||||||
|
return scroll_content_container.get_child(at)
|
||||||
|
|
||||||
|
|
||||||
|
## Returns the previous uncollapsed category, starting from index [code]at[/code], wrapping around if no other
|
||||||
|
## categories are uncollapsed.
|
||||||
|
func get_previous_visible_category(at: int) -> Category:
|
||||||
|
var i := at
|
||||||
|
var s := 0
|
||||||
|
|
||||||
|
while s < scroll_content_container.get_child_count():
|
||||||
|
i = (i - 1) % scroll_content_container.get_child_count()
|
||||||
|
if !(scroll_content_container.get_child(i) as Category).is_collapsed():
|
||||||
|
return scroll_content_container.get_child(i)
|
||||||
|
s += 1
|
||||||
|
|
||||||
|
return scroll_content_container.get_child(at)
|
||||||
|
|
||||||
|
|
||||||
## Callback for [member search_line_edit]. Handles emitting [signal node_selected]
|
## Callback for [member search_line_edit]. Handles emitting [signal node_selected]
|
||||||
func _on_search_line_edit_text_submitted(_new_text: String) -> void:
|
func _on_search_line_edit_text_submitted(_new_text: String) -> void:
|
||||||
var category: Category
|
var category: Category
|
||||||
|
@ -261,6 +279,10 @@ class Category extends VBoxContainer:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
func is_collapsed() -> bool:
|
||||||
|
return collapse_button.button_pressed
|
||||||
|
|
||||||
|
|
||||||
## Represents an item in a [AddNodeMenu.Category].
|
## Represents an item in a [AddNodeMenu.Category].
|
||||||
##
|
##
|
||||||
## A selectable and highlightable category item with a favorite button.
|
## A selectable and highlightable category item with a favorite button.
|
||||||
|
|
Loading…
Reference in a new issue