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
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d31f52d
Add event triggered on `TabControl` selection change by user
frenzibyte 5d227b4
Fix event triggering when clicking same tab
frenzibyte ba661c7
Trigger user event change when directly calling `SwitchTab`
frenzibyte 26841b7
Add proper xmldoc to `UpdateTabSelection`
frenzibyte 7452bb6
Rename and privatise `UpdateTabSelection`
frenzibyte a3d6f0a
Fix xmldoc on public select method
peppy 14e1794
Simplify convoluted logic
peppy 645a648
Remove unused `virtual` spec on `SwitchTab`
peppy aefb4a9
Simplify logic further
peppy 5299198
Reorder private methods
peppy 48aa5e7
Add visual feedback to test scene
bdach 18e1221
Merge branch 'master' into tab-control-user-events
bdach File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
osu.Framework.Tests/Visual/UserInterface/TestSceneTabControlEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.UserInterface; | ||
using osu.Framework.Input; | ||
using osu.Framework.Testing; | ||
using osuTK; | ||
using osuTK.Input; | ||
|
||
namespace osu.Framework.Tests.Visual.UserInterface | ||
{ | ||
public partial class TestSceneTabControlEvents : ManualInputManagerTestScene | ||
{ | ||
private EventQueuesTabControl tabControl = null!; | ||
|
||
[SetUpSteps] | ||
public void SetUpSteps() | ||
{ | ||
AddStep("add tab control", () => Child = tabControl = new EventQueuesTabControl | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Size = new Vector2(150, 40), | ||
Items = Enum.GetValues<TestEnum>(), | ||
}); | ||
|
||
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0); | ||
} | ||
|
||
[Test] | ||
public void TestClickSendsEvent() | ||
{ | ||
AddStep("click second tab", () => | ||
{ | ||
InputManager.MoveMouseTo(this.ChildrenOfType<TabItem<TestEnum>>().ElementAt(1)); | ||
InputManager.Click(MouseButton.Left); | ||
}); | ||
|
||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second); | ||
} | ||
|
||
[Test] | ||
public void TestClickSameTabDoesNotSendEvent() | ||
{ | ||
AddAssert("first tab selected", () => tabControl.Current.Value == TestEnum.First); | ||
AddStep("click first tab", () => | ||
{ | ||
InputManager.MoveMouseTo(this.ChildrenOfType<TabItem<TestEnum>>().First()); | ||
InputManager.Click(MouseButton.Left); | ||
}); | ||
|
||
AddAssert("first tab still selected", () => tabControl.Current.Value == TestEnum.First); | ||
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0); | ||
} | ||
|
||
[Test] | ||
public void TestSelectItemMethodSendsEvent() | ||
{ | ||
AddStep("call select item", () => tabControl.SelectItem(TestEnum.Second)); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second); | ||
} | ||
|
||
[Test] | ||
public void TestSwitchTabMethodSendsEvent() | ||
{ | ||
AddStep("set switchable", () => tabControl.IsSwitchable = true); | ||
AddStep("call switch tab", () => tabControl.SwitchTab(1)); | ||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second); | ||
AddStep("call switch tab", () => tabControl.SwitchTab(-1)); | ||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.First); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.First); | ||
} | ||
|
||
[Test] | ||
public void TestSwitchUsingKeyBindingSendsEvent() | ||
{ | ||
AddStep("set switchable", () => tabControl.IsSwitchable = true); | ||
AddStep("switch forward", () => InputManager.Keys(PlatformAction.DocumentNext)); | ||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.Second); | ||
AddStep("switch backward", () => InputManager.Keys(PlatformAction.DocumentPrevious)); | ||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.First); | ||
AddAssert("selected tab queue has \"second\"", () => tabControl.UserTabSelectionChangedQueue.Dequeue().Value == TestEnum.First); | ||
} | ||
|
||
[Test] | ||
public void TestSwitchOnRemovalDoesNotSendEvent() | ||
{ | ||
AddStep("set switchable", () => tabControl.IsSwitchable = true); | ||
AddStep("remove first tab", () => tabControl.RemoveItem(TestEnum.First)); | ||
|
||
AddAssert("selected tab = second", () => tabControl.Current.Value == TestEnum.Second); | ||
AddAssert("selected tab queue still empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0); | ||
} | ||
|
||
[Test] | ||
public void TestBindableChangeDoesNotSendEvent() | ||
{ | ||
AddStep("set selected tab = second", () => tabControl.Current.Value = TestEnum.Second); | ||
AddAssert("selected tab queue still empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0); | ||
} | ||
|
||
[TearDownSteps] | ||
public void TearDownSteps() | ||
{ | ||
AddAssert("selected tab queue empty", () => tabControl.UserTabSelectionChangedQueue.Count == 0); | ||
} | ||
|
||
private partial class EventQueuesTabControl : BasicTabControl<TestEnum> | ||
{ | ||
public readonly Queue<TabItem<TestEnum>> UserTabSelectionChangedQueue = new Queue<TabItem<TestEnum>>(); | ||
|
||
protected override void OnUserTabSelectionChanged(TabItem<TestEnum> item) => UserTabSelectionChangedQueue.Enqueue(item); | ||
} | ||
|
||
private enum TestEnum | ||
{ | ||
First, | ||
Second, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.