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

202 lines
6.4 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-20 10:05:19 +00:00
using System;
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-20 10:05:19 +00:00
private bool readOnly;
public bool ReadOnly
{
get => readOnly;
set
{
textBox.ReadOnly = value;
readOnly = value;
}
}
private string labelText;
public string LabelText
{
get => labelText;
set
{
labelText = value;
label.Text = value;
}
}
private float labelTextSize;
public float LabelTextSize
{
get => labelTextSize;
set
{
labelTextSize = value;
label.TextSize = value;
}
}
2018-07-23 12:44:10 +00:00
private string placeholderText;
public string PlaceholderText
2018-07-20 10:05:19 +00:00
{
2018-07-23 12:44:10 +00:00
get => placeholderText;
2018-07-20 10:05:19 +00:00
set
{
2018-07-23 12:44:10 +00:00
placeholderText = value;
2018-07-20 10:05:19 +00:00
textBox.PlaceholderText = value;
}
}
2018-07-23 12:44:10 +00:00
private string text;
public string Text
2018-07-20 10:05:19 +00:00
{
2018-07-23 12:44:10 +00:00
get => text;
2018-07-20 10:05:19 +00:00
set
{
2018-07-23 12:44:10 +00:00
text = value;
2018-07-20 10:05:19 +00:00
textBox.Text = value;
}
}
2018-07-23 12:44:10 +00:00
private float height = default_height;
2018-07-20 10:05:19 +00:00
public float Height
{
get => height;
private set
{
height = value;
textBox.Height = value;
content.Height = value;
}
}
public MarginPadding Padding
{
get => base.Padding;
set
{
base.Padding = value;
base.Height = Height + base.Padding.Top;
}
}
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()
{
Masking = true;
2018-07-23 12:44:10 +00:00
CornerRadius = outer_corner_radius;
2018-07-20 10:05:19 +00:00
RelativeSizeAxes = Axes.X;
2018-07-23 12:44:10 +00:00
base.Height = default_height + Padding.Top;
2018-07-20 10:05:19 +00:00
InternalChildren = new Drawable[]
{
new Container
{
2018-07-23 12:44:10 +00:00
RelativeSizeAxes = Axes.Both,
CornerRadius = outer_corner_radius,
2018-07-20 10:05:19 +00:00
Masking = true,
Children = new Drawable[]
{
new Box
{
2018-07-23 12:44:10 +00:00
RelativeSizeAxes = Axes.Both,
2018-07-20 10:05:19 +00:00
Colour = OsuColour.FromHex("1c2125"),
},
new Container
{
RelativeSizeAxes = Axes.X,
2018-07-23 12:44:10 +00:00
Height = default_height,
2018-07-20 10:05:19 +00:00
Child = new GridContainer
{
RelativeSizeAxes = Axes.X,
2018-07-23 12:44:10 +00:00
Height = default_height,
2018-07-20 10:05:19 +00:00
Content = new[]
{
new Drawable[]
{
label = new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
2018-07-23 12:44:10 +00:00
Padding = new MarginPadding { Left = default_label_left_padding, Top = default_label_top_padding },
2018-07-20 10:05:19 +00:00
Colour = Color4.White,
2018-07-23 12:44:10 +00:00
TextSize = default_label_text_size,
2018-07-20 10:05:19 +00:00
Text = LabelText,
Font = @"Exo2.0-Bold",
},
2018-07-24 06:46:24 +00:00
textBox = new OsuTextBox
2018-07-20 10:05:19 +00:00
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.X,
2018-07-23 12:44:10 +00:00
Height = default_height,
2018-07-20 10:05:19 +00:00
ReadOnly = ReadOnly,
2018-07-23 12:44:10 +00:00
CornerRadius = inner_corner_radius,
2018-07-20 10:05:19 +00:00
},
},
},
ColumnDimensions = new[]
{
2018-07-23 12:44:10 +00:00
new Dimension(GridSizeMode.Absolute, label_container_width),
2018-07-20 10:05:19 +00:00
new Dimension()
}
}
}
}
}
};
textBox.OnCommit += OnCommit;
2018-07-20 10:05:19 +00:00
}
}
}