mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-29 15:19:12 +08:00
Refactor IconPresenter
This commit is contained in:
@@ -5,7 +5,6 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Metadata;
|
||||
|
||||
@@ -142,16 +141,6 @@ public class IconPresenter : TemplatedControl, IMotionAwareControl
|
||||
UpdatePseudoClasses();
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
return LayoutHelper.MeasureChild(Icon, availableSize, Padding);
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
return LayoutHelper.ArrangeChild(Icon, finalSize, Padding);
|
||||
}
|
||||
|
||||
private void ChildChanged(AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
var oldChild = (Control?)e.OldValue;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
<Setter Property="IsMotionEnabled" Value="{DynamicResource {x:Static atom:SharedTokenKey.EnableMotion}}" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Height" Value="{DynamicResource {x:Static atom:SharedTokenKey.IconSize}}" />
|
||||
<Setter Property="Width" Value="{DynamicResource {x:Static atom:SharedTokenKey.IconSize}}" />
|
||||
|
||||
@@ -196,7 +196,6 @@ public class Icon : PathIcon, IMotionAwareControl
|
||||
{
|
||||
_sourceGeometriesData = new List<Geometry>();
|
||||
_transforms = new List<Matrix>();
|
||||
this.ConfigureMotionBindingStyle();
|
||||
Classes.CollectionChanged += HandlePseudoClassesChanged;
|
||||
}
|
||||
|
||||
@@ -507,7 +506,7 @@ public class Icon : PathIcon, IMotionAwareControl
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
base.MeasureOverride(availableSize);
|
||||
var size = base.MeasureOverride(availableSize);
|
||||
if (_sourceGeometriesData.Count == 0)
|
||||
{
|
||||
return default;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
@@ -23,7 +22,7 @@ public abstract class IconProvider<TIconKind> : MarkupExtension
|
||||
|
||||
public double Width { get; set; } = double.NaN;
|
||||
public double Height { get; set; } = double.NaN;
|
||||
public IconAnimation Animation { get; set; } = IconAnimation.None;
|
||||
public IconAnimation? Animation { get; set; }
|
||||
|
||||
public IconProvider()
|
||||
{
|
||||
@@ -38,15 +37,39 @@ public abstract class IconProvider<TIconKind> : MarkupExtension
|
||||
{
|
||||
Debug.Assert(Kind != null);
|
||||
var icon = GetIcon(Kind);
|
||||
icon.SetCurrentValue(Icon.LoadingAnimationProperty, Animation);
|
||||
|
||||
icon.SetValue(Icon.NormalFilledBrushProperty, NormalFilledColor, NormalFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
icon.SetValue(Icon.ActiveFilledBrushProperty, ActiveFilledColor, ActiveFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
icon.SetValue(Icon.SelectedFilledBrushProperty, SelectedFilledColor, SelectedFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
icon.SetValue(Icon.DisabledFilledBrushProperty, DisabledFilledColor, DisabledFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
icon.SetValue(Icon.PrimaryFilledBrushProperty, PrimaryFilledColor, PrimaryFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
icon.SetValue(Icon.SecondaryFilledBrushProperty, SecondaryFilledColor, SecondaryFilledColor != null ? BindingPriority.LocalValue : BindingPriority.Template);
|
||||
|
||||
if (Animation != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.LoadingAnimationProperty, Animation);
|
||||
}
|
||||
|
||||
if (NormalFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.NormalFilledBrushProperty, NormalFilledColor);
|
||||
}
|
||||
if (ActiveFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.ActiveFilledBrushProperty, ActiveFilledColor);
|
||||
}
|
||||
if (SelectedFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.SelectedFilledBrushProperty, SelectedFilledColor);
|
||||
}
|
||||
|
||||
if (DisabledFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.DisabledFilledBrushProperty, DisabledFilledColor);
|
||||
}
|
||||
|
||||
if (PrimaryFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.PrimaryFilledBrushProperty, PrimaryFilledColor);
|
||||
}
|
||||
if (SecondaryFilledColor != null)
|
||||
{
|
||||
icon.SetCurrentValue(Icon.SecondaryFilledBrushProperty, SecondaryFilledColor);
|
||||
}
|
||||
|
||||
if (!double.IsNaN(Width))
|
||||
{
|
||||
icon.SetCurrentValue(Layoutable.WidthProperty, Width);
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorPrimaryActive}}" />
|
||||
<Setter Property="DisabledIconBrush"
|
||||
Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorTextDisabled}}" />
|
||||
<Setter Property="Width" Value="{DynamicResource {x:Static atom:ButtonSpinnerTokenKey.HandleIconSize}}" />
|
||||
<Setter Property="Height"
|
||||
<Setter Property="IconWidth" Value="{DynamicResource {x:Static atom:ButtonSpinnerTokenKey.HandleIconSize}}" />
|
||||
<Setter Property="IconHeight"
|
||||
Value="{DynamicResource {x:Static atom:ButtonSpinnerTokenKey.HandleIconSize}}" />
|
||||
</Style>
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<atom:IconPresenter Name="IconPresenter"
|
||||
DockPanel.Dock="Left"
|
||||
Icon="{TemplateBinding Icon}"
|
||||
NormalFilledBrush="{TemplateBinding Foreground}" />
|
||||
NormalFilledBrush="{TemplateBinding Foreground}"
|
||||
IsVisible="{TemplateBinding Icon, Converter={x:Static ObjectConverters.IsNotNull}}"/>
|
||||
<atom:IconButton Name="{x:Static atom:TagThemeConstants.CloseButtonPart}"
|
||||
DockPanel.Dock="Right"
|
||||
IsVisible="{TemplateBinding IsClosable}"
|
||||
|
||||
Reference in New Issue
Block a user