Skip to content

Commit

Permalink
Merge pull request ppy#18220 from frenzibyte/control-popover-focus
Browse files Browse the repository at this point in the history
Focus textbox upon opening control point popovers
  • Loading branch information
peppy authored May 11, 2022
2 parents 52c8382 + d51689e commit 5800d7e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
Expand Down Expand Up @@ -66,6 +67,13 @@ public override void SetUpSteps()
});
}

[Test]
public void TestPopoverHasFocus()
{
clickDifficultyPiece(0);
velocityPopoverHasFocus();
}

[Test]
public void TestSingleSelection()
{
Expand Down Expand Up @@ -133,6 +141,15 @@ private void clickDifficultyPiece(int objectIndex) => AddStep($"click {objectInd
InputManager.Click(MouseButton.Left);
});

private void velocityPopoverHasFocus() => AddUntilStep("velocity popover textbox focused", () =>
{
var popover = this.ChildrenOfType<DifficultyPointPiece.DifficultyEditPopover>().SingleOrDefault();
var slider = popover?.ChildrenOfType<IndeterminateSliderWithTextBoxInput<double>>().Single();
var textbox = slider?.ChildrenOfType<OsuTextBox>().Single();

return textbox?.HasFocus == true;
});

private void velocityPopoverHasSingleValue(double velocity) => AddUntilStep($"velocity popover has {velocity}", () =>
{
var popover = this.ChildrenOfType<DifficultyPointPiece.DifficultyEditPopover>().SingleOrDefault();
Expand All @@ -151,6 +168,7 @@ private void velocityPopoverHasIndeterminateValue() => AddUntilStep("velocity po

private void dismissPopover()
{
AddStep("unfocus textbox", () => InputManager.Key(Key.Escape));
AddStep("dismiss popover", () => InputManager.Key(Key.Escape));
AddUntilStep("wait for dismiss", () => !this.ChildrenOfType<DifficultyPointPiece.DifficultyEditPopover>().Any(popover => popover.IsPresent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public override void SetUpSteps()
});
}

[Test]
public void TestPopoverHasFocus()
{
clickSamplePiece(0);
samplePopoverHasFocus();
}

[Test]
public void TestSingleSelection()
{
Expand Down Expand Up @@ -173,14 +180,23 @@ public void TestMultipleSelectionWithDifferentSampleBank()
samplePopoverHasSingleBank("normal");
}

private void clickSamplePiece(int objectIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} difficulty piece", () =>
private void clickSamplePiece(int objectIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} sample piece", () =>
{
var difficultyPiece = this.ChildrenOfType<SamplePointPiece>().Single(piece => piece.HitObject == EditorBeatmap.HitObjects.ElementAt(objectIndex));
var samplePiece = this.ChildrenOfType<SamplePointPiece>().Single(piece => piece.HitObject == EditorBeatmap.HitObjects.ElementAt(objectIndex));

InputManager.MoveMouseTo(difficultyPiece);
InputManager.MoveMouseTo(samplePiece);
InputManager.Click(MouseButton.Left);
});

private void samplePopoverHasFocus() => AddUntilStep("sample popover textbox focused", () =>
{
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
var slider = popover?.ChildrenOfType<IndeterminateSliderWithTextBoxInput<int>>().Single();
var textbox = slider?.ChildrenOfType<OsuTextBox>().Single();

return textbox?.HasFocus == true;
});

private void samplePopoverHasSingleVolume(int volume) => AddUntilStep($"sample popover has volume {volume}", () =>
{
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
Expand Down Expand Up @@ -215,8 +231,9 @@ private void samplePopoverHasIndeterminateBank() => AddUntilStep("sample popover

private void dismissPopover()
{
AddStep("unfocus textbox", () => InputManager.Key(Key.Escape));
AddStep("dismiss popover", () => InputManager.Key(Key.Escape));
AddUntilStep("wait for dismiss", () => !this.ChildrenOfType<DifficultyPointPiece.DifficultyEditPopover>().Any(popover => popover.IsPresent));
AddUntilStep("wait for dismiss", () => !this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().Any(popover => popover.IsPresent));
}

private void setVolumeViaPopover(int volume) => AddStep($"set volume {volume} via popover", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ private void load()
beatmap.EndChange();
});
}

protected override void LoadComplete()
{
base.LoadComplete();
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(sliderVelocitySlider));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ private void load()
volume.Current.BindValueChanged(val => updateVolumeFor(relevantObjects, val.NewValue));
}

protected override void LoadComplete()
{
base.LoadComplete();
ScheduleAfterChildren(() => GetContainingInputManager().ChangeFocus(volume));
}

private static string? getCommonBank(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleBank).Distinct().Count() == 1 ? relevantControlPoints.First().SampleBank : null;
private static int? getCommonVolume(SampleControlPoint[] relevantControlPoints) => relevantControlPoints.Select(point => point.SampleVolume).Distinct().Count() == 1 ? (int?)relevantControlPoints.First().SampleVolume : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays.Settings;
Expand Down Expand Up @@ -107,6 +108,14 @@ public IndeterminateSliderWithTextBoxInput(LocalisableString labelText, Bindable
Current.BindValueChanged(_ => updateState(), true);
}

public override bool AcceptsFocus => true;

protected override void OnFocus(FocusEvent e)
{
base.OnFocus(e);
GetContainingInputManager().ChangeFocus(textBox);
}

private void updateState()
{
if (Current.Value is T nonNullValue)
Expand Down

0 comments on commit 5800d7e

Please sign in to comment.