1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 23:47:24 +08:00
osu-lazer/osu.Game/Overlays/Settings/SettingsTextBox.cs

61 lines
1.7 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
2021-06-12 23:34:02 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
2021-06-12 23:34:02 +08:00
using osu.Framework.Input.Events;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.UserInterface;
2021-06-12 23:34:02 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Settings
{
public class SettingsTextBox : SettingsItem<string>
{
2021-06-13 00:37:31 +08:00
protected override Drawable CreateControl() => new TextBox
2018-11-15 05:29:11 +08:00
{
Margin = new MarginPadding { Top = 5 },
RelativeSizeAxes = Axes.X,
CommitOnFocusLost = true,
2018-11-15 05:29:11 +08:00
};
2021-06-12 23:34:02 +08:00
2021-06-13 00:37:31 +08:00
public class TextBox : OsuTextBox
2021-06-12 23:34:02 +08:00
{
private const float border_thickness = 3;
private Color4 borderColourFocused;
private Color4 borderColourUnfocused;
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
borderColourUnfocused = colour.Gray4.Opacity(0.5f);
borderColourFocused = BorderColour;
updateBorder();
}
protected override void OnFocus(FocusEvent e)
{
base.OnFocus(e);
updateBorder();
}
protected override void OnFocusLost(FocusLostEvent e)
{
base.OnFocusLost(e);
updateBorder();
}
private void updateBorder()
{
BorderThickness = border_thickness;
BorderColour = HasFocus ? borderColourFocused : borderColourUnfocused;
}
}
2018-04-13 17:19:50 +08:00
}
}