Skip to content

Commit 26d86a5

Browse files
authored
Merge pull request #6565 from Kruchji/relative-drag-click-fix
Fix second button click moving slider while dragging
2 parents 96862f4 + 6462479 commit 26d86a5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs

+30
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,36 @@ public void TestRelativeClick()
299299
checkValue(0);
300300
}
301301

302+
[Test]
303+
public void TestClickSecondButtonWhileRelativeDragging()
304+
{
305+
checkValue(0);
306+
307+
AddStep("Move Cursor", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.6f, 0.5f))); });
308+
AddStep("Click", () => { InputManager.PressButton(MouseButton.Left); });
309+
AddStep("Drag", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.25f, 0.5f))); });
310+
AddStep("Second Button Click", () => { InputManager.Click(MouseButton.Right); });
311+
AddStep("Drag", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.3f, 0.5f))); });
312+
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
313+
314+
checkValue(-6);
315+
}
316+
317+
[Test]
318+
public void TestClickSecondButtonWhileAbsoluteDragging()
319+
{
320+
checkValue(0);
321+
322+
AddStep("Move Cursor", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.8f, 0.5f))); });
323+
AddStep("Click", () => { InputManager.PressButton(MouseButton.Left); });
324+
AddStep("Drag", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.25f, 0.5f))); });
325+
AddStep("Second Button Click", () => { InputManager.Click(MouseButton.Right); });
326+
AddStep("Drag", () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.3f, 0.5f))); });
327+
AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); });
328+
329+
checkValue(-4);
330+
}
331+
302332
private void checkValue(int expected) =>
303333
AddAssert($"Value == {expected}", () => sliderBarValue.Value, () => Is.EqualTo(expected).Within(Precision.FLOAT_EPSILON));
304334

osu.Framework/Graphics/UserInterface/SliderBar.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ protected override void LoadComplete()
119119

120120
protected override bool OnMouseDown(MouseDownEvent e)
121121
{
122+
// Relative value at MouseDown shouldn't change until dragging ends.
123+
if (IsDragged)
124+
return base.OnMouseDown(e);
125+
122126
if (ShouldHandleAsRelativeDrag(e))
123127
{
124128
float min = float.CreateTruncating(currentNumberInstantaneous.MinValue);
@@ -171,7 +175,10 @@ protected override bool OnDragStart(DragStartEvent e)
171175
return true;
172176
}
173177

174-
protected override void OnDragEnd(DragEndEvent e) => Commit();
178+
protected override void OnDragEnd(DragEndEvent e)
179+
{
180+
Commit();
181+
}
175182

176183
public override bool AcceptsFocus => true;
177184

0 commit comments

Comments
 (0)