1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 20:57:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/SearchTextBox.cs

72 lines
1.8 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
public class SearchTextBox : FocusedTextBox
{
protected virtual bool AllowCommit => false;
public override bool HandleLeftRightArrows => false;
public SearchTextBox()
{
Height = 35;
AddRange(new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.fa_search,
Origin = Anchor.CentreRight,
Anchor = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10 },
Size = new Vector2(20),
}
});
PlaceholderText = "type to search";
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2018-04-13 17:19:50 +08:00
{
if (!e.ControlPressed && !e.ShiftPressed)
2018-04-13 17:19:50 +08:00
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
2018-04-13 17:19:50 +08:00
{
case Key.Left:
case Key.Right:
case Key.Up:
case Key.Down:
return false;
}
}
if (!AllowCommit)
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
2018-04-13 17:19:50 +08:00
{
case Key.KeypadEnter:
case Key.Enter:
return false;
}
}
if (e.ShiftPressed)
2018-04-13 17:19:50 +08:00
{
2018-10-02 11:02:47 +08:00
switch (e.Key)
2018-04-13 17:19:50 +08:00
{
case Key.Delete:
return false;
}
}
2018-10-02 11:02:47 +08:00
return base.OnKeyDown(e);
2018-04-13 17:19:50 +08:00
}
}
}