Redirect "ui_accept" input for specific Tree edge cases.

Trees appear to eat "ui_accept" before `gui_input` receives it. This makes certain use cases--triggering buttons in cells--impossible via the keyboard.

Here, `ScreenReader` attempts to intercept recent presses of "ui_accept" and, if a button in a cell should receive focus, redirects the `InputEvent` to the custom handler for `Tree`.

Unfortunately, this loses the ability to click buttons in cells in the editor's node tree for some reason. It restores, or maybe gets working in the first place, clicking on the _Remove_ button in the input mapping screen. Not sure how to restore the former functionality--these trees are complex and not well-documented.
This commit is contained in:
Nolan Darilek 2020-07-22 12:13:19 -05:00
parent d522da8fc0
commit 6beeaa01bd
2 changed files with 32 additions and 11 deletions

View File

@ -351,6 +351,8 @@ func text_edit_input(event):
var _last_tree_item_tokens
var button_index
func _tree_item_render():
if not node.has_focus():
@ -372,7 +374,15 @@ func _tree_item_render():
tokens.append("expanded")
var button_count = cell.get_button_count(i)
if button_count != 0:
button_index = 0
var column
for j in range(node.columns):
if cell.is_selected(j):
column = j
break
if column == i:
button_index = 0
else:
button_index = null
tokens.append(
(
str(button_count)
@ -380,12 +390,13 @@ func _tree_item_render():
+ TTS.singular_or_plural(button_count, "button", "buttons")
)
)
var button_tooltip = cell.get_button_tooltip(i, button_index)
if button_tooltip:
tokens.append(button_tooltip)
tokens.append("button")
if button_count > 1:
tokens.append("Use Home and End to switch focus.")
if button_index != null:
var button_tooltip = cell.get_button_tooltip(i, button_index)
if button_tooltip:
tokens.append(button_tooltip)
tokens.append("button")
if button_count > 1:
tokens.append("Use Home and End to switch focus.")
tokens.append("tree item")
if tokens != _last_tree_item_tokens:
TTS.speak(tokens.join(": "), true)
@ -394,8 +405,6 @@ func _tree_item_render():
var prev_selected_cell
var button_index
func _tree_item_or_cell_selected():
button_index = null
@ -430,8 +439,8 @@ func _tree_input(event):
node.rect_global_position.y + area.position.y + area.size.y / 2
)
node.get_tree().root.warp_mouse(position)
if item and column != null and button_index != null:
if event.is_action_pressed("ui_accept"):
if item and column != null and item.get_button_count(column):
if Input.is_action_just_pressed("ui_accept"):
node.accept_event()
return node.emit_signal("button_pressed", item, column, button_index + 1)
var new_button_index = button_index

View File

@ -173,6 +173,18 @@ var in_focus_mode_handler = false
func _input(event):
if not enabled:
return
var focus = find_focusable_control(get_tree().root)
if focus:
focus = focus.get_focus_owner()
if focus is Tree and Input.is_action_just_pressed("ui_accept"):
var accessible
for n in focus.get_children():
if n is Accessible:
accessible = n
break
if accessible and accessible.button_index != null:
accessible._tree_input(event)
get_tree().set_input_as_handled()
if enable_focus_mode:
if (
event is InputEventKey