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

Merge KeyEventExtra into KeyEvent #4029

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

madsmtm
Copy link
Member

@madsmtm madsmtm commented Dec 3, 2024

To make the text_with_all_modifiers and key_without_modifiers fields easier to use, and to allow constructing KeyEvent in user test code. This also removes the need for KeyEventExtModifierSupplement.

Fixes #3606 (which is desired by Xilem/Masonry).

I went with adding the fields on all platforms, and just defining their behaviour as the same as text/logical_key on the unsupported platforms. This is similar to how we have all WindowEvents available on all the platforms, but not all are emitted by all of them, so I felt this was a good trade-off.

  • Tested on all platforms changed
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

To make the fields easier to use, and to allow constructing KeyEvent in
user test code.
@madsmtm madsmtm added S - enhancement Wouldn't this be the coolest? S - api Design and usability I - BREAKING CHANGE labels Dec 3, 2024
/// - **Android:** Unimplemented, this field is always the same value as `logical_key`.
/// - **iOS:** Unimplemented, this field is always the same value as `logical_key`.
/// - **Web:** Unsupported, this field is always the same value as `logical_key`.
pub key_without_modifiers: keyboard::Key,
Copy link
Member Author

Choose a reason for hiding this comment

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

Another option would be to make this an Option<keyboard::Key>, I'm not familiar enough with it to say what would be best.

Comment on lines +864 to +866
/// - **Android:** Unimplemented, this field is always the same value as `text`.
/// - **iOS:** Unimplemented, this field is always the same value as `text`.
/// - **Web:** Unsupported, this field is always the same value as `text`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Another option would be to always set None here on these platforms, but I felt this choice was more consistent with key_without_modifiers (unless we change that to be an Option).

@madsmtm madsmtm added the C - nominated Nominated for discussion in the next meeting label Dec 3, 2024
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Could we have it the same way as before in a struct on a KeyboardEvent which you can not match, but can e.g. default init or set separately?

I don't really want to have an option to match on those, since they are not cross platform. Other than that removing the extension is fine and it's not that big of a breaking change.

@madsmtm
Copy link
Member Author

madsmtm commented Dec 3, 2024

Could we have it the same way as before in a struct on a KeyboardEvent which you can not match, but can e.g. default init or set separately?

Hmm, I can, but I kinda feel like that'd just be unnecessary indirection? And I guess it we really want users to be able to test their crates, they'll need the ability to set the fields in this extra struct anyhow?

I don't really want to have an option to match on those, since they are not cross platform. Other than that removing the extension is fine and it's not that big of a breaking change.

Am I understanding correctly that your worry is that users may be more aware of a method not being cross-platform, as opposed to a field being so?

@kchibisov
Copy link
Member

Yes, so it's an Option and you should account for it explicitly. If it's not an option you will kind of assume that it works, where on e.g. some it'll always fail. You can just default initialize it, I don't see an issue with it. Yes you won't be able to test the values you have in text_with_all_modifiers, but you write the keys yourself, so can write whatever in regular fields, so it doesn't really matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - nominated Nominated for discussion in the next meeting I - BREAKING CHANGE S - api Design and usability S - enhancement Wouldn't this be the coolest?
Development

Successfully merging this pull request may close these issues.

How to create instance of WindowEvent::KeyboardInput / KeyEvent
2 participants