Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document when to use _unhandled_key_input over _unhandled_input #42100

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

groud
Copy link
Member

@groud groud commented Sep 15, 2020

As discussed in IRC with @reduz and @EricEzaM

@@ -101,7 +101,8 @@
Called when an [InputEvent] hasn't been consumed by [method _input] or any GUI. The input event propagates up through the node tree until a node consumes it.
Copy link
Contributor

@EricEzaM EricEzaM Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the right language is used here. The call doesn't actually "propagate" from what I can tell (see SceneTree::_call_input_pause).

The input event propagates up through the node tree

This language might mislead the user into thinking the call is repeated on parents until it is handled, or until the last parent. This is not correct. call_input_pause only calls the method on the node it is registered to call on. For example, MenuButtons are registered to receive unhandled_key_input. The _unhandled_key_input method is only called on the MenuButton - not parents, and not children.

I would probably change this to something more accurate:
"_unhandled_input is called on every node which is registered to receive it until one of the nodes handles the input."

However this relies on the information that "It is only called if unhandled input processing is enabled" so this might be better to place after the next line
The usage of the word "propagates" may also mislead the user into thinking at Object::propagate_call is used behind the scenes for this functionality.

It may also be worth noting that the order of the nodes it is called on is based on order in the scene tree - based on Node::is_greater_than.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S. I know this isn't part of the PR but I thought since we are here, let's discuss

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right on all the points, but to be honest I don't think we should care that much.
The function is indeed not called on all the nodes, as they indeed have to implement the method. I am not sure it is worth mentioning to the user, as they probably know know an unexisting function cannot be called.

Regarding the "propagate" term, in the end it's the same. It's a similar behavior to calling Node::propagate_call, as the node order produced by Node::is_greater_than will lead to the same order as what a reversed propagate_call would do. That's why the documentation mentions "propagates up through the node tree".

We have to write the documentation from the user point of view, what happen behind the scene for performance reasons (like adding the nodes to a group, so that the function is only called on specific nodes, etc...) is not important. What matters is the end result.

doc/classes/Node.xml Outdated Show resolved Hide resolved
@akien-mga akien-mga added this to the 4.0 milestone Sep 23, 2020
@akien-mga akien-mga requested a review from reduz September 23, 2020 11:37
doc/classes/Node.xml Outdated Show resolved Hide resolved
@akien-mga akien-mga requested review from YuriSizov and a team July 3, 2022 22:30
@akien-mga
Copy link
Member

Oldie, but still goodie? Would need a rebase and maybe re-discussion with current GUI experts.

@NathanLovato
Copy link
Contributor

Yeah it's looking good.

@akien-mga akien-mga requested a review from a team July 5, 2022 12:51
doc/classes/Node.xml Outdated Show resolved Hide resolved
doc/classes/Node.xml Outdated Show resolved Hide resolved
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in PR review meeting to merge once rebased.

The discussion on existing language is not fully resolved but this can be reworked in a future PR / discussed in another issue.

@groud groud force-pushed the document_unhandled_key_input branch from a8e89b4 to 3913fda Compare July 5, 2022 12:59
@bruvzg
Copy link
Member

bruvzg commented Jul 5, 2022

Unhandled input processing was changed a bit, now there are 3 stages:

  • shortcut_input - processed first, used for global shortcuts. Only Key and Shortcut events.
  • unhandled_input - processed if event was not consumed by shortcut_input. All events.
  • unhandled_key_input - processed if event was not consumed by unhandled_input, it's only used to handle text input with Alt+ and Ctrl+ modifiers. Only Key events.

@YuriSizov
Copy link
Contributor

@groud Would you mind incorporating the changes that bruvzg mentions? (and fixing the typos mentioned in the review). Your additions touch directly on the need to use keyboard shortcuts, so I guess shortcut_input should be recommended as the first option.

@YuriSizov YuriSizov removed their request for review July 20, 2022 14:38
@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Sep 8, 2022
@YuriSizov YuriSizov marked this pull request as draft September 5, 2023 14:26
@akien-mga
Copy link
Member

Closing in on a 3 year anniversary here... @groud are you able to do the required adjustments?

@groud groud marked this pull request as ready for review September 12, 2023 06:59
@groud
Copy link
Member Author

groud commented Sep 12, 2023

I missclicked the "ready for review" button, sorry. I'll have a look today

@groud groud force-pushed the document_unhandled_key_input branch from 3913fda to 0e4c027 Compare September 12, 2023 09:36
@groud
Copy link
Member Author

groud commented Sep 12, 2023

Updated, let me know what you think. :)

@groud groud force-pushed the document_unhandled_key_input branch from 0e4c027 to ae4a60e Compare September 12, 2023 09:45
@akien-mga akien-mga changed the title Document why use _unhandled_key_input over _unhandled_input Document when to use _unhandled_key_input over _unhandled_input Sep 12, 2023
Copy link
Contributor

@Sauermann Sauermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes describe the implementation correctly as far as I can tell.

doc/classes/Node.xml Outdated Show resolved Hide resolved
@groud groud force-pushed the document_unhandled_key_input branch from ae4a60e to bc33add Compare September 12, 2023 11:18
@YuriSizov YuriSizov modified the milestones: 4.x, 4.2 Sep 14, 2023
@YuriSizov YuriSizov merged commit 30178b2 into godotengine:master Sep 14, 2023
@YuriSizov
Copy link
Contributor

YuriSizov commented Sep 14, 2023

Phew, finally done with this one! One day shy of a 3 year anniversary :D Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants