mirror of
https://github.com/ppy/osu
synced 2025-01-02 12:22:13 +00:00
Add rounded button variant
This commit is contained in:
parent
b8fe744d2b
commit
21ee24ea6d
@ -0,0 +1,44 @@
|
||||
// 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 System;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneRoundedButton : OsuTestScene
|
||||
{
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
RoundedButton button = null;
|
||||
|
||||
AddStep("create button", () => Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Colour4.DarkGray
|
||||
},
|
||||
button = new RoundedButton
|
||||
{
|
||||
Width = 400,
|
||||
Text = "Test button",
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Action = () => { }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddToggleStep("toggle disabled", disabled => button.Action = disabled ? (Action)null : () => { });
|
||||
}
|
||||
}
|
||||
}
|
@ -225,6 +225,11 @@ namespace osu.Game.Graphics
|
||||
public readonly Color4 GrayE = Color4Extensions.FromHex(@"eee");
|
||||
public readonly Color4 GrayF = Color4Extensions.FromHex(@"fff");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Blue"/>'s <see cref="OverlayColourProvider.Colour3"/>.
|
||||
/// </summary>
|
||||
public readonly Color4 Blue3 = Color4Extensions.FromHex(@"3399cc");
|
||||
|
||||
/// <summary>
|
||||
/// Equivalent to <see cref="OverlayColourProvider.Lime"/>'s <see cref="OverlayColourProvider.Colour1"/>.
|
||||
/// </summary>
|
||||
|
48
osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs
Normal file
48
osu.Game/Graphics/UserInterfaceV2/RoundedButton.cs
Normal file
@ -0,0 +1,48 @@
|
||||
// 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.Effects;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
public class RoundedButton : OsuButton
|
||||
{
|
||||
public override float Height
|
||||
{
|
||||
get => base.Height;
|
||||
set
|
||||
{
|
||||
base.Height = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateCornerRadius();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = colours.Blue3;
|
||||
|
||||
Content.EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Offset = new Vector2(0, 2),
|
||||
Radius = 4,
|
||||
Colour = Colour4.Black.Opacity(0.15f)
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateCornerRadius();
|
||||
}
|
||||
|
||||
private void updateCornerRadius() => Content.CornerRadius = DrawHeight / 2;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user