From ddea76927f4370325fe62c42952be839e900f55d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 3 Feb 2017 19:12:57 +0900 Subject: [PATCH] Better SearchTextBox focus handling. --- osu.Game/Screens/Select/FilterControl.cs | 4 ++-- osu.Game/Screens/Select/SearchTextBox.cs | 26 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 9050b9b4cb..3b657673e6 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -61,13 +61,13 @@ namespace osu.Game.Screens.Select public void Deactivate() { - searchTextBox.GrabFocus = false; + searchTextBox.HoldFocus = false; searchTextBox.TriggerFocusLost(); } public void Activate() { - searchTextBox.GrabFocus = true; + searchTextBox.HoldFocus = true; } private class TabItem : ClickableContainer diff --git a/osu.Game/Screens/Select/SearchTextBox.cs b/osu.Game/Screens/Select/SearchTextBox.cs index 9428fe7f32..e8717b40fd 100644 --- a/osu.Game/Screens/Select/SearchTextBox.cs +++ b/osu.Game/Screens/Select/SearchTextBox.cs @@ -17,8 +17,19 @@ namespace osu.Game.Screens.Select protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255); protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255); public Action Exit; - public bool GrabFocus = false; - + + private bool focus; + public bool HoldFocus + { + get { return focus; } + set + { + focus = value; + if (!focus) + TriggerFocusLost(); + } + } + private SpriteText placeholder; protected override string InternalText @@ -36,7 +47,7 @@ namespace osu.Game.Screens.Select } } } - + public SearchTextBox() { Height = 35; @@ -61,21 +72,20 @@ namespace osu.Game.Screens.Select } }); } - + protected override void Update() { - if (GrabFocus && !HasFocus && IsVisible) - TriggerFocus(); + if (HoldFocus) RequestFocus(); base.Update(); } - + protected override void OnFocusLost(InputState state) { if (state.Keyboard.Keys.Any(key => key == Key.Escape)) Exit?.Invoke(); base.OnFocusLost(state); } - + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (args.Key == Key.Left || args.Key == Key.Right || args.Key == Key.Enter)