1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 18:12:59 +08:00
osu-lazer/osu.Game/Screens/Edit/Setup/Components/LabelledComponents/LabelledTextBox.cs

130 lines
4.3 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-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-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-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-20 18:05:19 +08:00
public float LabelTextSize
{
get => label.Font.Size;
set => label.Font = label.Font.With(size: value);
2018-07-20 18:05: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;
}
2018-07-25 17:34:47 +08:00
private readonly OsuTextBox textBox;
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,
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
}
}
}
};
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
}
}