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

83 lines
2.3 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
2019-07-16 13:55:41 +08:00
using osu.Framework.Input;
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
{
2019-04-02 18:55:24 +08:00
Icon = FontAwesome.Solid.Search,
2018-04-13 17:19:50 +08:00
Origin = Anchor.CentreRight,
Anchor = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10 },
Size = new Vector2(20),
}
});
PlaceholderText = "type to search";
}
2019-07-16 13:55:41 +08:00
protected override bool HandleAction(PlatformAction action)
{
2019-07-23 12:25:03 +08:00
// Shift-delete is unnecessary for search inputs, so its propagated up the input queue.
2019-07-16 14:12:01 +08:00
if (action.ActionType == PlatformActionType.CharNext && action.ActionMethod == PlatformActionMethod.Delete)
2019-07-16 13:55:41 +08:00
return false;
return base.HandleAction(action);
}
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
}
}
}