Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong range constrained bindable value transferal in CopyTo() #5542

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions osu.Framework.Tests/Bindables/RangeConstrainedBindableTest.cs
Original file line number Diff line number Diff line change
@@ -101,6 +101,30 @@ public void TestDefaultMinValueAppliedInConstructor()
Assert.That(bindable.Value, Is.EqualTo(3));
}

[Test]
public void TestBindToAnotherBindableWithDisjointRange()
{
var first = new BindableDouble
{
MinValue = -10,
MaxValue = -5,
Value = -7
};

var second = new BindableDouble
{
MinValue = 5,
MaxValue = 10,
Value = 9
};

first.BindTo(second);

Assert.That(first.MinValue, Is.EqualTo(5));
Assert.That(first.MaxValue, Is.EqualTo(10));
Assert.That(first.Value, Is.EqualTo(9));
}

private class BindableNumberWithDefaultMaxValue : BindableInt
{
public BindableNumberWithDefaultMaxValue(int value = 0)
6 changes: 4 additions & 2 deletions osu.Framework/Bindables/RangeConstrainedBindable.cs
Original file line number Diff line number Diff line change
@@ -160,13 +160,15 @@ protected void TriggerMaxValueChange(RangeConstrainedBindable<T> source = null,

public override void CopyTo(Bindable<T> them)
{
base.CopyTo(them);

// if the other bindable is range-constrained, the bounds need to be copied across first,
// as Value assignment (in the base call below) automatically clamps to [MinValue, MaxValue].
if (them is RangeConstrainedBindable<T> other)
{
other.MinValue = MinValue;
other.MaxValue = MaxValue;
}

base.CopyTo(them);
}

public override void BindTo(Bindable<T> them)