Skip to content

Commit 54a23fb

Browse files
committed
Move ManualTextInput to a separate class
1 parent 09a14e1 commit 54a23fb

File tree

3 files changed

+59
-49
lines changed

3 files changed

+59
-49
lines changed

osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxEvents.cs

+4-48
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using osu.Framework.Graphics.UserInterface;
1313
using osu.Framework.Input;
1414
using osu.Framework.Testing;
15+
using osu.Framework.Testing.Input;
1516
using osuTK;
1617
using osuTK.Input;
1718

@@ -20,7 +21,7 @@ namespace osu.Framework.Tests.Visual.UserInterface
2021
public partial class TestSceneTextBoxEvents : ManualInputManagerTestScene
2122
{
2223
private EventQueuesTextBox textBox;
23-
private ManualTextInput textInput;
24+
private ManualTextInputSource textInput;
2425
private ManualTextInputContainer textInputContainer;
2526

2627
private const string default_text = "some default text";
@@ -618,57 +619,12 @@ protected override void OnImeResult(string result, bool successful) =>
618619
public partial class ManualTextInputContainer : Container
619620
{
620621
[Cached(typeof(TextInputSource))]
621-
public readonly ManualTextInput TextInput;
622+
public readonly ManualTextInputSource TextInput;
622623

623624
public ManualTextInputContainer()
624625
{
625626
RelativeSizeAxes = Axes.Both;
626-
TextInput = new ManualTextInput();
627-
}
628-
}
629-
630-
public class ManualTextInput : TextInputSource
631-
{
632-
public void Text(string text) => TriggerTextInput(text);
633-
634-
public new void TriggerImeComposition(string text, int start, int length)
635-
{
636-
base.TriggerImeComposition(text, start, length);
637-
}
638-
639-
public new void TriggerImeResult(string text)
640-
{
641-
base.TriggerImeResult(text);
642-
}
643-
644-
public override void ResetIme()
645-
{
646-
base.ResetIme();
647-
648-
// this call will be somewhat delayed in a real world scenario, but let's run it immediately for simplicity.
649-
base.TriggerImeComposition(string.Empty, 0, 0);
650-
}
651-
652-
public readonly Queue<bool> ActivationQueue = new Queue<bool>();
653-
public readonly Queue<bool> EnsureActivatedQueue = new Queue<bool>();
654-
public readonly Queue<bool> DeactivationQueue = new Queue<bool>();
655-
656-
protected override void ActivateTextInput(bool allowIme)
657-
{
658-
base.ActivateTextInput(allowIme);
659-
ActivationQueue.Enqueue(allowIme);
660-
}
661-
662-
protected override void EnsureTextInputActivated(bool allowIme)
663-
{
664-
base.EnsureTextInputActivated(allowIme);
665-
EnsureActivatedQueue.Enqueue(allowIme);
666-
}
667-
668-
protected override void DeactivateTextInput()
669-
{
670-
base.DeactivateTextInput();
671-
DeactivationQueue.Enqueue(true);
627+
TextInput = new ManualTextInputSource();
672628
}
673629
}
674630

osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxKeyEvents.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using osu.Framework.Input.Events;
1212
using osu.Framework.Platform;
1313
using osu.Framework.Testing;
14+
using osu.Framework.Testing.Input;
1415
using osuTK;
1516
using osuTK.Input;
1617

@@ -20,7 +21,7 @@ public partial class TestSceneTextBoxKeyEvents : ManualInputManagerTestScene
2021
{
2122
private KeyEventQueuesTextBox textBox;
2223

23-
private TestSceneTextBoxEvents.ManualTextInput textInput;
24+
private ManualTextInputSource textInput;
2425

2526
[Resolved]
2627
private GameHost host { get; set; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using System.Collections.Generic;
5+
using osu.Framework.Input;
6+
7+
namespace osu.Framework.Testing.Input
8+
{
9+
public class ManualTextInputSource : TextInputSource
10+
{
11+
public readonly Queue<bool> ActivationQueue = new Queue<bool>();
12+
public readonly Queue<bool> EnsureActivatedQueue = new Queue<bool>();
13+
public readonly Queue<bool> DeactivationQueue = new Queue<bool>();
14+
15+
public void Text(string text) => TriggerTextInput(text);
16+
17+
public new void TriggerImeComposition(string text, int start, int length)
18+
{
19+
base.TriggerImeComposition(text, start, length);
20+
}
21+
22+
public new void TriggerImeResult(string text)
23+
{
24+
base.TriggerImeResult(text);
25+
}
26+
27+
public override void ResetIme()
28+
{
29+
base.ResetIme();
30+
31+
// this call will be somewhat delayed in a real world scenario, but let's run it immediately for simplicity.
32+
base.TriggerImeComposition(string.Empty, 0, 0);
33+
}
34+
35+
protected override void ActivateTextInput(bool allowIme)
36+
{
37+
base.ActivateTextInput(allowIme);
38+
ActivationQueue.Enqueue(allowIme);
39+
}
40+
41+
protected override void EnsureTextInputActivated(bool allowIme)
42+
{
43+
base.EnsureTextInputActivated(allowIme);
44+
EnsureActivatedQueue.Enqueue(allowIme);
45+
}
46+
47+
protected override void DeactivateTextInput()
48+
{
49+
base.DeactivateTextInput();
50+
DeactivationQueue.Enqueue(true);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)