mirror of
https://gitee.com/chinware/atomui.git
synced 2024-12-02 03:47:52 +08:00
完成 slider 颜色
This commit is contained in:
parent
d2aeb89d07
commit
55ca06f9e0
@ -1,4 +1,8 @@
|
||||
using Avalonia;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Automation.Peers;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
@ -24,10 +28,10 @@ public class SliderThumb : TemplatedControl
|
||||
AvaloniaProperty.Register<SliderThumb, IBrush?>(nameof(OutlineBrush));
|
||||
|
||||
public static readonly StyledProperty<Thickness> OutlineThicknessProperty =
|
||||
AvaloniaProperty.Register<TemplatedControl, Thickness>(nameof(OutlineThickness));
|
||||
AvaloniaProperty.Register<SliderThumb, Thickness>(nameof(OutlineThickness));
|
||||
|
||||
public static readonly StyledProperty<double> ThumbCircleSizeProperty =
|
||||
AvaloniaProperty.Register<TemplatedControl, double>(nameof(ThumbCircleSize));
|
||||
AvaloniaProperty.Register<SliderThumb, double>(nameof(ThumbCircleSize));
|
||||
|
||||
private Point? _lastPoint;
|
||||
|
||||
@ -43,6 +47,14 @@ public class SliderThumb : TemplatedControl
|
||||
BorderBrushProperty);
|
||||
}
|
||||
|
||||
public SliderThumb()
|
||||
{
|
||||
var transitions = new Transitions();
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(OutlineBrushProperty, GlobalResourceKey.MotionDurationFast));
|
||||
transitions.Add(AnimationUtils.CreateTransition<ThicknessTransition>(OutlineThicknessProperty, GlobalResourceKey.MotionDurationFast));
|
||||
Transitions = transitions;
|
||||
}
|
||||
|
||||
public event EventHandler<VectorEventArgs>? DragStarted
|
||||
{
|
||||
add => AddHandler(DragStartedEvent, value);
|
||||
@ -83,7 +95,14 @@ public class SliderThumb : TemplatedControl
|
||||
{
|
||||
if (_lastPoint.HasValue) _lastPoint = _lastPoint.Value + v;
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
Console.WriteLine(change.Property.Name);
|
||||
Console.WriteLine(Transitions?.Count);
|
||||
}
|
||||
|
||||
protected override AutomationPeer OnCreateAutomationPeer() => new SliderThumbAutomationPeer(this);
|
||||
|
||||
protected virtual void OnDragStarted(VectorEventArgs e) { }
|
||||
@ -162,6 +181,7 @@ public class SliderThumb : TemplatedControl
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
Console.WriteLine("xxxx");
|
||||
// 绘制圆
|
||||
var centerPos = new Point(Bounds.Width / 2, Bounds.Height / 2);
|
||||
var thumbCircleRadius = ThumbCircleSize / 2 + BorderThickness.Left / 2;
|
||||
|
@ -2,6 +2,7 @@
|
||||
using AtomUI.Styling;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
@ -274,6 +275,12 @@ public class SliderTrack : Control, IControlCustomStyle
|
||||
BindUtils.CreateTokenBinding(this, SliderTrack.SliderRailSizeProperty, SliderResourceKey.RailSize);
|
||||
|
||||
HandleRangeModeChanged();
|
||||
if (Transitions is null) {
|
||||
var transitions = new Transitions();
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(TrackGrooveBrushProperty));
|
||||
transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(TrackBarBrushProperty));
|
||||
Transitions = transitions;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRangeModeChanged()
|
||||
@ -329,20 +336,6 @@ public class SliderTrack : Control, IControlCustomStyle
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsNeedHandlePressedForValue(Point point)
|
||||
{
|
||||
if ((StartSliderThumb is not null &&
|
||||
StartSliderThumb.IsVisible &&
|
||||
StartSliderThumb.Bounds.Contains(point)) ||
|
||||
EndSliderThumb is not null &&
|
||||
EndSliderThumb.IsVisible &&
|
||||
EndSliderThumb.Bounds.Contains(point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Point GetGlobalOffset()
|
||||
{
|
||||
var topLevel = TopLevel.GetTopLevel(this);
|
||||
@ -667,12 +660,9 @@ public class SliderTrack : Control, IControlCustomStyle
|
||||
void IControlCustomStyle.PrepareRenderInfo()
|
||||
{
|
||||
_renderContextData = new RenderContextData();
|
||||
|
||||
var startThumbPivotOffset = 0d;
|
||||
var endThumbPivotOffset = 0d;
|
||||
CalculateThumbValuePivotOffset(Bounds.Size, Orientation == Orientation.Vertical,
|
||||
out startThumbPivotOffset,
|
||||
out endThumbPivotOffset);
|
||||
out var startThumbPivotOffset,
|
||||
out var endThumbPivotOffset);
|
||||
var thumbSize = StartSliderThumb!.DesiredSize.Width;
|
||||
if (Orientation == Orientation.Horizontal) {
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user