Skip to content

Commit

Permalink
fix: fixed #1050
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Nov 22, 2021
1 parent 287e598 commit 24af666
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,11 @@ private void MoveToNextTick(double direction, bool isStart, bool isCenter = fals
var newValue = _track.ValueFromPoint(pt);
if (ValidateHelper.IsInRangeOfDouble(newValue))
{
var dir = (ValueStart + ValueEnd) / 2 > newValue;
if (!dir)
isStart = (ValueStart + ValueEnd) / 2 > newValue;
if (!isStart)
{
isStart = false;
direction = -Math.Abs(direction);
}
else
{
isStart = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class RangeTrack : FrameworkElement

private double Density { get; set; } = double.NaN;

private double ThumbStartCenterOffset { get; set; } = double.NaN;

public RepeatButton DecreaseRepeatButton
{
get => _decreaseButton;
Expand Down Expand Up @@ -257,13 +255,12 @@ protected override Size ArrangeOverride(Size arrangeSize)
: increaseButtonLength + thumbStartLength + centerButtonLength;
pieceSize.Height = thumbStartLength;

ThumbStart?.Arrange(new Rect(offset, pieceSize));
ThumbStartCenterOffset = offset.Y + thumbStartLength * 0.5;
ArrangeThumb(isDirectionReversed, false, offset, pieceSize);

offset.Y = isDirectionReversed ? decreaseButtonLength : increaseButtonLength;
pieceSize.Height = thumbEndLength;

ThumbEnd?.Arrange(new Rect(offset, pieceSize));
ArrangeThumb(isDirectionReversed, true, offset, pieceSize);
}
else
{
Expand Down Expand Up @@ -291,20 +288,45 @@ protected override Size ArrangeOverride(Size arrangeSize)
offset.X = isDirectionReversed ? increaseButtonLength : decreaseButtonLength;
pieceSize.Width = thumbStartLength;

ThumbStart?.Arrange(new Rect(offset, pieceSize));
ThumbStartCenterOffset = offset.X + thumbStartLength * 0.5;
ArrangeThumb(isDirectionReversed, false, offset, pieceSize);

offset.X = isDirectionReversed
? increaseButtonLength + thumbStartLength + centerButtonLength
: decreaseButtonLength + thumbEndLength + centerButtonLength;
pieceSize.Width = thumbEndLength;

ThumbEnd?.Arrange(new Rect(offset, pieceSize));
ArrangeThumb(isDirectionReversed, true, offset, pieceSize);
}

return arrangeSize;
}

private void ArrangeThumb(bool isDirectionReversed, bool isStart, Point offset, Size pieceSize)
{
if (isStart)
{
if (isDirectionReversed)
{
ThumbStart?.Arrange(new Rect(offset, pieceSize));
}
else
{
ThumbEnd?.Arrange(new Rect(offset, pieceSize));
}
}
else
{
if (isDirectionReversed)
{
ThumbEnd?.Arrange(new Rect(offset, pieceSize));
}
else
{
ThumbStart?.Arrange(new Rect(offset, pieceSize));
}
}
}

private void ComputeLengths(Size arrangeSize, bool isVertical, out double decreaseButtonLength,
out double centerButtonLength, out double increaseButtonLength, out double thumbStartLength,
out double thumbEndLength)
Expand Down Expand Up @@ -372,17 +394,13 @@ private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyCha

public virtual double ValueFromPoint(Point pt)
{
double val;
// Find distance from center of thumb to given point.
if (Orientation == Orientation.Horizontal)
{
val = ValueStart + ValueFromDistance(pt.X - ThumbStartCenterOffset, pt.Y - RenderSize.Height * 0.5);
}
else
{
val = ValueStart + ValueFromDistance(pt.X - RenderSize.Width * 0.5, pt.Y - ThumbStartCenterOffset);
}
return Math.Max(Minimum, Math.Min(Maximum, val));
return Orientation == Orientation.Horizontal
? !IsDirectionReversed
? pt.X / RenderSize.Width * Maximum
: (1 - pt.X / RenderSize.Width) * Maximum
: !IsDirectionReversed
? pt.Y / RenderSize.Height * Maximum
: (1 - pt.X / RenderSize.Height) * Maximum;
}

public virtual double ValueFromDistance(double horizontal, double vertical)
Expand Down

0 comments on commit 24af666

Please sign in to comment.