osu/osu.Game/Screens/Edit/Screens/Setup/Components/LabelledComponents/LabelledTextBox.cs

150 lines
4.8 KiB
C#
Raw Normal View History

2018-07-20 10:05:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2018-07-24 06:46:24 +00:00
using osu.Game.Graphics.UserInterface;
2018-07-23 12:44:10 +00:00
using static osu.Framework.Graphics.UserInterface.TextBox;
2018-07-20 10:05:19 +00:00
namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
{
public class LabelledTextBox : CompositeDrawable
{
2018-07-24 06:46:24 +00:00
private readonly OsuTextBox textBox;
2018-07-20 10:05:19 +00:00
private readonly Container content;
private readonly OsuSpriteText label;
2018-07-23 12:44:10 +00:00
private const float label_container_width = 150;
private const float outer_corner_radius = 15;
private const float inner_corner_radius = 10;
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 10:05:19 +00:00
public event OnCommitHandler OnCommit;
2018-07-24 19:04:02 +00:00
2018-07-20 10:05:19 +00:00
public bool ReadOnly
{
2018-07-24 19:04:02 +00:00
get => textBox.ReadOnly;
set => textBox.ReadOnly = value;
2018-07-20 10:05:19 +00:00
}
2018-07-24 19:04:02 +00:00
2018-07-20 10:05:19 +00:00
public string LabelText
{
2018-07-24 19:04:02 +00:00
get => label.Text;
set => label.Text = value;
2018-07-20 10:05:19 +00:00
}
2018-07-24 19:04:02 +00:00
2018-07-20 10:05:19 +00:00
public float LabelTextSize
{
2018-07-24 19:04:02 +00:00
get => label.TextSize;
set => label.TextSize = value;
2018-07-20 10:05:19 +00:00
}
2018-07-24 19:04:02 +00:00
2018-07-23 12:44:10 +00:00
public string PlaceholderText
2018-07-20 10:05:19 +00:00
{
2018-07-24 19:04:02 +00:00
get => textBox.PlaceholderText;
set => textBox.PlaceholderText = value;
2018-07-20 10:05:19 +00:00
}
2018-07-23 12:44:10 +00:00
public string Text
2018-07-20 10:05:19 +00:00
{
2018-07-24 19:04:02 +00:00
get => textBox.Text;
set => textBox.Text = value;
2018-07-20 10:05:19 +00:00
}
public MarginPadding Padding
{
get => base.Padding;
2018-07-24 19:04:02 +00:00
set => base.Padding = value;
2018-07-20 10:05:19 +00:00
}
public MarginPadding LabelPadding
{
get => label.Padding;
set => label.Padding = value;
}
public MarginPadding TextBoxPadding
{
get => textBox.Padding;
set => textBox.Padding = value;
}
public Color4 LabelTextColour
{
get => label.Colour;
set => label.Colour = value;
}
public Color4 BackgroundColour
{
get => content.Colour;
set => content.Colour = value;
}
public LabelledTextBox()
{
RelativeSizeAxes = Axes.X;
2018-07-24 19:04:02 +00:00
Height = default_height;
2018-07-24 07:10:17 +00:00
CornerRadius = outer_corner_radius;
Masking = true;
2018-07-20 10:05:19 +00:00
2018-07-24 07:10:17 +00:00
InternalChild = new Container
2018-07-20 10:05:19 +00:00
{
2018-07-24 07:10:17 +00:00
RelativeSizeAxes = Axes.Both,
CornerRadius = outer_corner_radius,
Masking = true,
Children = new Drawable[]
2018-07-20 10:05:19 +00:00
{
2018-07-24 07:10:17 +00:00
new Box
2018-07-20 10:05:19 +00:00
{
2018-07-24 07:10:17 +00:00
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex("1c2125"),
},
2018-07-24 19:04:02 +00:00
new GridContainer
2018-07-24 07:10:17 +00:00
{
RelativeSizeAxes = Axes.X,
Height = default_height,
2018-07-24 19:04:02 +00:00
Content = new[]
2018-07-20 10:05:19 +00:00
{
2018-07-24 19:04:02 +00:00
new Drawable[]
2018-07-20 10:05:19 +00:00
{
2018-07-24 19:04:02 +00:00
label = new OsuSpriteText
2018-07-20 10:05:19 +00:00
{
2018-07-24 19:04:02 +00:00
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
Padding = new MarginPadding { Left = default_label_left_padding, Top = default_label_top_padding },
Colour = Color4.White,
TextSize = default_label_text_size,
Font = @"Exo2.0-Bold",
},
textBox = new OsuTextBox
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Height = 1,
CornerRadius = inner_corner_radius,
2018-07-20 10:05:19 +00:00
},
2018-07-24 07:10:17 +00:00
},
2018-07-24 19:04:02 +00:00
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, label_container_width),
new Dimension()
2018-07-20 10:05:19 +00:00
}
}
}
};
textBox.OnCommit += OnCommit;
2018-07-20 10:05:19 +00:00
}
}
}