Skip to content

Conversation

Warchamp7
Copy link
Member

Description

Adds a new widget called SlidingStackedWidget that performs a sliding animation when switching between pages.

This is heavily based on the work in https://github.com/timschneeb/SlidingStackedWidget with a couple functionality tweaks, and adjustments to match our naming conventions. The biggest changes compared to the original widget in the repo above is to allow SlidingStackedWidget to be a completely transparent drop-in replacement for QStackedWidget. This is accomplished by overriding the normal QStackedWidget methods for changing pages, and adding handling for changing pages during the animation.

Note

This preview is for demonstration purposes only.

This PR does NOT update the settings window to use this sliding widget and there are no intentions to do so.

obs64_yDHmTWiq5v.mp4

Motivation and Context

Planning to use this in future UI updates around onboarding and certain configuration windows.

How Has This Been Tested?

Changed the settings window QStackedWidget to use this instead and ensured it behaved as expected.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

int nextIndex = indexOf(newWidget);

if (isAnimating) {
/* Avoid interrupting animation if trying to advance from and to the same indexes */
Copy link
Member

Choose a reason for hiding this comment

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

This should be a C++-style comment in my opinion, but this is not spelt-out by the code style guidelines that unfortunately can only cover pure C code (as those are based on the Linux kernel guidelines).

The C++ style is part of the language reference doc, but makes functionally no difference, so it's entirely a question of code style.

Right now we don't have any C++ code style guidelines (because the kernel guidelines can only cover C) so we have to introduce some. And in that case I'd vote to use C++-style comments in C++ code as an informal agreement until we have C++ style guidelines in writing.

Q_OBJECT

public:
enum SlideDirection { LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP, AUTOMATIC };
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
enum SlideDirection { LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP, AUTOMATIC };
enum class SlideDirection { SlideInvalid, SlideLeftToRight, SlideRightToLeft, SlideTopToBottom, SlideBottomToTop, SlideAutomatic };

Use class enum for type safety, use less generic names that spell out their meaning even by just looking at the value in isolation, ensure that uninitialised default value is never a "valid" value, so that it always has to be set/initialised explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't Slide be redundant as a prefix since I would generally expect these values to be used as Ex. SlideDirection::LeftToRight?

Copy link
Member

Choose a reason for hiding this comment

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

True, also if it's part of the widget's API, you get additional context.

SlidingStackedWidget::Direction::LeftToRight (as its full name would be) provides enough context I'd like to think.

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

Successfully merging this pull request may close these issues.

2 participants