Remove ``RoundedNub.cs` and make `Nub.cs`` non abstract again

This commit is contained in:
mk56-spn
2023-02-03 12:19:09 +01:00
parent 8c11e8e6f4
commit e1af5e110a
6 changed files with 41 additions and 59 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Tests.Visual.UserInterface
LowerBound = customStart, LowerBound = customStart,
UpperBound = customEnd, UpperBound = customEnd,
TooltipSuffix = "suffix", TooltipSuffix = "suffix",
NubWidth = RoundedNub.HEIGHT * 2, NubWidth = Nub.HEIGHT * 2,
DefaultStringLowerBound = "Start", DefaultStringLowerBound = "Start",
DefaultStringUpperBound = "End", DefaultStringUpperBound = "End",
MinRange = 10 MinRange = 10

View File

@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -11,33 +13,45 @@ using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
public abstract partial class Nub : Container, IHasCurrentValue<bool>, IHasAccentColour public partial class Nub : Container, IHasCurrentValue<bool>, IHasAccentColour
{ {
protected const float BORDER_WIDTH = 3; public const float HEIGHT = 15;
public const float EXPANDED_SIZE = 50;
private const float border_width = 3;
private readonly Box fill; private readonly Box fill;
private readonly Container main; private readonly Container main;
/// <summary> public Nub()
/// Implements the shape for the nub, allowing for any type of container to be used.
/// </summary>
/// <returns></returns>
protected abstract Container CreateNubContainer();
protected Nub()
{ {
InternalChild = main = CreateNubContainer(); Size = new Vector2(EXPANDED_SIZE, HEIGHT);
main.Add(fill = new Box InternalChildren = new[]
{ {
RelativeSizeAxes = Axes.Both, main = new CircularContainer
Alpha = 0, {
AlwaysPresent = true, BorderColour = Color4.White,
}); BorderThickness = border_width,
Masking = true,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Children = new Drawable[]
{
fill = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
}
},
};
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
@ -159,7 +173,7 @@ namespace osu.Game.Graphics.UserInterface
else else
{ {
main.ResizeWidthTo(0.75f, duration, Easing.OutQuint); main.ResizeWidthTo(0.75f, duration, Easing.OutQuint);
main.TransformTo(nameof(BorderThickness), BORDER_WIDTH, duration, Easing.OutQuint); main.TransformTo(nameof(BorderThickness), border_width, duration, Easing.OutQuint);
} }
} }
} }

View File

@ -41,7 +41,7 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
protected readonly RoundedNub Nub; protected readonly Nub Nub;
protected readonly OsuTextFlowContainer LabelTextFlowContainer; protected readonly OsuTextFlowContainer LabelTextFlowContainer;
private Sample sampleChecked; private Sample sampleChecked;
@ -61,7 +61,7 @@ namespace osu.Game.Graphics.UserInterface
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
}, },
Nub = new RoundedNub(), Nub = new Nub(),
new HoverSounds() new HoverSounds()
}; };
@ -70,14 +70,14 @@ namespace osu.Game.Graphics.UserInterface
Nub.Anchor = Anchor.CentreRight; Nub.Anchor = Anchor.CentreRight;
Nub.Origin = Anchor.CentreRight; Nub.Origin = Anchor.CentreRight;
Nub.Margin = new MarginPadding { Right = nub_padding }; Nub.Margin = new MarginPadding { Right = nub_padding };
LabelTextFlowContainer.Padding = new MarginPadding { Right = RoundedNub.EXPANDED_SIZE + nub_padding * 2 }; LabelTextFlowContainer.Padding = new MarginPadding { Right = Nub.EXPANDED_SIZE + nub_padding * 2 };
} }
else else
{ {
Nub.Anchor = Anchor.CentreLeft; Nub.Anchor = Anchor.CentreLeft;
Nub.Origin = Anchor.CentreLeft; Nub.Origin = Anchor.CentreLeft;
Nub.Margin = new MarginPadding { Left = nub_padding }; Nub.Margin = new MarginPadding { Left = nub_padding };
LabelTextFlowContainer.Padding = new MarginPadding { Left = RoundedNub.EXPANDED_SIZE + nub_padding * 2 }; LabelTextFlowContainer.Padding = new MarginPadding { Left = Nub.EXPANDED_SIZE + nub_padding * 2 };
} }
Nub.Current.BindTo(Current); Nub.Current.BindTo(Current);

View File

@ -163,7 +163,7 @@ namespace osu.Game.Graphics.UserInterface
public string? DefaultString; public string? DefaultString;
public LocalisableString? DefaultTooltip; public LocalisableString? DefaultTooltip;
public string? TooltipSuffix; public string? TooltipSuffix;
public float NubWidth { get; set; } = RoundedNub.HEIGHT; public float NubWidth { get; set; } = Nub.HEIGHT;
public override LocalisableString TooltipText => public override LocalisableString TooltipText =>
(Current.IsDefault ? DefaultTooltip : Current.Value.ToString($@"0.## {TooltipSuffix}")) ?? Current.Value.ToString($@"0.## {TooltipSuffix}"); (Current.IsDefault ? DefaultTooltip : Current.Value.ToString($@"0.## {TooltipSuffix}")) ?? Current.Value.ToString($@"0.## {TooltipSuffix}");

View File

@ -1,32 +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.Graphics;
using osu.Framework.Graphics.Containers;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public partial class RoundedNub : Nub
{
public const float HEIGHT = 15;
public const float EXPANDED_SIZE = 50;
public RoundedNub()
{
Size = new Vector2(EXPANDED_SIZE, HEIGHT);
}
protected override Container CreateNubContainer() =>
new CircularContainer
{
BorderColour = Colour4.White,
BorderThickness = BORDER_WIDTH,
Masking = true,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
};
}
}

View File

@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface
public partial class RoundedSliderBar<T> : OsuSliderBar<T> public partial class RoundedSliderBar<T> : OsuSliderBar<T>
where T : struct, IEquatable<T>, IComparable<T>, IConvertible where T : struct, IEquatable<T>, IComparable<T>, IConvertible
{ {
protected readonly RoundedNub Nub; protected readonly Nub Nub;
protected readonly Box LeftBox; protected readonly Box LeftBox;
protected readonly Box RightBox; protected readonly Box RightBox;
private readonly Container nubContainer; private readonly Container nubContainer;
@ -50,8 +50,8 @@ namespace osu.Game.Graphics.UserInterface
public RoundedSliderBar() public RoundedSliderBar()
{ {
Height = RoundedNub.HEIGHT; Height = Nub.HEIGHT;
RangePadding = RoundedNub.EXPANDED_SIZE / 2; RangePadding = Nub.EXPANDED_SIZE / 2;
Children = new Drawable[] Children = new Drawable[]
{ {
new Container new Container
@ -93,7 +93,7 @@ namespace osu.Game.Graphics.UserInterface
nubContainer = new Container nubContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = Nub = new RoundedNub Child = Nub = new Nub
{ {
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X, RelativePositionAxes = Axes.X,