This commit is contained in:
NaBian 2021-11-22 23:55:42 +08:00
parent 287e5982c4
commit 24af66624f
2 changed files with 39 additions and 26 deletions

View File

@ -271,16 +271,11 @@ namespace HandyControl.Controls
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;
}
}
}

View File

@ -26,8 +26,6 @@ namespace HandyControl.Controls
private double Density { get; set; } = double.NaN;
private double ThumbStartCenterOffset { get; set; } = double.NaN;
public RepeatButton DecreaseRepeatButton
{
get => _decreaseButton;
@ -257,13 +255,12 @@ namespace HandyControl.Controls
: 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
{
@ -291,20 +288,45 @@ namespace HandyControl.Controls
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)
@ -372,17 +394,13 @@ namespace HandyControl.Controls
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)