1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 15:32:56 +08:00
osu-lazer/osu.Game/Graphics/UserInterfaceV2/LabelledTextBox.cs
2022-05-17 17:42:46 +09:00

72 lines
2.0 KiB
C#

// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Graphics.UserInterfaceV2
{
public class LabelledTextBox : LabelledComponent<OsuTextBox, string>
{
public event TextBox.OnCommitHandler OnCommit;
public LabelledTextBox()
: base(false)
{
}
public bool ReadOnly
{
get => Component.ReadOnly;
set => Component.ReadOnly = value;
}
public LocalisableString PlaceholderText
{
set => Component.PlaceholderText = value;
}
public string Text
{
set => Component.Text = value;
}
public CompositeDrawable TabbableContentContainer
{
set => Component.TabbableContentContainer = value;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Component.BorderColour = colours.Blue;
}
protected virtual OsuTextBox CreateTextBox() => new OsuTextBox();
public override bool AcceptsFocus => true;
protected override void OnFocus(FocusEvent e)
{
base.OnFocus(e);
GetContainingInputManager().ChangeFocus(Component);
}
protected override OsuTextBox CreateComponent() => CreateTextBox().With(t =>
{
t.CommitOnFocusLost = true;
t.Anchor = Anchor.Centre;
t.Origin = Anchor.Centre;
t.RelativeSizeAxes = Axes.X;
t.CornerRadius = CORNER_RADIUS;
t.OnCommit += (sender, newText) => OnCommit?.Invoke(sender, newText);
});
}
}