Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jan 29, 2024
1 parent cf97cb1 commit 0bacf69
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
60 changes: 47 additions & 13 deletions osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,34 @@ public float KeyboardStep
set => slider.KeyboardStep = value;
}

private bool hasCustomPrecision;

public Bindable<T> Current
{
get => slider.Current;
set => slider.Current = value;
get => current.Current;
set
{
current.Current = value;

BindableNumber<T> vNumber = (BindableNumber<T>)value;
BindableNumber<T> sliderCurrent = (BindableNumber<T>)slider.Current;

sliderCurrent.MinValue = vNumber.MinValue;
sliderCurrent.MaxValue = vNumber.MaxValue;
sliderCurrent.Default = vNumber.Default;
if (!hasCustomPrecision) sliderCurrent.Precision = vNumber.Precision;
}
}

public T SliderPrecision
{
set
{
BindableNumber<T> sliderCurrent = (BindableNumber<T>)slider.Current;

sliderCurrent.Precision = value;
hasCustomPrecision = true;
}
}

private bool instantaneous;
Expand All @@ -51,6 +75,8 @@ public bool Instantaneous
private readonly SettingsSlider<T> slider;
private readonly LabelledTextBox textBox;

private readonly BindableWithCurrent<T> current;

public SliderWithTextBoxInput(LocalisableString labelText)
{
RelativeSizeAxes = Axes.X;
Expand Down Expand Up @@ -79,10 +105,26 @@ public SliderWithTextBoxInput(LocalisableString labelText)
},
};

current = new BindableWithCurrent<T>();
current.BindValueChanged(c =>
{
if (!updatingFromTextBox)
{
decimal decimalValue = c.NewValue.ToDecimal(NumberFormatInfo.InvariantInfo);
textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}");
}

slider.Current.Value = c.NewValue;
}, true);

textBox.OnCommit += textCommitted;
textBox.Current.BindValueChanged(textChanged);

Current.BindValueChanged(updateTextBoxFromSlider, true);
slider.Current.BindValueChanged(c =>
{
if (!updatingFromTextBox)
current.Value = c.NewValue;
});
}

public bool TakeFocus() => GetContainingInputManager().ChangeFocus(textBox);
Expand Down Expand Up @@ -110,7 +152,7 @@ private void tryUpdateSliderFromTextBox()

try
{
switch (slider.Current)
switch (current)
{
case Bindable<int> bindableInt:
bindableInt.Value = int.Parse(textBox.Current.Value);
Expand All @@ -121,7 +163,7 @@ private void tryUpdateSliderFromTextBox()
break;

default:
slider.Current.Parse(textBox.Current.Value, CultureInfo.CurrentCulture);
current.Parse(textBox.Current.Value, CultureInfo.CurrentCulture);
break;
}
}
Expand All @@ -133,13 +175,5 @@ private void tryUpdateSliderFromTextBox()

updatingFromTextBox = false;
}

private void updateTextBoxFromSlider(ValueChangedEvent<T> _)
{
if (updatingFromTextBox) return;

decimal decimalValue = slider.Current.Value.ToDecimal(NumberFormatInfo.InvariantInfo);
textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}");
}
}
}
3 changes: 2 additions & 1 deletion osu.Game/Screens/Edit/Timing/EffectSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ private void load()
scrollSpeedSlider = new SliderWithTextBoxInput<double>("Scroll Speed")
{
Current = new EffectControlPoint().ScrollSpeedBindable,
KeyboardStep = 0.1f
KeyboardStep = 0.1f,
SliderPrecision = 0.1f,
}
});
}
Expand Down

0 comments on commit 0bacf69

Please sign in to comment.