Add ability to revert slider settings to default when double-clicking nub

This commit is contained in:
Joseph Madamba 2023-10-17 21:37:38 -07:00
parent 1a3a81c33b
commit 18e8ca6245
3 changed files with 29 additions and 3 deletions

View File

@ -93,11 +93,12 @@ public RoundedSliderBar()
nubContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Child = Nub = new Nub
Child = Nub = new SliderNub
{
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
Current = { Value = true }
Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
},
},
hoverClickSounds = new HoverClickSounds()
@ -166,5 +167,18 @@ protected override void UpdateValue(float value)
{
Nub.MoveToX(value, 250, Easing.OutQuint);
}
public partial class SliderNub : Nub
{
public Action? OnDoubleClicked { get; init; }
protected override bool OnClick(ClickEvent e) => true;
protected override bool OnDoubleClick(DoubleClickEvent e)
{
OnDoubleClicked?.Invoke();
return true;
}
}
}
}

View File

@ -10,6 +10,7 @@
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Overlays;
using osuTK;
using osuTK.Graphics;
@ -18,6 +19,8 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class ShearedNub : Container, IHasCurrentValue<bool>, IHasAccentColour
{
public Action? OnDoubleClicked { get; init; }
protected const float BORDER_WIDTH = 3;
public const int HEIGHT = 30;
@ -179,5 +182,13 @@ private void onCurrentValueChanged(ValueChangedEvent<bool> filled)
main.TransformTo(nameof(BorderThickness), BORDER_WIDTH, duration, Easing.OutQuint);
}
}
protected override bool OnClick(ClickEvent e) => true;
protected override bool OnDoubleClick(DoubleClickEvent e)
{
OnDoubleClicked?.Invoke();
return true;
}
}
}

View File

@ -100,7 +100,8 @@ public ShearedSliderBar()
X = -SHEAR.X * HEIGHT / 2f,
Origin = Anchor.TopCentre,
RelativePositionAxes = Axes.X,
Current = { Value = true }
Current = { Value = true },
OnDoubleClicked = () => Current.SetDefault(),
},
},
hoverClickSounds = new HoverClickSounds()