diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs b/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs index 602709ffc2..76f170dfee 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs @@ -59,6 +59,7 @@ public TestSceneStepButton() CallStack = new StackTrace() }, new StepSlider(nameof(StepSlider), 0, 10, 5), + new StepColourPicker(nameof(StepColourPicker), Colour4.AliceBlue), } }; } diff --git a/osu.Framework/Testing/Drawables/Steps/StepColourPicker.cs b/osu.Framework/Testing/Drawables/Steps/StepColourPicker.cs new file mode 100644 index 0000000000..eef7db7fbf --- /dev/null +++ b/osu.Framework/Testing/Drawables/Steps/StepColourPicker.cs @@ -0,0 +1,69 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osuTK; + +namespace osu.Framework.Testing.Drawables.Steps +{ + public partial class StepColourPicker : CompositeDrawable + { + private const float scale_adjust = 0.5f; + + public Action? ValueChanged { get; set; } + + private readonly Bindable current; + + public StepColourPicker(string description, Colour4 initialColour) + { + current = new Bindable(initialColour); + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = FrameworkColour.GreenDark, + }, + new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new SpriteText + { + Text = description, + Padding = new MarginPadding(5), + Font = FrameworkFont.Regular.With(size: 14), + }, + new BasicColourPicker + { + RelativeSizeAxes = Axes.X, + Width = 1f / scale_adjust, + Scale = new Vector2(scale_adjust), + Current = current, + } + } + } + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + current.BindValueChanged(v => ValueChanged?.Invoke(v.NewValue), true); + } + } +} diff --git a/osu.Framework/Testing/TestScene.cs b/osu.Framework/Testing/TestScene.cs index d0b76e9ae4..8b724f166f 100644 --- a/osu.Framework/Testing/TestScene.cs +++ b/osu.Framework/Testing/TestScene.cs @@ -391,6 +391,17 @@ protected void AddSliderStep([NotNull] string description, T min, T max, T st }); } + protected void AddColourPickerStep([NotNull] string description, Colour4 initial, Action valueChanged) + { + schedule(() => + { + StepsContainer.Add(new StepColourPicker(description, initial) + { + ValueChanged = valueChanged, + }); + }); + } + protected void AddAssert([NotNull] string description, [NotNull] Func assert, [CanBeNull] string extendedDescription = null) { AddStep(new AssertButton