Skip to content

Commit 5c37ed9

Browse files
authored
Merge pull request #6705 from minetoblend/feature/color-picker-step-button
Add colour picker step-button for test scenes
2 parents 70d27e4 + 0f26e65 commit 5c37ed9

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public TestSceneStepButton()
5959
CallStack = new StackTrace()
6060
},
6161
new StepSlider<int>(nameof(StepSlider<int>), 0, 10, 5),
62+
new StepColourPicker(nameof(StepColourPicker), Colour4.AliceBlue),
6263
}
6364
};
6465
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using System;
5+
using osu.Framework.Bindables;
6+
using osu.Framework.Graphics;
7+
using osu.Framework.Graphics.Containers;
8+
using osu.Framework.Graphics.Shapes;
9+
using osu.Framework.Graphics.Sprites;
10+
using osu.Framework.Graphics.UserInterface;
11+
using osuTK;
12+
13+
namespace osu.Framework.Testing.Drawables.Steps
14+
{
15+
public partial class StepColourPicker : CompositeDrawable
16+
{
17+
private const float scale_adjust = 0.5f;
18+
19+
public Action<Colour4>? ValueChanged { get; set; }
20+
21+
private readonly Bindable<Colour4> current;
22+
23+
public StepColourPicker(string description, Colour4 initialColour)
24+
{
25+
current = new Bindable<Colour4>(initialColour);
26+
27+
RelativeSizeAxes = Axes.X;
28+
AutoSizeAxes = Axes.Y;
29+
30+
InternalChildren = new Drawable[]
31+
{
32+
new Box
33+
{
34+
RelativeSizeAxes = Axes.Both,
35+
Colour = FrameworkColour.GreenDark,
36+
},
37+
new FillFlowContainer
38+
{
39+
RelativeSizeAxes = Axes.X,
40+
AutoSizeAxes = Axes.Y,
41+
Direction = FillDirection.Vertical,
42+
Children = new Drawable[]
43+
{
44+
new SpriteText
45+
{
46+
Text = description,
47+
Padding = new MarginPadding(5),
48+
Font = FrameworkFont.Regular.With(size: 14),
49+
},
50+
new BasicColourPicker
51+
{
52+
RelativeSizeAxes = Axes.X,
53+
Width = 1f / scale_adjust,
54+
Scale = new Vector2(scale_adjust),
55+
Current = current,
56+
}
57+
}
58+
}
59+
};
60+
}
61+
62+
protected override void LoadComplete()
63+
{
64+
base.LoadComplete();
65+
66+
current.BindValueChanged(v => ValueChanged?.Invoke(v.NewValue), true);
67+
}
68+
}
69+
}

osu.Framework/Testing/TestScene.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ protected void AddSliderStep<T>([NotNull] string description, T min, T max, T st
391391
});
392392
}
393393

394+
protected void AddColourPickerStep([NotNull] string description, Colour4 initial, Action<Colour4> valueChanged)
395+
{
396+
schedule(() =>
397+
{
398+
StepsContainer.Add(new StepColourPicker(description, initial)
399+
{
400+
ValueChanged = valueChanged,
401+
});
402+
});
403+
}
404+
394405
protected void AddAssert([NotNull] string description, [NotNull] Func<bool> assert, [CanBeNull] string extendedDescription = null)
395406
{
396407
AddStep(new AssertButton

0 commit comments

Comments
 (0)