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

animate long press latching #12990

Merged
merged 6 commits into from
Apr 20, 2024
Merged

animate long press latching #12990

merged 6 commits into from
Apr 20, 2024

Conversation

m0dB
Copy link
Contributor

@m0dB m0dB commented Mar 22, 2024

Animate long press latching (e.g. sync button) by capture the off-state in a pixmap and during the long press latch time, gradually draw less of it.

longpresslatching.mov

@github-actions github-actions bot added the ui label Mar 22, 2024
@JoergAtGithub
Copy link
Member

I just tested this on Windows11, and the buttons appear fluidly animated and make the long press behavior really easier to understand.
And even for me as a experienced user, who is aware about the long press sync button functionality, it simplifies the use, because now I see how long I need to hold the button.

@m0dB
Copy link
Contributor Author

m0dB commented Mar 23, 2024

Great! Happy you like it, and thanks for validating!

@m0dB m0dB requested a review from ronso0 March 23, 2024 15:43
@m0dB
Copy link
Contributor Author

m0dB commented Mar 23, 2024

@daschuer @Swiftb0y @ronso0 could you test on linux?

Any objections against this approach?

Copy link
Member

@acolombier acolombier left a comment

Choose a reason for hiding this comment

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

Looking nice and smooth on Linux (PopOs 22.04 Wayland)

Kooha-2024-03-23-22-17-07.mp4

@m0dB
Copy link
Contributor Author

m0dB commented Mar 23, 2024

Thanks, Antoine!

Copy link
Member

@ywwg ywwg left a comment

Choose a reason for hiding this comment

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

my main note is that this gives every single pushbutton in the UI the latching logic and support objects even if they are never used. Would it be possible to make this a child object of a pushbutton (WPushButtonLatching) that inherits WPushButton and just adds on the new stuff? I think that would also be cleaner from a skin design perspective.

m_preLongPressPixmap.setDevicePixelRatio(devicePixelRatio());
paintOnDevice(&m_preLongPressPixmap);
// ... and start the long press latching animation
m_animTimer.start(1000 / 60);
Copy link
Member

Choose a reason for hiding this comment

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

if I understand correctly, this creates an independent 60fps timer to update this animation. Would it be possible / feasible to connect instead to the global UI update timer? or does it not really matter because it's just updating the position data, and the drawing is done elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doesn't matter. The overhead of the timer is minimal and it doesn't do the actual drawing, it just triggers the drawing when Qt sees fit. This is the recommended way.

@ronso0
Copy link
Member

ronso0 commented Mar 26, 2024

my main note is that this gives every single pushbutton in the UI the latching logic and support objects even if they are never used.

These objects / connections can be created only if m_leftButtonMode == ControlPushButton::LONGPRESSLATCHING in setup()?

@m0dB
Copy link
Contributor Author

m0dB commented Mar 26, 2024

my main note is that this gives every single pushbutton in the UI the latching logic and support objects even if they are never used. Would it be possible to make this a child object of a pushbutton (WPushButtonLatching) that inherits WPushButton and just adds on the new stuff? I think that would also be cleaner from a skin design perspective.

It would be possible but IMO this would lead to added complexity in the code rather than the opposite. Also, WPushButton already implements several modes / behaviours as it is, so why only isolating this one? The added overhead is minimal.

Also, as far as I remember, the skin parser is not instantiating different classes based on properties anywhere, so it would be strange to add that only for this particular case.

But I see your objection that this does add code to WPushButton that is only used for a very specific use case. What I could do is place the QTimer, the QPixmap, and the latching related code in a class that is a member of WPushButton, reducing the overhead to an std::unique_ptr and some function calls.

@m0dB m0dB requested a review from ywwg March 26, 2024 15:46
@m0dB
Copy link
Contributor Author

m0dB commented Mar 26, 2024

my main note is that this gives every single pushbutton in the UI the latching logic and support objects even if they are never used.

These objects / connections can be created only if m_leftButtonMode == ControlPushButton::LONGPRESSLATCHING in setup()?

Yes.

I have moved the code and objects to nested class WPushButton::LongPressLatching, which is a instantiated as member std::unique<LongPressLatching> m_pLongPressLatching only if m_leftButtonMode == ControlPushButton::LONGPRESSLATCHING.

@fwcd let me know if this addresses your concerns.

@fwcd
Copy link
Member

fwcd commented Mar 26, 2024

I think you wanted to ping @ywwg? 😄

@m0dB
Copy link
Contributor Author

m0dB commented Mar 26, 2024

Indeed! All those 4 letter usernames! 😅

Copy link
Member

@ywwg ywwg left a comment

Choose a reason for hiding this comment

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

I like this refactor! I agree since wpushbutton already does a lot of things it doesn't make sense to create a subclass. thanks.

One more question, is the animation triggered when someone long-presses on a controller? I am guessing right now it only works when initiated with the UI and a mouse. It seems out of scope for this PR to implement this for controllers but we probably want to do that too

QVector<int> m_align;

class LongPressLatching {
Copy link
Member

Choose a reason for hiding this comment

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

please add an explanatory comment for this new class that summarizes the feature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment added. If you find it's sufficient, could you merge this? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

@daschuer is the last outstanding reviewer

@m0dB m0dB added this to the 2.4.1 milestone Apr 7, 2024
@daschuer
Copy link
Member

/home/daniel/workspace/mixxx2/src/widget/wpushbutton.h:134:10: error: ‘unique_ptr’ in namespace ‘std’ does not name a template type
  134 |     std::unique_ptr<LongPressLatching> m_pLongPressLatching;
      |          ^~~~~~~~~~

#include <memory> is missing.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

I can confirm it is working nice after adding the include.

@ronso0
Copy link
Member

ronso0 commented Apr 19, 2024

@daschuer Okay to merge?

@daschuer
Copy link
Member

After adding the missing include, yes.

@m0dB m0dB merged commit d20b804 into mixxxdj:2.4 Apr 20, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants