2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-07-16 05:55:41 +00:00
|
|
|
|
using osu.Framework.Input;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class SearchTextBox : FocusedTextBox
|
|
|
|
|
{
|
|
|
|
|
protected virtual bool AllowCommit => false;
|
|
|
|
|
|
|
|
|
|
public SearchTextBox()
|
|
|
|
|
{
|
|
|
|
|
Height = 35;
|
2020-02-18 14:40:12 +00:00
|
|
|
|
Add(new SpriteIcon
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-02-18 14:40:12 +00:00
|
|
|
|
Icon = FontAwesome.Solid.Search,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
|
Size = new Vector2(20),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-02-18 14:40:12 +00:00
|
|
|
|
TextFlow.Padding = new MarginPadding { Right = 35 };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
PlaceholderText = "type to search";
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-23 06:31:09 +00:00
|
|
|
|
public override bool OnPressed(PlatformAction action)
|
2019-07-16 05:55:41 +00:00
|
|
|
|
{
|
2019-12-30 17:29:46 +00:00
|
|
|
|
switch (action.ActionType)
|
|
|
|
|
{
|
|
|
|
|
case PlatformActionType.LineEnd:
|
|
|
|
|
case PlatformActionType.LineStart:
|
|
|
|
|
return false;
|
2019-12-30 17:38:22 +00:00
|
|
|
|
|
|
|
|
|
// Shift+delete is handled via PlatformAction on macOS. this is not so useful in the context of a SearchTextBox
|
|
|
|
|
// as we do not allow arrow key navigation in the first place (ie. the caret should always be at the end of text)
|
|
|
|
|
// Avoid handling it here to allow other components to potentially consume the shortcut.
|
|
|
|
|
case PlatformActionType.CharNext:
|
|
|
|
|
if (action.ActionMethod == PlatformActionMethod.Delete)
|
|
|
|
|
return false;
|
2019-12-30 17:49:34 +00:00
|
|
|
|
|
2019-12-30 17:38:22 +00:00
|
|
|
|
break;
|
2019-12-30 17:29:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-23 06:31:09 +00:00
|
|
|
|
return base.OnPressed(action);
|
2019-07-16 05:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-10-02 03:44:14 +00:00
|
|
|
|
if (!e.ControlPressed && !e.ShiftPressed)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
switch (e.Key)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
case Key.Left:
|
|
|
|
|
case Key.Right:
|
|
|
|
|
case Key.Up:
|
|
|
|
|
case Key.Down:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AllowCommit)
|
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
switch (e.Key)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
case Key.KeypadEnter:
|
|
|
|
|
case Key.Enter:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:44:14 +00:00
|
|
|
|
if (e.ShiftPressed)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
switch (e.Key)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
case Key.Delete:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|