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

Update RadialGauge to use KeyboardAccelerators #4456

Merged
merged 6 commits into from
Oct 11, 2022

Conversation

XamlBrewer
Copy link
Contributor

Replace KeyDown event handling by KeyboardAccelerators. This does not change the behavior. It improves performance by not reacting to just any key stroke. I also removes the call to CoreWindow.GetKeyState - an API that doesn't exist in WinUI 3.

Fixes

Replace KeyDown event handling by KeyboardAccelerators.

PR Type

What kind of change does this PR introduce?

Refactoring (no functional changes, no api changes)

What is the current behavior?

The value can be manipulated via keyboard input: arrows, with our without CTRL.

What is the new behavior?

The same.

It improves performance by not reacting to just any key stroke. I also removes the call to CoreWindow.GetKeyState - an API that doesn't exist in WinUI 3. It is possible to create a RadialGauge control for WinUI 2 (UWP) as well as WinUI3 (Win32) from the same source code, and this modification brings this situation closer.

PR Checklist

Please check if your PR fulfills the following requirements:

  • [ * ] Tested code with current UWP (and WinUI 3) versions.
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
    • If control, added to Visual Studio Design project
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • [ * ] Contains NO breaking changes

Other information

Replace KeyDown event handling by KeyboardAccelerators. This does not change the behavior. It improves performance by not reacting to just any key stroke. I also removes the call to CoreWindow.GetKeyState - an API that doesn't exist in WinUI 3.
@ghost
Copy link

ghost commented Jan 11, 2022

Thanks XamlBrewer for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from michael-hawker and azchohfi January 11, 2022 19:00
Fixed StyleCop issues
Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

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

After testing RadialGauge on both main and then this branch, this PR has caused a regression.

  1. Open the RadialGauge sample
  2. Tab until the selection rectangle is around the radial gauge
  3. Press the arrow keys on the keyboard. Nothing happens, when it should change the value

@XamlBrewer
Copy link
Contributor Author

I guess it makes sense to create a Toolkit Labs Experiment for this control, so we can easily debug on all platforms (UWP, WinUI 3, UNO).

@michael-hawker
Copy link
Member

I guess it makes sense to create a Toolkit Labs Experiment for this control, so we can easily debug on all platforms (UWP, WinUI 3, UNO).

The plan after the upcoming hotfix is to bring the labs infrastructure to the main repo so we can merge all our branches together. If you do want to test in the interim across both though, copying over to a Labs environment does work. We've done it for a few things we've been working on like the new GridSplitter.

@Arlodotexe
Copy link
Member

Arlodotexe commented Sep 13, 2022

The migration to Labs will take place as 8.0. We'd like to include this as a hotfix in 7.1.3/7.2, so we'll need to fix the regression before moving forward @XamlBrewer

@XamlBrewer
Copy link
Contributor Author

To me, the most probable reason for this is that you forgot to set 'IsInteractive' to True. The control only listens to keystrokes and touch gestures when it is in interactive mode. I'm pretty confident about the source code - I can share a simple UWP host app running this exact version if you want.

Other possibility: mismatch between 'Maximum' (default 1, from RangeBase) and 'SmallChange'/'LargeChange' (set to 1 and 10 in the constructor - maybe not the best idea). In that case you might not see changes when using arrow keys.

@ghost ghost added the no-recent-activity 📉 Open Issues that require attention label Sep 29, 2022
@ghost
Copy link

ghost commented Sep 29, 2022

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 30 days of this comment.

@ghost ghost removed the no-recent-activity 📉 Open Issues that require attention label Sep 29, 2022
@Arlodotexe Arlodotexe assigned Arlodotexe and unassigned Arlodotexe Sep 30, 2022
@Arlodotexe
Copy link
Member

Arlodotexe commented Oct 5, 2022

@XamlBrewer Looks like the arrow keys only work when the Ctrl key is pressed, and only after reducing the StepSize

@XamlBrewer
Copy link
Contributor Author

XamlBrewer commented Oct 6, 2022

The default values for Minimum, Maximum, StepSize, SmallChange, and LargeChange are not ideal, but they did not change since 2018 (unless there was a change in RangeBase). So I do not understand how this PR can create a regression in this domain.

@XamlBrewer
Copy link
Contributor Author

XamlBrewer commented Oct 7, 2022

@Arlodotexe When you configure SmallChange and/or LargeChange to be smaller than the StepSize, then you can't change the Value using the arrow keys - since the result is rounded back to the original Value. To me, this is expected behavior. As a workaround we could use Max(*Change, StepSize) as increment or decrement in the keyboard accelerators. But then we're basically ignoring the property values set by the developer. How do other controls (like the Slider) deal with this?

@Arlodotexe
Copy link
Member

Arlodotexe commented Oct 7, 2022

As a workaround we could use Max(*Change, StepSize) as increment or decrement in the keyboard accelerators. But then we're basically ignoring the property values set by the developer. How do other controls (like the Slider) deal with this?

This line wasn't carried over during the refactor. I've pushed a commit that fixes the regression while using the new code.

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Behavior works the same as before, seems great! Thanks @XamlBrewer and @Arlodotexe for looking at this.

Just a quick thing I noticed around the event lifetime though. @Arlodotexe since it effects things outside this PR as well, let me know your thoughts on if we just want to snap this and then open another PR to fix the event registration?

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Discussed with team, opened #4784 to follow up this PR. But we're good to merge this one. Thanks!

@michael-hawker michael-hawker merged commit 06aec3e into CommunityToolkit:main Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants