Refactor IconPkg Generator

This commit is contained in:
polarboy 2024-10-09 23:43:01 +08:00
parent f654fa13b4
commit 86491701d0
5 changed files with 3374 additions and 3366 deletions

View File

@ -288,43 +288,43 @@ internal class BaseNavMenuItemTheme : BaseControlTheme
private void BuildMenuIndicatorStyle()
{
// {
// var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
// menuIndicatorStyle.Add(Visual.IsVisibleProperty, true);
// menuIndicatorStyle.Add(Icon.NormalFilledBrushProperty, NavMenuTokenResourceKey.ItemColor);
// menuIndicatorStyle.Add(Icon.SelectedFilledBrushProperty, NavMenuTokenResourceKey.ItemSelectedColor);
// menuIndicatorStyle.Add(Icon.DisabledFilledBrushProperty, NavMenuTokenResourceKey.ItemDisabledColor);
// // 设置颜色
//
// Add(menuIndicatorStyle);
// }
// {
// var darkCommonStyle = new Style(selector => selector.Nesting().PropertyEquals(NavMenuItem.IsDarkStyleProperty, true));
// {
// var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
// menuIndicatorStyle.Add(Icon.NormalFilledBrushProperty, NavMenuTokenResourceKey.DarkItemColor);
// menuIndicatorStyle.Add(Icon.SelectedFilledBrushProperty, NavMenuTokenResourceKey.DarkItemSelectedColor);
// menuIndicatorStyle.Add(Icon.DisabledFilledBrushProperty, NavMenuTokenResourceKey.DarkItemDisabledColor);
// darkCommonStyle.Add(menuIndicatorStyle);
// }
// Add(darkCommonStyle);
// }
//
// var selectedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Selected));
// {
// var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
// menuIndicatorStyle.Add(Icon.IconModeProperty, IconMode.Selected);
// selectedStyle.Add(menuIndicatorStyle);
// }
// Add(selectedStyle);
//
// var hasNoSubMenuStyle = new Style(selector => selector.Nesting().PropertyEquals(NavMenuItem.HasSubMenuProperty, false));
// {
// var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
// menuIndicatorStyle.Add(Visual.IsVisibleProperty, false);
// hasNoSubMenuStyle.Add(menuIndicatorStyle);
// }
// Add(hasNoSubMenuStyle);
{
var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
menuIndicatorStyle.Add(Visual.IsVisibleProperty, true);
menuIndicatorStyle.Add(Icon.NormalFilledBrushProperty, NavMenuTokenResourceKey.ItemColor);
menuIndicatorStyle.Add(Icon.SelectedFilledBrushProperty, NavMenuTokenResourceKey.ItemSelectedColor);
menuIndicatorStyle.Add(Icon.DisabledFilledBrushProperty, NavMenuTokenResourceKey.ItemDisabledColor);
// 设置颜色
Add(menuIndicatorStyle);
}
{
var darkCommonStyle = new Style(selector => selector.Nesting().PropertyEquals(NavMenuItem.IsDarkStyleProperty, true));
{
var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
menuIndicatorStyle.Add(Icon.NormalFilledBrushProperty, NavMenuTokenResourceKey.DarkItemColor);
menuIndicatorStyle.Add(Icon.SelectedFilledBrushProperty, NavMenuTokenResourceKey.DarkItemSelectedColor);
menuIndicatorStyle.Add(Icon.DisabledFilledBrushProperty, NavMenuTokenResourceKey.DarkItemDisabledColor);
darkCommonStyle.Add(menuIndicatorStyle);
}
Add(darkCommonStyle);
}
var selectedStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.Selected));
{
var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
menuIndicatorStyle.Add(Icon.IconModeProperty, IconMode.Selected);
selectedStyle.Add(menuIndicatorStyle);
}
Add(selectedStyle);
var hasNoSubMenuStyle = new Style(selector => selector.Nesting().PropertyEquals(NavMenuItem.HasSubMenuProperty, false));
{
var menuIndicatorStyle = new Style(selector => selector.Nesting().Template().Name(MenuIndicatorIconPart));
menuIndicatorStyle.Add(Visual.IsVisibleProperty, false);
hasNoSubMenuStyle.Add(menuIndicatorStyle);
}
Add(hasNoSubMenuStyle);
}
private void BuildMenuIconStyle()

View File

@ -403,7 +403,7 @@ internal class NavMenuToken : AbstractControlDesignToken
ItemContentMargin = itemContentMargin;
ItemContentPadding = new Thickness(_globalToken.Padding, _globalToken.PaddingXXS);
ItemMargin = new Thickness(0, 0, _globalToken.MarginXXS, 0);
ItemMargin = new Thickness(0, 0, _globalToken.MarginXS, 0);
ItemHeight = _globalToken.ControlHeight;
GroupTitleLineHeight = _globalToken.ControlHeight;
CollapsedWidth = _globalToken.ControlHeight * 2;

View File

@ -3,6 +3,12 @@
<Import Project="$(MSBuildThisFileDirectory)..\..\build\Common.props"/>
<Import Project="$(MSBuildThisFileDirectory)..\..\build\Nuget.props"/>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs"/>
</ItemGroup>

View File

@ -97,23 +97,24 @@ public class IconPackageGenerator : IIncrementalGenerator
sourceText.AppendLine("///");
sourceText.AppendLine("using Avalonia;");
sourceText.AppendLine("using System;");
sourceText.AppendLine("using AtomUI.IconPkg;");
sourceText.AppendLine($"namespace {ns};");
sourceText.AppendLine($"public partial class {packageClassName}");
sourceText.AppendLine("{");
foreach (var info in fileInfos)
{
sourceText.AppendLine($" public static Icon {info.Name}{info.ThemeType}()");
sourceText.AppendLine($" public static AtomUI.IconPkg.Icon {info.Name}{info.ThemeType}()");
sourceText.AppendLine(" {");
sourceText.AppendLine($" return {packageClassName}.Current.BuildIcon({packageName}IconKind.{info.Name}{info.ThemeType});");
sourceText.AppendLine(" }\n");
sourceText.AppendLine($" public static Icon {info.Name}{info.ThemeType}(ColorInfo colorInfo)");
sourceText.AppendLine($" public static AtomUI.IconPkg.Icon {info.Name}{info.ThemeType}(ColorInfo colorInfo)");
sourceText.AppendLine(" {");
sourceText.AppendLine($" return {packageClassName}.Current.BuildIcon({packageName}IconKind.{info.Name}{info.ThemeType}, colorInfo);");
sourceText.AppendLine(" }\n");
sourceText.AppendLine($" public static Icon {info.Name}{info.ThemeType}(TwoToneColorInfo twoToneColorInfo)");
sourceText.AppendLine($" public static AtomUI.IconPkg.Icon {info.Name}{info.ThemeType}(TwoToneColorInfo twoToneColorInfo)");
sourceText.AppendLine(" {");
sourceText.AppendLine($" return {packageClassName}.Current.BuildIcon({packageName}IconKind.{info.Name}{info.ThemeType}, twoToneColorInfo);");
sourceText.AppendLine(" }\n");
@ -128,7 +129,7 @@ public class IconPackageGenerator : IIncrementalGenerator
var viewBox = svgParsedInfo.ViewBox;
sourceText.Append(
$" _iconInfoPool.Add((int){packageName}IconKind.{info.Name}{info.ThemeType}, ");
$" _iconInfoPool.Add((int){packageName}IconKind.{info.Name}{info.ThemeType}, ");
sourceText.Append("new Lazy<IconInfo>(() => new IconInfo(");
sourceText.Append($"\"{info.Name}{info.ThemeType}\", ");