2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 12:59:30 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-01-30 23:16:55 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-03 13:36:21 +08:00
|
|
|
|
using OpenTK;
|
2017-05-12 18:57:06 +08:00
|
|
|
|
using OpenTK.Input;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
|
2017-05-12 18:57:06 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
2017-01-11 06:43:00 +08:00
|
|
|
|
{
|
2017-02-19 16:59:22 +08:00
|
|
|
|
public class SearchTextBox : FocusedTextBox
|
2017-01-11 06:43:00 +08:00
|
|
|
|
{
|
2017-05-05 12:59:24 +08:00
|
|
|
|
protected virtual bool AllowCommit => false;
|
|
|
|
|
|
2017-01-11 06:43:00 +08:00
|
|
|
|
public SearchTextBox()
|
|
|
|
|
{
|
|
|
|
|
Height = 35;
|
2017-07-11 21:58:06 +08:00
|
|
|
|
AddRange(new Drawable[]
|
2017-01-11 06:43:00 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
new SpriteIcon
|
2017-01-11 06:43:00 +08:00
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_search,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(20),
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-02-08 13:01:17 +08:00
|
|
|
|
|
|
|
|
|
PlaceholderText = "type to search";
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-01-30 23:16:55 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-02-09 11:33:24 +08:00
|
|
|
|
if (HandlePendingText(state)) return true;
|
|
|
|
|
|
2017-02-08 14:30:20 +08:00
|
|
|
|
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Left:
|
|
|
|
|
case Key.Right:
|
|
|
|
|
case Key.Up:
|
|
|
|
|
case Key.Down:
|
|
|
|
|
return false;
|
2017-07-18 17:40:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AllowCommit)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
|
{
|
2017-06-16 05:06:28 +08:00
|
|
|
|
case Key.KeypadEnter:
|
2017-05-05 12:59:24 +08:00
|
|
|
|
case Key.Enter:
|
2017-07-18 17:40:34 +08:00
|
|
|
|
return false;
|
2017-02-08 14:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 19:01:44 +08:00
|
|
|
|
if (state.Keyboard.ShiftPressed)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Delete:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 23:16:55 +08:00
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
2018-01-05 19:21:19 +08:00
|
|
|
|
}
|