mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Make LabelledTextBox use the new LabelledComponent class (#6188)
Make LabelledTextBox use the new LabelledComponent class Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
d2b76ec688
@ -6,7 +6,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Screens.Edit.Setup.Components.LabelledComponents;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
@ -7,7 +7,8 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Screens.Edit.Setup.Components.LabelledComponents;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
@ -19,6 +20,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<OsuTextBox> 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 +63,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",
|
||||
}
|
||||
};
|
||||
|
@ -7,9 +7,9 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Screens.Edit.Setup.Components.LabelledComponents;
|
||||
using osu.Game.Tournament.IPC;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
@ -5,11 +5,10 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Setup.Components.LabelledComponents
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
public abstract class LabelledComponent<T> : CompositeDrawable
|
||||
where T : Drawable
|
49
osu.Game/Graphics/UserInterfaceV2/LabelledTextBox.cs
Normal file
49
osu.Game/Graphics/UserInterfaceV2/LabelledTextBox.cs
Normal file
@ -0,0 +1,49 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
public class LabelledTextBox : LabelledComponent<OsuTextBox>
|
||||
{
|
||||
public event TextBox.OnCommitHandler OnCommit;
|
||||
|
||||
public LabelledTextBox()
|
||||
: base(false)
|
||||
{
|
||||
}
|
||||
|
||||
public bool ReadOnly
|
||||
{
|
||||
set => Component.ReadOnly = value;
|
||||
}
|
||||
|
||||
public string PlaceholderText
|
||||
{
|
||||
set => Component.PlaceholderText = value;
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
set => Component.Text = value;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Component.BorderColour = colours.Blue;
|
||||
}
|
||||
|
||||
protected override OsuTextBox 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));
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
// 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.
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public string PlaceholderText
|
||||
{
|
||||
get => textBox.PlaceholderText;
|
||||
set => textBox.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;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
textBox.BorderColour = colours.Blue;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user