完成AtomUI -> AtomUI.Theme 重构

This commit is contained in:
polarboy 2024-07-29 23:40:17 +08:00
parent 09da5fb309
commit 47555e07be
148 changed files with 282 additions and 262 deletions

View File

@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtomUI", "src\AtomUI\AtomUI.csproj", "{87085491-3C99-4C8F-8FA6-F179B9569CE8}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtomUI.Theme", "src\AtomUI.Theme\AtomUI.Theme.csproj", "{87085491-3C99-4C8F-8FA6-F179B9569CE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AtomUI.Base", "src\AtomUI.Base\AtomUI.Base.csproj", "{8FFEB15F-7E48-4AF4-B708-8E96A68CF2D9}"
EndProject

View File

@ -31,7 +31,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\AtomUI.Controls\AtomUI.Controls.csproj" />
<ProjectReference Include="..\..\src\AtomUI.Icon.AntDesign\AtomUI.Icon.AntDesign.csproj" />
<ProjectReference Include="..\..\src\AtomUI\AtomUI.csproj" />
<ProjectReference Include="..\..\src\AtomUI.Theme\AtomUI.Theme.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,5 @@
using System.Collections.ObjectModel;
using AtomUI.ColorSystem;
using AtomUI.Palette;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;

View File

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AtomUI.Base</PackageId>
<RootNamespace>AtomUI</RootNamespace>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<GeneratePackageOnBuild Condition=" '$(Configuration)' != 'Debug' ">True</GeneratePackageOnBuild>

View File

@ -0,0 +1,48 @@
using Avalonia;
using Avalonia.Data;
namespace AtomUI.Data;
public static class BindUtils
{
public static IDisposable RelayBind(AvaloniaObject source, AvaloniaProperty sourceProperty, AvaloniaObject target,
AvaloniaProperty? targetProperty = null,
BindingMode mode = BindingMode.Default)
{
targetProperty ??= sourceProperty;
var registry = AvaloniaPropertyRegistry.Instance;
if (!registry.IsRegistered(source.GetType(), sourceProperty)) {
throw new ArgumentException($"Relay source property is not registered for: {source.GetType().Name}.");
}
if (!registry.IsRegistered(target.GetType(), targetProperty)) {
throw new ArgumentException($"Relay target property is not registered for: {target.GetType().Name}.");
}
var descriptor = new IndexerDescriptor
{
Source = source,
Property = sourceProperty,
Priority = BindingPriority.Inherited,
Mode = mode
};
return target.Bind(targetProperty, descriptor);
}
public static IDisposable RelayBind<TSource, TResult>(AvaloniaObject source, AvaloniaProperty<TSource> sourceProperty,
AvaloniaObject target, AvaloniaProperty<TResult> targetProperty,
Func<TSource, TResult> converter,
BindingPriority priority = BindingPriority.Template)
{
var registry = AvaloniaPropertyRegistry.Instance;
if (!registry.IsRegistered(source.GetType(), sourceProperty)) {
throw new ArgumentException($"Relay source property is not registered for: {source.GetType().Name}.");
}
if (!registry.IsRegistered(target.GetType(), targetProperty)) {
throw new ArgumentException($"Relay target property is not registered for: {target.GetType().Name}.");
}
return target.Bind(targetProperty, source.GetObservable(sourceProperty, converter), priority);
}
}

View File

@ -2,7 +2,7 @@
using AtomUI.Utils;
using Avalonia.Media;
namespace AtomUI.ColorSystem;
namespace AtomUI.Media;
public static class ColorExtensions
{

View File

@ -1,5 +1,4 @@
using AtomUI.Utils;
using Avalonia.Animation;
using Avalonia.Animation;
using Avalonia.Media;
namespace AtomUI.Media;
@ -8,6 +7,6 @@ public class ColorTransition : InterpolatingTransitionBase<Color>
{
protected override Color Interpolate(double progress, Color from, Color to)
{
return AnimationUtils.ColorInterpolate(from, to, progress);
return InterpolateUtils.ColorInterpolate(from, to, progress);
}
}

View File

@ -1,7 +1,7 @@
using AtomUI.Utils;
using Avalonia.Media;
namespace AtomUI.ColorSystem;
namespace AtomUI.Media;
public enum WCAG2Level
{

View File

@ -0,0 +1,50 @@
using Avalonia.Media;
namespace AtomUI.Media;
public static class InterpolateUtils
{
public static Color ColorInterpolate(Color fromColor, Color toColor, double progress)
{
double a1 = fromColor.GetAlphaF();
double r1 = fromColor.GetRedF() * a1;
double g1 = fromColor.GetGreenF() * a1;
double b1 = fromColor.GetBlueF() * a1;
double a2 = toColor.GetAlphaF();
double r2 = toColor.GetRedF() * a2;
double g2 = toColor.GetGreenF() * a2;
double b2 = toColor.GetBlueF() * a2;
double r = DoubleInterpolate(r1, r2, progress);
double g = DoubleInterpolate(g1, g2, progress);
double b = DoubleInterpolate(b1, b2, progress);
double a = DoubleInterpolate(a1, a2, progress);
// 处理接近完全透明的情况
if (a < 1e-5) {
// 在这种情况下我们可以选择直接使用目标颜色的RGB分量
r = toColor.GetRedF();
g = toColor.GetGreenF();
b = toColor.GetBlueF();
} else {
// 如果alpha不为零反预乘alpha
r /= a;
g /= a;
b /= a;
}
// 防止颜色分量超出范围
r = Math.Clamp(r, 0.0f, 1.0f);
g = Math.Clamp(g, 0.0f, 1.0f);
b = Math.Clamp(b, 0.0f, 1.0f);
a = Math.Clamp(a, 0.0f, 1.0f);
return ColorUtils.FromRgbF(a, r, g, b);
}
public static double DoubleInterpolate(double oldValue, double newValue, double progress)
{
return ((newValue - oldValue) * progress) + oldValue;
}
}

View File

@ -1,5 +1,4 @@
using AtomUI.Utils;
using Avalonia.Animation;
using Avalonia.Animation;
using Avalonia.Media;
using Avalonia.Media.Immutable;
@ -15,7 +14,7 @@ public class SolidColorBrushTransition : InterpolatingTransitionBase<IBrush?>
if (from is ISolidColorBrush fromBrush && to is ISolidColorBrush toBrush) {
return new ImmutableSolidColorBrush(
AnimationUtils.ColorInterpolate(fromBrush.Color, toBrush.Color, progress),
InterpolateUtils.ColorInterpolate(fromBrush.Color, toBrush.Color, progress),
DoubleInterpolate(progress, from.Opacity, to.Opacity));
}
// TODO 不知道这样返回是否合适

View File

@ -1,4 +1,5 @@
using System.Reflection;
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Utils;
using Avalonia;

View File

@ -130,7 +130,7 @@ public class Alert : TemplatedControl, IControlCustomStyle
void IControlCustomStyle.HandleTemplateApplied(INameScope scope)
{
BindUtils.CreateTokenBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness,
TokenResourceBinder.CreateTokenBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness,
BindingPriority.Template,
new RenderScaleAwareThicknessConfigure(this));
SetupCloseButton();
@ -152,8 +152,8 @@ public class Alert : TemplatedControl, IControlCustomStyle
{
Kind = "CloseOutlined",
};
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorIcon);
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.ActiveFilledBrushProperty, GlobalResourceKey.ColorIconHover);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorIcon);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.ActiveFilledBrushProperty, GlobalResourceKey.ColorIconHover);
}
}

View File

@ -1,4 +1,5 @@
using AtomUI.Styling;
using AtomUI.Data;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
@ -274,9 +275,9 @@ internal class AlertTheme : ControlTheme
Name = CloseBtnPart,
};
BindUtils.CreateTokenBinding(closeBtn, IconButton.WidthProperty, GlobalResourceKey.IconSizeSM);
BindUtils.CreateTokenBinding(closeBtn, IconButton.HeightProperty, GlobalResourceKey.IconSizeSM);
BindUtils.CreateTokenBinding(closeBtn, IconButton.MarginProperty, AlertResourceKey.ExtraElementMargin);
TokenResourceBinder.CreateTokenBinding(closeBtn, IconButton.WidthProperty, GlobalResourceKey.IconSizeSM);
TokenResourceBinder.CreateTokenBinding(closeBtn, IconButton.HeightProperty, GlobalResourceKey.IconSizeSM);
TokenResourceBinder.CreateTokenBinding(closeBtn, IconButton.MarginProperty, AlertResourceKey.ExtraElementMargin);
CreateTemplateParentBinding(closeBtn, IconButton.IsVisibleProperty, Alert.IsClosableProperty);
CreateTemplateParentBinding(closeBtn, IconButton.IconProperty, Alert.CloseIconProperty);
@ -349,7 +350,7 @@ internal class AlertTheme : ControlTheme
Padding = new Thickness(0),
IsVisible = !string.IsNullOrEmpty(alert.Description)
};
BindUtils.CreateTokenBinding(descriptionLabel, Label.MarginProperty, GlobalResourceKey.MarginXS, BindingPriority.Template,
TokenResourceBinder.CreateTokenBinding(descriptionLabel, Label.MarginProperty, GlobalResourceKey.MarginXS, BindingPriority.Template,
o =>
{
if (o is double value) {

View File

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AtomUI.Controls</PackageId>
<RootNamespace>AtomUI.Controls</RootNamespace>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>GeneratedFiles</CompilerGeneratedFilesOutputPath>
@ -15,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AtomUI\AtomUI.csproj" />
<ProjectReference Include="..\AtomUI.Theme\AtomUI.Theme.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Svg"/>

View File

@ -1,14 +1,13 @@
using AtomUI.ColorSystem;
using AtomUI.Controls.Badge;
using AtomUI.Controls.Badge;
using AtomUI.Controls.MotionScene;
using AtomUI.Data;
using AtomUI.MotionScene;
using AtomUI.Palette;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Metadata;
@ -262,7 +261,7 @@ public class CountBadge : Control, IControlCustomStyle
BindUtils.RelayBind(this, OverflowCountProperty, _badgeAdorner, CountBadgeAdorner.OverflowCountProperty);
BindUtils.RelayBind(this, CountProperty, _badgeAdorner, CountBadgeAdorner.CountProperty);
}
BindUtils.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow);
TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow);
}
private void HandleDecoratedTargetChanged()

View File

@ -1,14 +1,13 @@
using AtomUI.ColorSystem;
using AtomUI.Controls.Badge;
using AtomUI.Controls.Badge;
using AtomUI.Controls.MotionScene;
using AtomUI.Data;
using AtomUI.MotionScene;
using AtomUI.Palette;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Metadata;
@ -215,7 +214,7 @@ public partial class DotBadge : Control, IControlCustomStyle
BindUtils.RelayBind(this, TextProperty, _dotBadgeAdorner, DotBadgeAdorner.TextProperty);
BindUtils.RelayBind(this, OffsetProperty, _dotBadgeAdorner, DotBadgeAdorner.OffsetProperty);
}
BindUtils.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow);
TokenResourceBinder.CreateTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationSlow);
}
private void HandleDecoratedTargetChanged()

View File

@ -1,14 +1,11 @@
using AtomUI.ColorSystem;
using AtomUI.Data;
using AtomUI.Palette;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Metadata;
using Avalonia.VisualTree;
namespace AtomUI.Controls;

View File

@ -1,5 +1,5 @@
using AtomUI.ColorSystem;
using AtomUI.Controls.Utils;
using AtomUI.Controls.Utils;
using AtomUI.Media;
using AtomUI.Styling;
using Avalonia;
using Avalonia.Controls;

View File

@ -236,20 +236,20 @@ public class Button : AvaloniaButton,
private void SetupControlTheme()
{
if (ButtonType == ButtonType.Default) {
BindUtils.CreateTokenBinding(this, ThemeProperty, DefaultButtonTheme.ID);
TokenResourceBinder.CreateTokenBinding(this, ThemeProperty, DefaultButtonTheme.ID);
} else if (ButtonType == ButtonType.Primary) {
BindUtils.CreateTokenBinding(this, ThemeProperty, PrimaryButtonTheme.ID);
TokenResourceBinder.CreateTokenBinding(this, ThemeProperty, PrimaryButtonTheme.ID);
} else if (ButtonType == ButtonType.Text) {
BindUtils.CreateTokenBinding(this, ThemeProperty, TextButtonTheme.ID);
TokenResourceBinder.CreateTokenBinding(this, ThemeProperty, TextButtonTheme.ID);
} else if (ButtonType == ButtonType.Link) {
BindUtils.CreateTokenBinding(this, ThemeProperty, LinkButtonTheme.ID);
TokenResourceBinder.CreateTokenBinding(this, ThemeProperty, LinkButtonTheme.ID);
}
}
void ApplyShapeStyleConfig()
{
if (Shape == ButtonShape.Circle) {
BindUtils.CreateTokenBinding(this, PaddingProperty, ButtonResourceKey.CirclePadding);
TokenResourceBinder.CreateTokenBinding(this, PaddingProperty, ButtonResourceKey.CirclePadding);
}
}

View File

@ -1,4 +1,4 @@
using AtomUI.ColorSystem;
using AtomUI.Media;
using Avalonia.Media;
namespace AtomUI.Controls;

View File

@ -1,4 +1,4 @@
using AtomUI.ColorSystem;
using AtomUI.Media;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
@ -114,10 +114,10 @@ public partial class EmptyIndicator : TemplatedControl,
void IControlCustomStyle.SetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, ColorFillTokenProperty, GlobalResourceKey.ColorFill);
BindUtils.CreateTokenBinding(this, ColorFillTertiaryTokenProperty, GlobalResourceKey.ColorFillTertiary);
BindUtils.CreateTokenBinding(this, ColorFillQuaternaryTokenProperty, GlobalResourceKey.ColorFillQuaternary);
BindUtils.CreateTokenBinding(this, ColorBgContainerTokenProperty, GlobalResourceKey.ColorBgContainer);
TokenResourceBinder.CreateTokenBinding(this, ColorFillTokenProperty, GlobalResourceKey.ColorFill);
TokenResourceBinder.CreateTokenBinding(this, ColorFillTertiaryTokenProperty, GlobalResourceKey.ColorFillTertiary);
TokenResourceBinder.CreateTokenBinding(this, ColorFillQuaternaryTokenProperty, GlobalResourceKey.ColorFillQuaternary);
TokenResourceBinder.CreateTokenBinding(this, ColorBgContainerTokenProperty, GlobalResourceKey.ColorBgContainer);
}
private void SetupImage()

View File

@ -1,4 +1,5 @@
using AtomUI.Styling;
using AtomUI.Data;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
@ -42,7 +43,7 @@ internal class EmptyIndicatorTheme : ControlTheme
Text = indicator.Description ?? "No data"
};
BindUtils.CreateTokenBinding(description, TextBlock.ForegroundProperty, GlobalResourceKey.ColorTextDescription);
TokenResourceBinder.CreateTokenBinding(description, TextBlock.ForegroundProperty, GlobalResourceKey.ColorTextDescription);
BindUtils.RelayBind(indicator, EmptyIndicator.DescriptionMarginProperty, description, TextBlock.MarginProperty,
d => new Thickness(0, d, 0, 0));
layout.Children.Add(description);

View File

@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Reactive.Disposables;
using AtomUI.Data;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
@ -115,8 +116,8 @@ public class Flyout : PopupFlyoutBase
public Flyout()
{
BindUtils.CreateGlobalTokenBinding(this, MotionDurationTokenProperty, GlobalResourceKey.MotionDurationMid);
BindUtils.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
TokenResourceBinder.CreateGlobalTokenBinding(this, MotionDurationTokenProperty, GlobalResourceKey.MotionDurationMid);
TokenResourceBinder.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
}
private void HandlePopupPropertyChanged(AvaloniaPropertyChangedEventArgs args)

View File

@ -1,4 +1,5 @@
using System.Reactive.Disposables;
using AtomUI.Data;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
@ -161,7 +162,7 @@ public class FlyoutHost : Control
((ISetLogicalParent)AnchorTarget).SetParent(this);
VisualChildren.Add(AnchorTarget);
}
BindUtils.CreateGlobalTokenBinding(this, MarginToAnchorProperty, GlobalResourceKey.MarginXXS);
TokenResourceBinder.CreateGlobalTokenBinding(this, MarginToAnchorProperty, GlobalResourceKey.MarginXXS);
_initialized = true;
}
}

View File

@ -27,13 +27,13 @@ public class MenuFlyoutPresenterTheme : ControlTheme
ClipToBounds = false,
UseLayoutRounding = false
};
BindUtils.CreateTokenBinding(wrapper, Border.BackgroundProperty, MenuResourceKey.MenuBgColor);
BindUtils.CreateTokenBinding(wrapper, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
BindUtils.CreateTokenBinding(wrapper, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
BindUtils.CreateTokenBinding(wrapper, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
BindUtils.CreateTokenBinding(wrapper, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
BindUtils.CreateTokenBinding(wrapper, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
BindUtils.CreateTokenBinding(wrapper, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.BackgroundProperty, MenuResourceKey.MenuBgColor);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
var scrollViewer = new MenuScrollViewer();
var itemsPresenter = new ItemsPresenter

View File

@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Reflection;
using AtomUI.Controls.Utils;
using AtomUI.Data;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;

View File

@ -1,10 +1,9 @@
using AtomUI.Utils;
using AtomUI.Data;
using Avalonia;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.LogicalTree;
using Avalonia.Markup.Xaml.MarkupExtensions;
using Avalonia.Media;
namespace AtomUI.Controls;

View File

@ -1,9 +1,8 @@
using AtomUI.Styling;
using AtomUI.Utils;
using AtomUI.Data;
using AtomUI.Styling;
using Avalonia;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.LogicalTree;
using Avalonia.Metadata;
namespace AtomUI.Controls;

View File

@ -123,8 +123,8 @@ public class MarqueeLabel : TextBlock,
void IControlCustomStyle.SetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, CycleSpaceProperty, MarqueeLabelResourceKey.CycleSpace);
BindUtils.CreateTokenBinding(this, MoveSpeedProperty, MarqueeLabelResourceKey.DefaultSpeed);
TokenResourceBinder.CreateTokenBinding(this, CycleSpaceProperty, MarqueeLabelResourceKey.CycleSpace);
TokenResourceBinder.CreateTokenBinding(this, MoveSpeedProperty, MarqueeLabelResourceKey.DefaultSpeed);
}
void IControlCustomStyle.HandlePropertyChangedForStyle(AvaloniaPropertyChangedEventArgs e)

View File

@ -25,13 +25,13 @@ public class ContextMenuTheme : ControlTheme
{
Name = RootContainerPart
};
BindUtils.CreateTokenBinding(wrapper, Border.BackgroundProperty, MenuResourceKey.MenuBgColor);
BindUtils.CreateTokenBinding(wrapper, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
BindUtils.CreateTokenBinding(wrapper, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
BindUtils.CreateTokenBinding(wrapper, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
BindUtils.CreateTokenBinding(wrapper, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
BindUtils.CreateTokenBinding(wrapper, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
BindUtils.CreateTokenBinding(wrapper, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.BackgroundProperty, MenuResourceKey.MenuBgColor);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
TokenResourceBinder.CreateTokenBinding(wrapper, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
var scrollViewer = new MenuScrollViewer();
var itemsPresenter = new ItemsPresenter

View File

@ -1,7 +1,7 @@
using AtomUI.Utils;
using AtomUI.Data;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.LogicalTree;
namespace AtomUI.Controls;
@ -28,7 +28,7 @@ public class Menu : AvaloniaMenu,
{
base.OnAttachedToLogicalTree(e);
if (ItemContainerTheme is null) {
BindUtils.CreateGlobalResourceBinding(this, ItemContainerThemeProperty, TopLevelMenuItemTheme.ID);
TokenResourceBinder.CreateGlobalResourceBinding(this, ItemContainerThemeProperty, TopLevelMenuItemTheme.ID);
}
}

View File

@ -1,4 +1,5 @@
using AtomUI.Media;
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
@ -88,9 +89,9 @@ public class MenuItem : AvaloniaMenuItem, IControlCustomStyle
UpdatePseudoClasses();
} else if (e.Property == IconProperty) {
if (Icon is not null && Icon is PathIcon pathIcon) {
BindUtils.CreateTokenBinding(pathIcon, PathIcon.WidthProperty, MenuResourceKey.ItemIconSize);
BindUtils.CreateTokenBinding(pathIcon, PathIcon.HeightProperty, MenuResourceKey.ItemIconSize);
BindUtils.CreateTokenBinding(pathIcon, PathIcon.NormalFilledBrushProperty, MenuResourceKey.ItemColor);
TokenResourceBinder.CreateTokenBinding(pathIcon, PathIcon.WidthProperty, MenuResourceKey.ItemIconSize);
TokenResourceBinder.CreateTokenBinding(pathIcon, PathIcon.HeightProperty, MenuResourceKey.ItemIconSize);
TokenResourceBinder.CreateTokenBinding(pathIcon, PathIcon.NormalFilledBrushProperty, MenuResourceKey.ItemColor);
}
} else if (e.Property == ToggleTypeProperty) {
HandleToggleTypeChanged();

View File

@ -94,9 +94,9 @@ internal class MenuItemTheme : ControlTheme
Grid.SetColumn(iconPresenter, 1);
iconPresenter.RegisterInNameScope(scope);
CreateTemplateParentBinding(iconPresenter, Viewbox.ChildProperty, MenuItem.IconProperty);
BindUtils.CreateTokenBinding(iconPresenter, Viewbox.MarginProperty, MenuResourceKey.ItemMargin);
BindUtils.CreateGlobalTokenBinding(iconPresenter, Viewbox.WidthProperty, MenuResourceKey.ItemIconSize);
BindUtils.CreateGlobalTokenBinding(iconPresenter, Viewbox.HeightProperty, MenuResourceKey.ItemIconSize);
TokenResourceBinder.CreateTokenBinding(iconPresenter, Viewbox.MarginProperty, MenuResourceKey.ItemMargin);
TokenResourceBinder.CreateGlobalTokenBinding(iconPresenter, Viewbox.WidthProperty, MenuResourceKey.ItemIconSize);
TokenResourceBinder.CreateGlobalTokenBinding(iconPresenter, Viewbox.HeightProperty, MenuResourceKey.ItemIconSize);
var itemTextPresenter = new ContentPresenter
{
@ -107,7 +107,7 @@ internal class MenuItemTheme : ControlTheme
IsHitTestVisible = false
};
Grid.SetColumn(itemTextPresenter, 2);
BindUtils.CreateTokenBinding(itemTextPresenter, ContentPresenter.MarginProperty, MenuResourceKey.ItemMargin);
TokenResourceBinder.CreateTokenBinding(itemTextPresenter, ContentPresenter.MarginProperty, MenuResourceKey.ItemMargin);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentProperty, MenuItem.HeaderProperty);
CreateTemplateParentBinding(itemTextPresenter, ContentPresenter.ContentTemplateProperty, MenuItem.HeaderTemplateProperty);
@ -121,7 +121,7 @@ internal class MenuItemTheme : ControlTheme
VerticalAlignment = VerticalAlignment.Center,
};
Grid.SetColumn(inputGestureText, 3);
BindUtils.CreateTokenBinding(inputGestureText, ContentPresenter.MarginProperty, MenuResourceKey.ItemMargin);
TokenResourceBinder.CreateTokenBinding(inputGestureText, ContentPresenter.MarginProperty, MenuResourceKey.ItemMargin);
CreateTemplateParentBinding(inputGestureText,
TextBlock.TextProperty,
MenuItem.InputGestureProperty,
@ -137,8 +137,8 @@ internal class MenuItemTheme : ControlTheme
VerticalAlignment = VerticalAlignment.Center,
Kind = "RightOutlined"
};
BindUtils.CreateGlobalTokenBinding(menuIndicatorIcon, PathIcon.WidthProperty, GlobalResourceKey.IconSizeXS);
BindUtils.CreateGlobalTokenBinding(menuIndicatorIcon, PathIcon.HeightProperty, GlobalResourceKey.IconSizeXS);
TokenResourceBinder.CreateGlobalTokenBinding(menuIndicatorIcon, PathIcon.WidthProperty, GlobalResourceKey.IconSizeXS);
TokenResourceBinder.CreateGlobalTokenBinding(menuIndicatorIcon, PathIcon.HeightProperty, GlobalResourceKey.IconSizeXS);
Grid.SetColumn(menuIndicatorIcon, 4);
menuIndicatorIcon.RegisterInNameScope(scope);
@ -169,13 +169,13 @@ internal class MenuItemTheme : ControlTheme
};
var border = new Border();
BindUtils.CreateTokenBinding(border, Border.BackgroundProperty, GlobalResourceKey.ColorBgContainer);
BindUtils.CreateTokenBinding(border, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
BindUtils.CreateTokenBinding(border, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
BindUtils.CreateTokenBinding(border, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
BindUtils.CreateTokenBinding(border, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
BindUtils.CreateTokenBinding(border, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
BindUtils.CreateTokenBinding(border, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty, GlobalResourceKey.ColorBgContainer);
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
TokenResourceBinder.CreateTokenBinding(border, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
TokenResourceBinder.CreateTokenBinding(border, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
TokenResourceBinder.CreateTokenBinding(border, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
TokenResourceBinder.CreateTokenBinding(border, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
TokenResourceBinder.CreateTokenBinding(border, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
var scrollViewer = new MenuScrollViewer();
var itemsPresenter = new ItemsPresenter
@ -189,8 +189,8 @@ internal class MenuItemTheme : ControlTheme
popup.Child = border;
BindUtils.CreateTokenBinding(popup, Popup.MarginToAnchorProperty, MenuResourceKey.TopLevelItemPopupMarginToAnchor);
BindUtils.CreateTokenBinding(popup, Popup.MaskShadowsProperty, MenuResourceKey.MenuPopupBoxShadows);
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty, MenuResourceKey.TopLevelItemPopupMarginToAnchor);
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty, MenuResourceKey.MenuPopupBoxShadows);
CreateTemplateParentBinding(popup, Popup.IsOpenProperty, MenuItem.IsSubMenuOpenProperty, BindingMode.TwoWay);
return popup;

View File

@ -1,4 +1,5 @@
using AtomUI.Media;
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia.Animation;
@ -42,8 +43,8 @@ internal class MenuScrollViewerTheme : ControlTheme
RenderTransform = null
};
CreateTemplateParentBinding(scrollUpButton, IconButton.CommandProperty, nameof(MenuScrollViewer.LineUp));
BindUtils.CreateTokenBinding(scrollUpButton.Icon, PathIcon.WidthProperty, MenuResourceKey.ScrollButtonIconSize);
BindUtils.CreateTokenBinding(scrollUpButton.Icon, PathIcon.HeightProperty, MenuResourceKey.ScrollButtonIconSize);
TokenResourceBinder.CreateTokenBinding(scrollUpButton.Icon, PathIcon.WidthProperty, MenuResourceKey.ScrollButtonIconSize);
TokenResourceBinder.CreateTokenBinding(scrollUpButton.Icon, PathIcon.HeightProperty, MenuResourceKey.ScrollButtonIconSize);
DockPanel.SetDock(scrollUpButton, Dock.Top);
var scrollDownButton = new IconButton()
{
@ -58,8 +59,8 @@ internal class MenuScrollViewerTheme : ControlTheme
RenderTransform = null
};
CreateTemplateParentBinding(scrollDownButton, IconButton.CommandProperty, nameof(MenuScrollViewer.LineDown));
BindUtils.CreateTokenBinding(scrollDownButton.Icon, PathIcon.WidthProperty, MenuResourceKey.ScrollButtonIconSize);
BindUtils.CreateTokenBinding(scrollDownButton.Icon, PathIcon.HeightProperty, MenuResourceKey.ScrollButtonIconSize);
TokenResourceBinder.CreateTokenBinding(scrollDownButton.Icon, PathIcon.WidthProperty, MenuResourceKey.ScrollButtonIconSize);
TokenResourceBinder.CreateTokenBinding(scrollDownButton.Icon, PathIcon.HeightProperty, MenuResourceKey.ScrollButtonIconSize);
DockPanel.SetDock(scrollDownButton, Dock.Bottom);
var scrollViewContent = CreateScrollContentPresenter(viewer);

View File

@ -29,7 +29,7 @@ public class MenuSeparator : AvaloniaSeparator
{
base.OnAttachedToVisualTree(e);
if (!_initialized) {
BindUtils.CreateTokenBinding(this, LineWidthProperty, GlobalResourceKey.LineWidth, BindingPriority.Template,
TokenResourceBinder.CreateTokenBinding(this, LineWidthProperty, GlobalResourceKey.LineWidth, BindingPriority.Template,
new RenderScaleAwareDoubleConfigure(this));
_initialized = true;
}

View File

@ -69,13 +69,13 @@ public class TopLevelMenuItemTheme : ControlTheme
var border = new Border();
BindUtils.CreateTokenBinding(border, Border.BackgroundProperty, GlobalResourceKey.ColorBgContainer);
BindUtils.CreateTokenBinding(border, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
BindUtils.CreateTokenBinding(border, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
BindUtils.CreateTokenBinding(border, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
BindUtils.CreateTokenBinding(border, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
BindUtils.CreateTokenBinding(border, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
BindUtils.CreateTokenBinding(border, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
TokenResourceBinder.CreateTokenBinding(border, Border.BackgroundProperty, GlobalResourceKey.ColorBgContainer);
TokenResourceBinder.CreateTokenBinding(border, Border.CornerRadiusProperty, MenuResourceKey.MenuPopupBorderRadius);
TokenResourceBinder.CreateTokenBinding(border, Border.MinWidthProperty, MenuResourceKey.MenuPopupMinWidth);
TokenResourceBinder.CreateTokenBinding(border, Border.MaxWidthProperty, MenuResourceKey.MenuPopupMaxWidth);
TokenResourceBinder.CreateTokenBinding(border, Border.MinHeightProperty, MenuResourceKey.MenuPopupMinHeight);
TokenResourceBinder.CreateTokenBinding(border, Border.MaxHeightProperty, MenuResourceKey.MenuPopupMaxHeight);
TokenResourceBinder.CreateTokenBinding(border, Border.PaddingProperty, MenuResourceKey.MenuPopupContentPadding);
var scrollViewer = new MenuScrollViewer();
var itemsPresenter = new ItemsPresenter
@ -89,8 +89,8 @@ public class TopLevelMenuItemTheme : ControlTheme
border.Child = scrollViewer;
popup.Child = border;
BindUtils.CreateTokenBinding(popup, Popup.MarginToAnchorProperty, MenuResourceKey.TopLevelItemPopupMarginToAnchor);
BindUtils.CreateTokenBinding(popup, Popup.MaskShadowsProperty, MenuResourceKey.MenuPopupBoxShadows);
TokenResourceBinder.CreateTokenBinding(popup, Popup.MarginToAnchorProperty, MenuResourceKey.TopLevelItemPopupMarginToAnchor);
TokenResourceBinder.CreateTokenBinding(popup, Popup.MaskShadowsProperty, MenuResourceKey.MenuPopupBoxShadows);
CreateTemplateParentBinding(popup, Popup.IsOpenProperty, MenuItem.IsSubMenuOpenProperty, BindingMode.TwoWay);

View File

@ -1,5 +1,6 @@
using System.Reactive.Disposables;
using AtomUI.Controls.MotionScene;
using AtomUI.Data;
using AtomUI.MotionScene;
using AtomUI.Styling;
using AtomUI.Utils;
@ -88,8 +89,8 @@ public class Popup : AvaloniaPopup
{
base.OnAttachedToLogicalTree(e);
if (!_initialized) {
BindUtils.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
BindUtils.CreateGlobalTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationMid);
TokenResourceBinder.CreateGlobalTokenBinding(this, MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
TokenResourceBinder.CreateGlobalTokenBinding(this, MotionDurationProperty, GlobalResourceKey.MotionDurationMid);
_initialized = true;
}
}

View File

@ -1,4 +1,5 @@
using AtomUI.Media;
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;

View File

@ -27,8 +27,8 @@ public class AbstractCircleProgressTheme : AbstractProgressBarTheme
VerticalAlignment = VerticalAlignment.Center
};
exceptionCompletedIcon.RegisterInNameScope(scope);
BindUtils.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError);
BindUtils.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
TokenResourceBinder.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError);
TokenResourceBinder.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
var successCompletedIcon = new PathIcon
{
@ -38,8 +38,8 @@ public class AbstractCircleProgressTheme : AbstractProgressBarTheme
VerticalAlignment = VerticalAlignment.Center,
};
successCompletedIcon.RegisterInNameScope(scope);
BindUtils.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorSuccess);
BindUtils.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
TokenResourceBinder.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorSuccess);
TokenResourceBinder.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
container.Children.Add(exceptionCompletedIcon);
container.Children.Add(successCompletedIcon);

View File

@ -26,8 +26,8 @@ public class AbstractLineProgressTheme : AbstractProgressBarTheme
HorizontalAlignment = HorizontalAlignment.Left
};
exceptionCompletedIcon.RegisterInNameScope(scope);
BindUtils.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError);
BindUtils.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
TokenResourceBinder.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError);
TokenResourceBinder.CreateGlobalTokenBinding(exceptionCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
var successCompletedIcon = new PathIcon
{
@ -36,8 +36,8 @@ public class AbstractLineProgressTheme : AbstractProgressBarTheme
HorizontalAlignment = HorizontalAlignment.Left
};
successCompletedIcon.RegisterInNameScope(scope);
BindUtils.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorSuccess);
BindUtils.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
TokenResourceBinder.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorSuccess);
TokenResourceBinder.CreateGlobalTokenBinding(successCompletedIcon, PathIcon.DisabledFilledBrushProperty, GlobalResourceKey.ControlItemBgActiveDisabled);
container.Children.Add(exceptionCompletedIcon);
container.Children.Add(successCompletedIcon);

View File

@ -426,7 +426,7 @@ public abstract class AbstractProgressBar : RangeBase,
protected virtual void NotifySetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, SuccessThresholdBrushProperty, GlobalResourceKey.ColorSuccess);
TokenResourceBinder.CreateTokenBinding(this, SuccessThresholdBrushProperty, GlobalResourceKey.ColorSuccess);
}
protected virtual void NotifyPropertyChanged(AvaloniaPropertyChangedEventArgs e)

View File

@ -1,4 +1,3 @@
using AtomUI.ColorSystem;
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Styling;

View File

@ -1,4 +1,5 @@
using System.Collections.Specialized;
using AtomUI.Data;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;

View File

@ -176,9 +176,9 @@ public class SegmentedItem : TemplatedControl, IControlCustomStyle
{
if (Icon is not null) {
if (Icon.ThemeType != IconThemeType.TwoTone) {
BindUtils.CreateTokenBinding(Icon, PathIcon.NormalFilledBrushProperty, SegmentedResourceKey.ItemColor);
BindUtils.CreateTokenBinding(Icon, PathIcon.ActiveFilledBrushProperty, SegmentedResourceKey.ItemHoverColor);
BindUtils.CreateTokenBinding(Icon, PathIcon.SelectedFilledBrushProperty, SegmentedResourceKey.ItemSelectedColor);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.NormalFilledBrushProperty, SegmentedResourceKey.ItemColor);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.ActiveFilledBrushProperty, SegmentedResourceKey.ItemHoverColor);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.SelectedFilledBrushProperty, SegmentedResourceKey.ItemSelectedColor);
}
if (_mainLayout is not null) {

View File

@ -1,3 +1,4 @@
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Styling;
using AtomUI.Utils;

View File

@ -205,7 +205,7 @@ public class Separator : AvaloniaSeparator, IControlCustomStyle
void IControlCustomStyle.SetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, LineWidthProperty, GlobalResourceKey.LineWidth, BindingPriority.Template,
TokenResourceBinder.CreateTokenBinding(this, LineWidthProperty, GlobalResourceKey.LineWidth, BindingPriority.Template,
new RenderScaleAwareDoubleConfigure(this));
}

View File

@ -1,4 +1,4 @@
using AtomUI.ColorSystem;
using AtomUI.Media;
using AtomUI.TokenSystem;
using Avalonia;
using Avalonia.Media;

View File

@ -344,11 +344,11 @@ public class SliderTrack : Control, IControlCustomStyle
public override void ApplyTemplate()
{
base.ApplyTemplate();
BindUtils.CreateTokenBinding(this, SliderTrack.SliderTrackSizeProperty, SliderResourceKey.SliderTrackSize);
BindUtils.CreateTokenBinding(this, SliderTrack.SliderMarkSizeProperty, SliderResourceKey.MarkSize);
BindUtils.CreateTokenBinding(this, SliderTrack.SliderRailSizeProperty, SliderResourceKey.RailSize);
BindUtils.CreateTokenBinding(this, SliderTrack.MarkBackgroundBrushProperty, GlobalResourceKey.ColorBgElevated);
BindUtils.CreateTokenBinding(this, SliderTrack.MarkBorderThicknessProperty, SliderResourceKey.ThumbCircleBorderThickness);
TokenResourceBinder.CreateTokenBinding(this, SliderTrack.SliderTrackSizeProperty, SliderResourceKey.SliderTrackSize);
TokenResourceBinder.CreateTokenBinding(this, SliderTrack.SliderMarkSizeProperty, SliderResourceKey.MarkSize);
TokenResourceBinder.CreateTokenBinding(this, SliderTrack.SliderRailSizeProperty, SliderResourceKey.RailSize);
TokenResourceBinder.CreateTokenBinding(this, SliderTrack.MarkBackgroundBrushProperty, GlobalResourceKey.ColorBgElevated);
TokenResourceBinder.CreateTokenBinding(this, SliderTrack.MarkBorderThicknessProperty, SliderResourceKey.ThumbCircleBorderThickness);
HandleRangeModeChanged();
CalculateMaxMarkSize();

View File

@ -1,3 +1,4 @@
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Styling;
using AtomUI.Utils;
@ -211,7 +212,7 @@ internal class SwitchKnob : Control, IControlCustomStyle
void IControlCustomStyle.SetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, LoadingBgOpacityTokenProperty, ToggleSwitchResourceKey.SwitchDisabledOpacity);
TokenResourceBinder.CreateTokenBinding(this, LoadingBgOpacityTokenProperty, ToggleSwitchResourceKey.SwitchDisabledOpacity);
LoadingAnimationDuration = TimeSpan.FromMilliseconds(1200);
}

View File

@ -1,6 +1,5 @@
using AtomUI.ColorSystem;
using AtomUI.Media;
using AtomUI.TokenSystem;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Media;

View File

@ -1,13 +1,12 @@
using AtomUI.ColorSystem;
using AtomUI.Controls.Utils;
using AtomUI.Data;
using AtomUI.Palette;
using AtomUI.Styling;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.LogicalTree;
using Avalonia.Media;
using Avalonia.Metadata;
@ -220,7 +219,7 @@ public class Tag : TemplatedControl, IControlCustomStyle
void IControlCustomStyle.SetupTokenBindings()
{
BindUtils.CreateTokenBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness, BindingPriority.Template,
TokenResourceBinder.CreateTokenBinding(this, BorderThicknessProperty, GlobalResourceKey.BorderThickness, BindingPriority.Template,
new RenderScaleAwareThicknessConfigure(this, thickness =>
{
if (!Bordered) {
@ -345,7 +344,7 @@ public class Tag : TemplatedControl, IControlCustomStyle
Bordered = false;
_hasColorSet = true;
Background = new SolidColorBrush(color);
BindUtils.CreateTokenBinding(this, ForegroundProperty, GlobalResourceKey.ColorTextLightSolid);
TokenResourceBinder.CreateTokenBinding(this, ForegroundProperty, GlobalResourceKey.ColorTextLightSolid);
}
}
@ -358,13 +357,13 @@ public class Tag : TemplatedControl, IControlCustomStyle
Kind = "CloseOutlined"
};
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.WidthProperty, TagResourceKey.TagCloseIconSize);
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.HeightProperty, TagResourceKey.TagCloseIconSize);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.WidthProperty, TagResourceKey.TagCloseIconSize);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.HeightProperty, TagResourceKey.TagCloseIconSize);
if (_hasColorSet && !_isPresetColorTag) {
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorTextLightSolid);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorTextLightSolid);
} else {
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorIcon);
BindUtils.CreateTokenBinding(CloseIcon, PathIcon.ActiveFilledBrushProperty, GlobalResourceKey.ColorIconHover);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorIcon);
TokenResourceBinder.CreateTokenBinding(CloseIcon, PathIcon.ActiveFilledBrushProperty, GlobalResourceKey.ColorIconHover);
}
}
}
@ -376,11 +375,11 @@ public class Tag : TemplatedControl, IControlCustomStyle
if (_layoutPanel?.Children[0] is PathIcon oldIcon) {
_layoutPanel.Children.Remove(oldIcon);
}
BindUtils.CreateTokenBinding(Icon, PathIcon.WidthProperty, TagResourceKey.TagIconSize);
BindUtils.CreateTokenBinding(Icon, PathIcon.HeightProperty, TagResourceKey.TagIconSize);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.WidthProperty, TagResourceKey.TagIconSize);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.HeightProperty, TagResourceKey.TagIconSize);
_layoutPanel?.Children.Insert(0, Icon);
if (_hasColorSet) {
BindUtils.CreateTokenBinding(Icon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorTextLightSolid);
TokenResourceBinder.CreateTokenBinding(Icon, PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorTextLightSolid);
} else if (_isPresetColorTag) {
Icon.NormalFilledBrush = Foreground;
}

View File

@ -54,10 +54,10 @@ internal class TagTheme : ControlTheme
};
closeBtn.RegisterInNameScope(scope);
BindUtils.CreateTokenBinding(closeBtn, IconButton.WidthProperty, GlobalResourceKey.IconSizeSM);
BindUtils.CreateTokenBinding(closeBtn, IconButton.HeightProperty, GlobalResourceKey.IconSizeSM);
BindUtils.CreateTokenBinding(textBlock, TextBlock.HeightProperty, TagResourceKey.TagLineHeight);
BindUtils.CreateTokenBinding(textBlock, TextBlock.LineHeightProperty, TagResourceKey.TagLineHeight);
TokenResourceBinder.CreateTokenBinding(closeBtn, IconButton.WidthProperty, GlobalResourceKey.IconSizeSM);
TokenResourceBinder.CreateTokenBinding(closeBtn, IconButton.HeightProperty, GlobalResourceKey.IconSizeSM);
TokenResourceBinder.CreateTokenBinding(textBlock, TextBlock.HeightProperty, TagResourceKey.TagLineHeight);
TokenResourceBinder.CreateTokenBinding(textBlock, TextBlock.LineHeightProperty, TagResourceKey.TagLineHeight);
CreateTemplateParentBinding(closeBtn, IconButton.IsVisibleProperty, Tag.IsClosableProperty);
CreateTemplateParentBinding(closeBtn, IconButton.IconProperty, Tag.CloseIconProperty);

View File

@ -1,4 +1,4 @@
using AtomUI.ColorSystem;
using AtomUI.Media;
using AtomUI.TokenSystem;
using Avalonia;
using Avalonia.Media;

View File

@ -1,5 +1,5 @@
using System.Reflection;
using AtomUI.ColorSystem;
using AtomUI.Palette;
using AtomUI.Reflection;
using AtomUI.Styling;
using AtomUI.Utils;
@ -637,7 +637,7 @@ public class ToolTip : TemplatedControl,
SetPopupParent(_popup, control);
BindUtils.CreateTokenBinding(_popup, Popup.MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
TokenResourceBinder.CreateTokenBinding(_popup, Popup.MaskShadowsProperty, GlobalResourceKey.BoxShadowsSecondary);
SetToolTipColor(control);
var marginToAnchor = GetMarginToAnchor(control);

View File

@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AtomUI.Generator</PackageId>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeBuildOutput>false</IncludeBuildOutput>

View File

@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>AtomUI.Icon.AntDesign</AssemblyName>
<PackageId>AtomUI.Icon.AntDesign</PackageId>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>GeneratedFiles</CompilerGeneratedFilesOutputPath>
<GeneratePackageOnBuild Condition=" '$(Configuration)' != 'Debug' ">True</GeneratePackageOnBuild>

View File

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AtomUI.Icon</PackageId>
<GeneratePackageOnBuild Condition=" '$(Configuration)' != 'Debug' ">True</GeneratePackageOnBuild>
</PropertyGroup>

View File

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>AtomUI.Theme</PackageId>
<RootNamespace>AtomUI</RootNamespace>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>GeneratedFiles</CompilerGeneratedFilesOutputPath>

View File

@ -1,5 +1,4 @@
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.VisualTree;
namespace AtomUI.Data;

View File

@ -7,49 +7,8 @@ using Avalonia.Styling;
namespace AtomUI.Utils;
public static class BindUtils
public static class TokenResourceBinder
{
public static IDisposable RelayBind(AvaloniaObject source, AvaloniaProperty sourceProperty, AvaloniaObject target,
AvaloniaProperty? targetProperty = null,
BindingMode mode = BindingMode.Default)
{
targetProperty ??= sourceProperty;
var registry = AvaloniaPropertyRegistry.Instance;
if (!registry.IsRegistered(source.GetType(), sourceProperty)) {
throw new ArgumentException($"Relay source property is not registered for: {source.GetType().Name}.");
}
if (!registry.IsRegistered(target.GetType(), targetProperty)) {
throw new ArgumentException($"Relay target property is not registered for: {target.GetType().Name}.");
}
var descriptor = new IndexerDescriptor
{
Source = source,
Property = sourceProperty,
Priority = BindingPriority.Inherited,
Mode = mode
};
return target.Bind(targetProperty, descriptor);
}
public static IDisposable RelayBind<TSource, TResult>(AvaloniaObject source, AvaloniaProperty<TSource> sourceProperty,
AvaloniaObject target, AvaloniaProperty<TResult> targetProperty,
Func<TSource, TResult> converter,
BindingPriority priority = BindingPriority.Template)
{
var registry = AvaloniaPropertyRegistry.Instance;
if (!registry.IsRegistered(source.GetType(), sourceProperty)) {
throw new ArgumentException($"Relay source property is not registered for: {source.GetType().Name}.");
}
if (!registry.IsRegistered(target.GetType(), targetProperty)) {
throw new ArgumentException($"Relay target property is not registered for: {target.GetType().Name}.");
}
return target.Bind(targetProperty, source.GetObservable(sourceProperty, converter), priority);
}
public static IDisposable CreateTokenBinding(AvaloniaObject target,
AvaloniaProperty targetProperty,
TokenResourceKey resourceKey)

Some files were not shown because too many files have changed in this diff Show More