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

Add event handler for user change of TabControl tab selection #6218

Merged
merged 12 commits into from Mar 21, 2024

Conversation

frenzibyte
Copy link
Member

@frenzibyte frenzibyte commented Mar 17, 2024

The abstraction may look a little bit too much, but I've been trying to find a middle-ground between code readability and simplicity of structure.

The previously existing SelectTab method is supposed to do all that's necessary for the tab selection to be changed, without necessarily being related to user action, so I've renamed it to UpdateTabSelection.

I've also introduced two methods, SelectTab and SelectItem, the former is for internal use by TabItem click event to update tab selection and trigger user event, meanwhile the latter is for external use by calling it with the target item to update tab selection and trigger user event as well (e.g. osu! calling the method when changing editor screen mode, so that an auxiliary sample is played).

I didn't want SelectTab to exist in the first place, but it's necessary so that the TabItem click event doesn't have to call SelectItem and perform an unnecessary lookup for an already known tab item, so that's why it's there.

@@ -378,10 +403,13 @@ private void selectTab(TabItem<T> tab)
/// </summary>
/// <param name="direction">Pass 1 to move to the next tab, or -1 to move to the previous tab.</param>
/// <param name="wrap">If <c>true</c>, moving past the start or the end of the tab list will wrap to the opposite end.</param>
public virtual void SwitchTab(int direction, bool wrap = true)
/// <returns>Whether tab selection has changed as a result of this call.</returns>
public virtual bool SwitchTab(int direction, bool wrap = true)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

So this method doesn't signal a user selection but SelectItem does? How does that make sense naming / exposure wise?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not realise this method is public, thought it was protected. We can signal the event from here and define a private version that's used by the "switch tab on remove" case.

The reason why I don't want the sound to play on the "switch tab on remove" scenario is because there would already be a sound played when the user removes the tab (e.g. a click sound on the "close" button).

@peppy peppy self-requested a review March 19, 2024 08:11
@@ -349,16 +352,37 @@ private void updateDropdown(TabItem<T> tab, bool isVisible)
}

/// <summary>
/// Selects a <see cref="TabItem{T}"/>.
/// Selects a <see cref="TabItem{T}"/> and signals an event that the user selected the given tab value via <see cref="OnUserTabSelectionChanged"/>.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I dunno about all these public events triggering the OnUserTabSelectionChanged method, but let's see how it works.

@peppy peppy self-requested a review March 20, 2024 14:41
peppy
peppy previously approved these changes Mar 20, 2024
@peppy
Copy link
Sponsor Member

peppy commented Mar 20, 2024

I've made further simplifications to convoluted logic. Requesting a second review.

@bdach bdach self-requested a review March 21, 2024 08:39
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

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

seems fine

@bdach bdach enabled auto-merge March 21, 2024 09:00
@bdach bdach merged commit 3f59b97 into ppy:master Mar 21, 2024
13 checks passed
@frenzibyte frenzibyte deleted the tab-control-user-events branch March 23, 2024 09:25
frenzibyte pushed a commit to frenzibyte/osu-framework that referenced this pull request Mar 24, 2024
Add event handler for user change of `TabControl` tab selection
frenzibyte pushed a commit to frenzibyte/osu-framework that referenced this pull request Mar 24, 2024
Add event handler for user change of `TabControl` tab selection
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.

None yet

3 participants