Apply proposed changes (untested)

This commit is contained in:
AlFasGD 2018-07-23 15:44:10 +03:00
parent 6dd5c7e5ab
commit dd56a2d95f
3 changed files with 36 additions and 42 deletions

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
LabelText = "Testing text", LabelText = "Testing text",
TextBoxPlaceholderText = "This is definitely working as intended", PlaceholderText = "This is definitely working as intended",
Padding = new MarginPadding { Left = 150, Right = 150 } Padding = new MarginPadding { Left = 150, Right = 150 }
} }
}; };

View File

@ -8,29 +8,25 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System; using System;
using static osu.Framework.Graphics.UserInterface.TextBox;
namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
{ {
public class LabelledTextBox : CompositeDrawable public class LabelledTextBox : CompositeDrawable
{ {
private readonly OsuSetupTextBox textBox; private readonly SetupTextBox textBox;
private readonly Container content; private readonly Container content;
private readonly OsuSpriteText label; private readonly OsuSpriteText label;
public const float LABEL_CONTAINER_WIDTH = 150; private const float label_container_width = 150;
public const float OUTER_CORNER_RADIUS = 15; private const float outer_corner_radius = 15;
public const float INNER_CORNER_RADIUS = 10; private const float inner_corner_radius = 10;
public const float DEFAULT_HEIGHT = 40; private const float default_height = 40;
public const float DEFAULT_LABEL_LEFT_PADDING = 15; private const float default_label_left_padding = 15;
public const float DEFAULT_LABEL_TOP_PADDING = 12; private const float default_label_top_padding = 12;
public const float DEFAULT_LABEL_TEXT_SIZE = 16; private const float default_label_text_size = 16;
public event Action<string> TextBoxTextChanged; public event OnCommitHandler TextBoxTextChanged;
public void TriggerTextBoxTextChanged(string newText)
{
TextBoxTextChanged?.Invoke(newText);
}
private bool readOnly; private bool readOnly;
public bool ReadOnly public bool ReadOnly
@ -65,30 +61,30 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
} }
} }
private string textBoxPlaceholderText; private string placeholderText;
public string TextBoxPlaceholderText public string PlaceholderText
{ {
get => textBoxPlaceholderText; get => placeholderText;
set set
{ {
textBoxPlaceholderText = value; placeholderText = value;
textBox.PlaceholderText = value; textBox.PlaceholderText = value;
} }
} }
private string textBoxText; private string text;
public string TextBoxText public string Text
{ {
get => textBoxText; get => text;
set set
{ {
textBoxText = value; text = value;
textBox.Text = value; textBox.Text = value;
TextBoxTextChanged?.Invoke(value); TextBoxTextChanged?.Invoke(textBox, true);
} }
} }
private float height = DEFAULT_HEIGHT; private float height = default_height;
public float Height public float Height
{ {
get => height; get => height;
@ -137,34 +133,32 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
public LabelledTextBox() public LabelledTextBox()
{ {
Masking = true; Masking = true;
CornerRadius = OUTER_CORNER_RADIUS; CornerRadius = outer_corner_radius;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
base.Height = DEFAULT_HEIGHT + Padding.Top; base.Height = default_height + Padding.Top;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new Container new Container
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
Height = DEFAULT_HEIGHT, CornerRadius = outer_corner_radius,
CornerRadius = OUTER_CORNER_RADIUS,
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
Height = DEFAULT_HEIGHT,
Colour = OsuColour.FromHex("1c2125"), Colour = OsuColour.FromHex("1c2125"),
}, },
new Container new Container
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = DEFAULT_HEIGHT, Height = default_height,
Child = new GridContainer Child = new GridContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = DEFAULT_HEIGHT, Height = default_height,
Content = new[] Content = new[]
{ {
new Drawable[] new Drawable[]
@ -173,26 +167,26 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
{ {
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
Padding = new MarginPadding { Left = DEFAULT_LABEL_LEFT_PADDING, Top = DEFAULT_LABEL_TOP_PADDING }, Padding = new MarginPadding { Left = default_label_left_padding, Top = default_label_top_padding },
Colour = Color4.White, Colour = Color4.White,
TextSize = DEFAULT_LABEL_TEXT_SIZE, TextSize = default_label_text_size,
Text = LabelText, Text = LabelText,
Font = @"Exo2.0-Bold", Font = @"Exo2.0-Bold",
}, },
textBox = new OsuSetupTextBox textBox = new SetupTextBox
{ {
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft, Origin = Anchor.TopLeft,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = DEFAULT_HEIGHT, Height = default_height,
ReadOnly = ReadOnly, ReadOnly = ReadOnly,
CornerRadius = INNER_CORNER_RADIUS, CornerRadius = inner_corner_radius,
}, },
}, },
}, },
ColumnDimensions = new[] ColumnDimensions = new[]
{ {
new Dimension(GridSizeMode.Absolute, LABEL_CONTAINER_WIDTH), new Dimension(GridSizeMode.Absolute, label_container_width),
new Dimension() new Dimension()
} }
} }
@ -201,7 +195,7 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components.LabelledComponents
} }
}; };
textBox.OnCommit += delegate { TriggerTextBoxTextChanged(textBox.Text); }; textBox.OnCommit += (_, a) => TextBoxTextChanged?.Invoke(textBox, a);
} }
} }
} }

View File

@ -9,7 +9,7 @@ using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Edit.Screens.Setup.Components namespace osu.Game.Screens.Edit.Screens.Setup.Components
{ {
public class OsuSetupTextBox : OsuTextBox public class SetupTextBox : OsuTextBox
{ {
protected override float LeftRightPadding => 15; protected override float LeftRightPadding => 15;