1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 18:27:26 +08:00

Update LabelledTextBox to use LabelledComponent

This commit is contained in:
smoogipoo 2019-09-20 18:50:50 +09:00
parent 523272edab
commit 2bbf4ca4b5
2 changed files with 51 additions and 98 deletions

View File

@ -19,6 +19,36 @@ namespace osu.Game.Tests.Visual.UserInterface
typeof(LabelledTextBox),
};
[TestCase(false)]
[TestCase(true)]
public void TestTextBox(bool hasDescription) => createTextBox(hasDescription);
private void createTextBox(bool hasDescription = false)
{
AddStep("create component", () =>
{
LabelledComponent component;
Child = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 500,
AutoSizeAxes = Axes.Y,
Child = component = new LabelledTextBox
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Label = "Testing text",
PlaceholderText = "This is definitely working as intended",
}
};
component.Label = "a sample component";
component.Description = hasDescription ? "this text describes the component" : string.Empty;
});
}
[BackgroundDependencyLoader]
private void load()
{
@ -32,7 +62,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
LabelText = "Testing text",
Label = "Testing text",
PlaceholderText = "This is definitely working as intended",
}
};

View File

@ -3,127 +3,50 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Setup.Components.LabelledComponents
{
public class LabelledTextBox : CompositeDrawable
public class LabelledTextBox : LabelledComponent
{
private const float label_container_width = 150;
private const float corner_radius = 15;
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;
public event TextBox.OnCommitHandler OnCommit;
protected new OsuTextBox Component => (OsuTextBox)base.Component;
public LabelledTextBox()
: base(false)
{
}
public bool ReadOnly
{
get => textBox.ReadOnly;
set => textBox.ReadOnly = value;
}
public string LabelText
{
get => label.Text;
set => label.Text = value;
}
public float LabelTextSize
{
get => label.Font.Size;
set => label.Font = label.Font.With(size: value);
set => Component.ReadOnly = value;
}
public string PlaceholderText
{
get => textBox.PlaceholderText;
set => textBox.PlaceholderText = value;
set => Component.PlaceholderText = value;
}
public string Text
{
get => textBox.Text;
set => textBox.Text = value;
}
public Color4 LabelTextColour
{
get => label.Colour;
set => label.Colour = value;
}
private readonly OsuTextBox textBox;
private readonly OsuSpriteText label;
public LabelledTextBox()
{
RelativeSizeAxes = Axes.X;
Height = default_height;
CornerRadius = corner_radius;
Masking = true;
InternalChild = new Container
{
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex("1c2125"),
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
Height = default_height,
Content = new[]
{
new Drawable[]
{
label = new OsuSpriteText
{
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),
},
textBox = new OsuTextBox
{
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Height = 1,
CornerRadius = corner_radius,
},
},
},
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, label_container_width),
new Dimension()
}
}
}
};
textBox.OnCommit += OnCommit;
set => Component.Text = value;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
textBox.BorderColour = colours.Blue;
Component.BorderColour = colours.Blue;
}
protected override Drawable CreateComponent() => new OsuTextBox
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
CornerRadius = CORNER_RADIUS,
}.With(t => t.OnCommit += (sender, newText) => OnCommit?.Invoke(sender, newText));
}
}