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

66 lines
1.9 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK.Input;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
/// A textbox which holds focus eagerly.
/// </summary>
2017-02-19 16:59:22 +08:00
public class SearchTextBox : FocusedTextBox
{
protected virtual bool AllowCommit => false;
public SearchTextBox()
{
Height = 35;
Add(new Drawable[]
{
new TextAwesome
{
Icon = FontAwesome.fa_search,
Origin = Anchor.CentreRight,
Anchor = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10 },
TextSize = 20
}
});
2017-02-08 13:01:17 +08:00
PlaceholderText = "type to search";
}
2017-02-03 18:12:57 +08:00
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (HandlePendingText(state)) return true;
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
{
switch (args.Key)
{
case Key.Left:
case Key.Right:
case Key.Up:
case Key.Down:
return false;
case Key.Enter:
if (!AllowCommit) return false;
break;
}
}
if (state.Keyboard.ShiftPressed)
{
switch (args.Key)
{
case Key.Delete:
return false;
}
}
return base.OnKeyDown(state, args);
}
}
}