Change ways to access submit button state

This commit is contained in:
ansel 2022-11-29 14:37:35 +03:00
parent 6c126f5223
commit 84aaf5fedf
2 changed files with 16 additions and 17 deletions

View File

@ -52,7 +52,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("press Enter", () => InputManager.Key(Key.Enter)); AddStep("press Enter", () => InputManager.Key(Key.Enter));
AddAssert("text committed", () => commentEditor.CommittedText == "text"); AddAssert("text committed", () => commentEditor.CommittedText == "text");
AddAssert("button is loading", () => commentEditor.IsLoading); AddAssert("button is loading", () => commentEditor.IsSubmitting);
} }
[Test] [Test]
@ -67,7 +67,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("press Enter", () => InputManager.Key(Key.Enter)); AddStep("press Enter", () => InputManager.Key(Key.Enter));
AddAssert("no text committed", () => commentEditor.CommittedText.Length == 0); AddAssert("no text committed", () => commentEditor.CommittedText.Length == 0);
AddAssert("button is not loading", () => !commentEditor.IsLoading); AddAssert("button is not loading", () => !commentEditor.IsSubmitting);
} }
[Test] [Test]
@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual.UserInterface
}); });
AddAssert("text committed", () => commentEditor.CommittedText == "some other text"); AddAssert("text committed", () => commentEditor.CommittedText == "some other text");
AddAssert("button is loading", () => commentEditor.IsLoading); AddAssert("button is loading", () => commentEditor.IsSubmitting);
} }
[Test] [Test]
@ -116,9 +116,9 @@ namespace osu.Game.Tests.Visual.UserInterface
private void onCommit(string value) private void onCommit(string value)
{ {
IsLoading = true; CommitButton.IsLoading = true;
CommittedText = value; CommittedText = value;
Scheduler.AddDelayed(() => IsLoading = false, 1000); Scheduler.AddDelayed(() => CommitButton.IsLoading = false, 1000);
} }
protected override LocalisableString FooterText => @"Footer text. And it is pretty long. Cool."; protected override LocalisableString FooterText => @"Footer text. And it is pretty long. Cool.";

View File

@ -25,11 +25,10 @@ namespace osu.Game.Overlays.Comments
public Action<string>? OnCommit; public Action<string>? OnCommit;
public bool IsLoading /// <summary>
{ /// Is the editor waiting for submit action to complete?
get => commitButton.IsLoading; /// </summary>
set => commitButton.IsLoading = value; public bool IsSubmitting => CommitButton.IsLoading;
}
protected abstract LocalisableString FooterText { get; } protected abstract LocalisableString FooterText { get; }
@ -41,7 +40,7 @@ namespace osu.Game.Overlays.Comments
protected readonly Bindable<string> Current = new Bindable<string>(); protected readonly Bindable<string> Current = new Bindable<string>();
private CommitButton commitButton = null!; protected EditorCommitButton CommitButton = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
@ -99,7 +98,7 @@ namespace osu.Game.Overlays.Comments
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
Spacing = new Vector2(5, 0), Spacing = new Vector2(5, 0),
Child = commitButton = new CommitButton Child = CommitButton = new EditorCommitButton
{ {
Text = CommitButtonText, Text = CommitButtonText,
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
@ -119,10 +118,10 @@ namespace osu.Game.Overlays.Comments
textBox.OnCommit += (_, _) => textBox.OnCommit += (_, _) =>
{ {
if (commitButton.IsLoading) if (CommitButton.IsLoading)
return; return;
commitButton.TriggerClick(); CommitButton.TriggerClick();
}; };
} }
@ -130,7 +129,7 @@ namespace osu.Game.Overlays.Comments
{ {
base.LoadComplete(); base.LoadComplete();
Current.BindValueChanged(text => commitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true); Current.BindValueChanged(text => CommitButton.IsBlocked.Value = string.IsNullOrEmpty(text.NewValue), true);
} }
private partial class EditorTextBox : BasicTextBox private partial class EditorTextBox : BasicTextBox
@ -167,7 +166,7 @@ namespace osu.Game.Overlays.Comments
}; };
} }
private sealed partial class CommitButton : RoundedButton protected sealed partial class EditorCommitButton : RoundedButton
{ {
private const int duration = 200; private const int duration = 200;
@ -190,7 +189,7 @@ namespace osu.Game.Overlays.Comments
} }
} }
public CommitButton() public EditorCommitButton()
{ {
Height = 25; Height = 25;
AutoSizeAxes = Axes.X; AutoSizeAxes = Axes.X;