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
|
|
|
|
|
2018-07-25 17:38:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-07-25 17:34:47 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-07-24 14:46:24 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
|
2018-11-06 17:28:22 +08:00
|
|
|
|
namespace osu.Game.Screens.Edit.Setup.Components.LabelledComponents
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
|
|
|
|
public class LabelledTextBox : CompositeDrawable
|
|
|
|
|
{
|
2018-07-23 20:44:10 +08:00
|
|
|
|
private const float label_container_width = 150;
|
2018-07-25 20:14:40 +08:00
|
|
|
|
private const float corner_radius = 15;
|
2018-07-23 20:44:10 +08:00
|
|
|
|
private const float default_height = 40;
|
|
|
|
|
private const float default_label_left_padding = 15;
|
|
|
|
|
private const float default_label_top_padding = 12;
|
|
|
|
|
private const float default_label_text_size = 16;
|
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
|
|
|
|
|
2018-07-20 18:05:19 +08:00
|
|
|
|
public bool ReadOnly
|
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
get => textBox.ReadOnly;
|
|
|
|
|
set => textBox.ReadOnly = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2018-07-20 18:05:19 +08:00
|
|
|
|
public string LabelText
|
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
get => label.Text;
|
|
|
|
|
set => label.Text = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2018-07-20 18:05:19 +08:00
|
|
|
|
public float LabelTextSize
|
|
|
|
|
{
|
2019-02-12 12:04:46 +08:00
|
|
|
|
get => label.Font.Size;
|
2019-02-20 18:32:30 +08:00
|
|
|
|
set => label.Font = label.Font.With(size: value);
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 03:33:19 +08:00
|
|
|
|
|
2018-07-23 20:44:10 +08:00
|
|
|
|
public string PlaceholderText
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
get => textBox.PlaceholderText;
|
|
|
|
|
set => textBox.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
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
get => textBox.Text;
|
|
|
|
|
set => textBox.Text = value;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color4 LabelTextColour
|
|
|
|
|
{
|
|
|
|
|
get => label.Colour;
|
|
|
|
|
set => label.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Color4 BackgroundColour
|
|
|
|
|
{
|
|
|
|
|
get => content.Colour;
|
|
|
|
|
set => content.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 17:34:47 +08:00
|
|
|
|
private readonly OsuTextBox textBox;
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
private readonly OsuSpriteText label;
|
|
|
|
|
|
2018-07-20 18:05:19 +08:00
|
|
|
|
public LabelledTextBox()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2018-07-25 03:04:02 +08:00
|
|
|
|
Height = default_height;
|
2018-07-25 20:14:40 +08:00
|
|
|
|
CornerRadius = corner_radius;
|
2018-07-24 15:10:17 +08:00
|
|
|
|
Masking = true;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
|
2018-07-24 15:10:17 +08:00
|
|
|
|
InternalChild = new Container
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-24 15:10:17 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-07-25 20:14:40 +08:00
|
|
|
|
CornerRadius = corner_radius,
|
2018-07-24 15:10:17 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-24 15:10:17 +08:00
|
|
|
|
new Box
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-24 15:10:17 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.FromHex("1c2125"),
|
|
|
|
|
},
|
2018-07-25 03:04:02 +08:00
|
|
|
|
new GridContainer
|
2018-07-24 15:10:17 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = default_height,
|
2018-07-25 03:04:02 +08:00
|
|
|
|
Content = new[]
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
new Drawable[]
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
label = new OsuSpriteText
|
2018-07-20 18:05:19 +08:00
|
|
|
|
{
|
2018-07-25 03:04:02 +08:00
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Padding = new MarginPadding { Left = default_label_left_padding, Top = default_label_top_padding },
|
|
|
|
|
Colour = Color4.White,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: default_label_text_size, weight: FontWeight.Bold),
|
2018-07-25 03:04:02 +08:00
|
|
|
|
},
|
|
|
|
|
textBox = new OsuTextBox
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 1,
|
2018-07-25 20:14:40 +08:00
|
|
|
|
CornerRadius = corner_radius,
|
2018-07-20 18:05:19 +08:00
|
|
|
|
},
|
2018-07-24 15:10:17 +08:00
|
|
|
|
},
|
2018-07-25 03:04:02 +08:00
|
|
|
|
},
|
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, label_container_width),
|
|
|
|
|
new Dimension()
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-24 14:19:45 +08:00
|
|
|
|
textBox.OnCommit += OnCommit;
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
2018-07-25 17:38:50 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
textBox.BorderColour = colours.Blue;
|
|
|
|
|
}
|
2018-07-20 18:05:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|