2019-01-24 16:43:03 +08:00
|
|
|
|
// 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-07-20 18:05:19 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-07-25 17:38:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-09-08 18:51:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-07-25 17:34:47 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-03-17 15:56:58 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2022-05-17 16:42:46 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2018-07-24 14:46:24 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
|
2019-09-24 18:00:26 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2019-10-28 14:33:08 +08:00
|
|
|
|
public class LabelledTextBox : LabelledComponent<OsuTextBox, string>
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-25 17:34:47 +08:00
|
|
|
|
public event TextBox.OnCommitHandler OnCommit;
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2019-09-20 17:50:50 +08:00
|
|
|
|
public LabelledTextBox()
|
|
|
|
|
: base(false)
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2019-09-20 17:50:50 +08:00
|
|
|
|
public bool ReadOnly
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2021-06-11 02:34:52 +08:00
|
|
|
|
get => Component.ReadOnly;
|
2019-09-20 17:50:50 +08:00
|
|
|
|
set => Component.ReadOnly = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2022-05-17 16:42:46 +08:00
|
|
|
|
public LocalisableString PlaceholderText
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2019-09-20 17:50:50 +08:00
|
|
|
|
set => Component.PlaceholderText = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 20:44:10 +08:00
|
|
|
|
public string Text
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2019-09-20 17:50:50 +08:00
|
|
|
|
set => Component.Text = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 17:38:50 +08:00
|
|
|
|
|
2022-03-06 08:43:56 +08:00
|
|
|
|
public CompositeDrawable TabbableContentContainer
|
2020-09-08 18:51:31 +08:00
|
|
|
|
{
|
|
|
|
|
set => Component.TabbableContentContainer = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 17:38:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2019-09-20 17:50:50 +08:00
|
|
|
|
Component.BorderColour = colours.Blue;
|
2018-07-25 17:38:50 +08:00
|
|
|
|
}
|
2019-09-20 17:50:50 +08:00
|
|
|
|
|
2021-06-10 21:38:56 +08:00
|
|
|
|
protected virtual OsuTextBox CreateTextBox() => new OsuTextBox();
|
2020-09-24 17:18:50 +08:00
|
|
|
|
|
2021-03-17 15:56:58 +08:00
|
|
|
|
public override bool AcceptsFocus => true;
|
|
|
|
|
|
|
|
|
|
protected override void OnFocus(FocusEvent e)
|
|
|
|
|
{
|
|
|
|
|
base.OnFocus(e);
|
|
|
|
|
GetContainingInputManager().ChangeFocus(Component);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 17:18:50 +08:00
|
|
|
|
protected override OsuTextBox CreateComponent() => CreateTextBox().With(t =>
|
|
|
|
|
{
|
2021-06-10 21:38:56 +08:00
|
|
|
|
t.CommitOnFocusLost = true;
|
|
|
|
|
t.Anchor = Anchor.Centre;
|
|
|
|
|
t.Origin = Anchor.Centre;
|
|
|
|
|
t.RelativeSizeAxes = Axes.X;
|
|
|
|
|
t.CornerRadius = CORNER_RADIUS;
|
|
|
|
|
|
2020-09-24 17:18:50 +08:00
|
|
|
|
t.OnCommit += (sender, newText) => OnCommit?.Invoke(sender, newText);
|
|
|
|
|
});
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|