Skip to content

Commit

Permalink
Merge pull request #29897 from bdach/editor/setup-screen-slider
Browse files Browse the repository at this point in the history
Implement "form" slider bar control
  • Loading branch information
peppy authored Sep 19, 2024
2 parents cd61aec + ca8402d commit bd8addf
Show file tree
Hide file tree
Showing 5 changed files with 422 additions and 4 deletions.
26 changes: 26 additions & 0 deletions osu.Game.Tests/Visual/UserInterface/TestSceneFormControls.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
Expand Down Expand Up @@ -68,6 +69,31 @@ public TestSceneFormControls()
HintText = EditorSetupStrings.LetterboxDuringBreaksDescription,
Current = { Disabled = true },
},
new FormSliderBar<float>
{
Caption = "Instantaneous slider",
Current = new BindableFloat
{
MinValue = 0,
MaxValue = 10,
Value = 5,
Precision = 0.1f,
},
TabbableContentContainer = this,
},
new FormSliderBar<float>
{
Caption = "Non-instantaneous slider",
Current = new BindableFloat
{
MinValue = 0,
MaxValue = 10,
Value = 5,
Precision = 0.1f,
},
Instantaneous = false,
TabbableContentContainer = this,
},
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Graphics/UserInterface/OsuSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void load(AudioManager audio)
protected override void LoadComplete()
{
base.LoadComplete();
CurrentNumber.BindValueChanged(current => TooltipText = getTooltipText(current.NewValue), true);
CurrentNumber.BindValueChanged(current => TooltipText = GetDisplayableValue(current.NewValue), true);
}

protected override void OnUserChange(T value)
Expand All @@ -55,7 +55,7 @@ protected override void OnUserChange(T value)

playSample(value);

TooltipText = getTooltipText(value);
TooltipText = GetDisplayableValue(value);
}

private void playSample(T value)
Expand Down Expand Up @@ -83,7 +83,7 @@ private void playSample(T value)
channel.Play();
}

private LocalisableString getTooltipText(T value)
public LocalisableString GetDisplayableValue(T value)
{
if (CurrentNumber.IsInteger)
return int.CreateTruncating(value).ToString("N0");
Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Graphics/UserInterfaceV2/FormCheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public Bindable<bool> Current

private readonly BindableWithCurrent<bool> current = new BindableWithCurrent<bool>();

/// <summary>
/// Caption describing this slider bar, displayed on top of the controls.
/// </summary>
public LocalisableString Caption { get; init; }

/// <summary>
/// Hint text containing an extended description of this slider bar, displayed in a tooltip when hovering the caption.
/// </summary>
public LocalisableString HintText { get; init; }

private Box background = null!;
Expand Down
Loading

0 comments on commit bd8addf

Please sign in to comment.