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 slider behaviour for bigger thumbs #7016

Merged
merged 1 commit into from
Nov 25, 2021
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
17 changes: 9 additions & 8 deletions src/Avalonia.Controls/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,17 @@ private void TrackPressed(object sender, PointerPressedEventArgs e)
}
}

private void MoveToPoint(PointerPoint x)
private void MoveToPoint(PointerPoint posOnTrack)
{
var orient = Orientation == Orientation.Horizontal;

var pointDen = orient ? _track.Bounds.Width : _track.Bounds.Height;
// Just add epsilon to avoid NaN in case 0/0
pointDen += double.Epsilon;

var pointNum = orient ? x.Position.X : x.Position.Y;
var logicalPos = MathUtilities.Clamp(pointNum / pointDen, 0.0d, 1.0d);
var thumbLength = (orient
? _track.Thumb.Bounds.Width
: _track.Thumb.Bounds.Height) + double.Epsilon;
var trackLength = (orient
? _track.Bounds.Width
: _track.Bounds.Height) - thumbLength;
var trackPos = orient ? posOnTrack.Position.X : posOnTrack.Position.Y;
var logicalPos = MathUtilities.Clamp((trackPos - thumbLength * 0.5) / trackLength, 0.0d, 1.0d);
var invert = orient ?
IsDirectionReversed ? 1 : 0 :
IsDirectionReversed ? 0 : 1;
Expand Down