mirror of
https://github.com/ppy/osu
synced 2024-12-12 01:48:49 +00:00
Expose a NumberFormatInfo for more extensibility
This commit is contained in:
parent
b84f83cf16
commit
cbf4852438
@ -28,18 +28,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private readonly Box leftBox;
|
||||
private readonly Box rightBox;
|
||||
|
||||
private int tooltipDecimalDigits = 1;
|
||||
/// <summary>
|
||||
/// The amount of decimal digits to display for <see cref="OsuSliderBar{T}"/>s with floating point values.
|
||||
/// </summary>
|
||||
public int TooltipDecimalDigits
|
||||
private NumberFormatInfo format;
|
||||
public NumberFormatInfo Format
|
||||
{
|
||||
get => tooltipDecimalDigits;
|
||||
get => format ?? (format = createDefaultFormat());
|
||||
set
|
||||
{
|
||||
if (tooltipDecimalDigits == value)
|
||||
if (format == value)
|
||||
return;
|
||||
tooltipDecimalDigits = value;
|
||||
format = value;
|
||||
|
||||
if (IsLoaded)
|
||||
{
|
||||
@ -63,17 +60,14 @@ namespace osu.Game.Graphics.UserInterface
|
||||
var floatMaxValue = bindableDouble?.MaxValue ?? bindableFloat.MaxValue;
|
||||
|
||||
if (floatMaxValue == 1 && (floatMinValue == 0 || floatMinValue == -1))
|
||||
return floatValue.Value.ToString(@"P0");
|
||||
return floatValue.Value.ToString("P", Format);
|
||||
|
||||
var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
|
||||
nfi.NumberDecimalDigits = TooltipDecimalDigits;
|
||||
|
||||
return string.Format(nfi, "{0:F}", floatValue.Value);
|
||||
return floatValue.Value.ToString("F", Format);
|
||||
}
|
||||
|
||||
var bindableInt = CurrentNumber as BindableNumber<int>;
|
||||
if (bindableInt != null)
|
||||
return bindableInt.Value.ToString(@"n0");
|
||||
return bindableInt.Value.ToString("N0");
|
||||
|
||||
return Current.Value.ToString();
|
||||
}
|
||||
@ -137,6 +131,15 @@ namespace osu.Game.Graphics.UserInterface
|
||||
AccentColour = colours.Pink;
|
||||
}
|
||||
|
||||
private NumberFormatInfo createDefaultFormat()
|
||||
{
|
||||
var nfi = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
|
||||
nfi.PercentDecimalDigits = 0;
|
||||
nfi.NumberDecimalDigits = 1;
|
||||
|
||||
return nfi;
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
Nub.Glowing = true;
|
||||
|
Loading…
Reference in New Issue
Block a user