Skip to content

Commit

Permalink
feat: add IconPacks.Avalonia
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Oct 27, 2024
1 parent 7700d2a commit 8c87422
Show file tree
Hide file tree
Showing 15 changed files with 1,080 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/AvaloniaApp/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</FluentTheme.Palettes>
</FluentTheme>

<StyleInclude Source="avares://IconPacks.Avalonia.BoxIcons/BoxIcons.xaml"/>
<!-- <StyleInclude Source="avares://IconPacks.Avalonia.BoxIcons/BoxIcons.xaml" /> -->
<StyleInclude Source="avares://IconPacks.Avalonia/Icons.xaml" />
</Application.Styles>
</Application>
3 changes: 2 additions & 1 deletion src/AvaloniaApp/AvaloniaApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IconPacks.Avalonia.BoxIcons\IconPacks.Avalonia.BoxIcons.csproj" />
<!-- <ProjectReference Include="..\IconPacks.Avalonia.BoxIcons\IconPacks.Avalonia.BoxIcons.csproj" /> -->
<ProjectReference Include="..\IconPacks.Avalonia\IconPacks.Avalonia.csproj" />
</ItemGroup>

</Project>
26 changes: 21 additions & 5 deletions src/AvaloniaApp/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,37 @@

<Separator />

<Label Content="PackIconControl Control" />
<iconPacks:PackIconControl Margin="10"
Kind="{Binding #BoxIcons.SelectedItem, Mode=OneWay}"
Foreground="{DynamicResource SystemControlHighlightAccentBrush}" />

<Label Content="PackIconBoxIcons Control" />
<iconPacks:PackIconBoxIcons Margin="10"
Kind="{Binding #BoxIcons.SelectedItem, Mode=OneWay}"
Foreground="{DynamicResource SystemControlHighlightAccentBrush}" />

<Label Content="Image ValueConverter" />
<Image Source="{Binding #BoxIcons.SelectedItem, Mode=OneWay, Converter={iconPacks:PackIconBoxIconsKindToImageConverter Brush=Goldenrod}}" Width="24" Height="24"
<Label Content="Image with ValueConverter" />
<Image Source="{Binding #BoxIcons.SelectedItem, Mode=OneWay, Converter={iconPacks:PackIconBoxIconsKindToImageConverter Brush=Goldenrod}}"
Width="24" Height="24"
HorizontalAlignment="Left" Margin="10" />

<Label Content="Image MarkupExtension" />
<Image Source="{iconPacks:BoxIconsImage Kind=RegularAtom, Brush=Brown}" Width="24" Height="24" HorizontalAlignment="Left" Margin="10" />
<Label Content="Image with MarkupExtension" />
<Image Source="{iconPacks:BoxIconsImage Kind=RegularAtom, Brush=Brown}"
Width="24" Height="24"
HorizontalAlignment="Left" Margin="10" />

<Label Content="Button MarkupExtension" />
<Label Content="Image with PackIconImage MarkupExtension" />
<Image Source="{iconPacks:PackIconImage Kind={x:Static iconPacks:PackIconBoxIconsKind.RegularAlarm}, Brush=GreenYellow}"
Width="24" Height="24"
HorizontalAlignment="Left" Margin="10" />

<Label Content="Button with MarkupExtension" />
<Button Content="{iconPacks:BoxIcons RegularAtom}" Margin="10" />

<Label Content="Button with PackIcon MarkupExtension" />
<Button Content="{iconPacks:PackIcon {x:Static iconPacks:PackIconBoxIconsKind.RegularAlarm}}" Margin="10" />

<Separator />

<Label Content="Flip Orientation" />
Expand Down
14 changes: 14 additions & 0 deletions src/AvaloniaIconPacks.TestApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IconPacks.Avalonia.BoxIcons", "IconPacks.Avalonia.BoxIcons\IconPacks.Avalonia.BoxIcons.csproj", "{0159372E-46AA-4886-B346-4AA74B26D613}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IconPacks.Avalonia", "IconPacks.Avalonia\IconPacks.Avalonia.csproj", "{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,6 +62,18 @@ Global
{0159372E-46AA-4886-B346-4AA74B26D613}.Release|x64.Build.0 = Release|Any CPU
{0159372E-46AA-4886-B346-4AA74B26D613}.Release|x86.ActiveCfg = Release|Any CPU
{0159372E-46AA-4886-B346-4AA74B26D613}.Release|x86.Build.0 = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|x64.ActiveCfg = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|x64.Build.0 = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|x86.ActiveCfg = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Debug|x86.Build.0 = Debug|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|Any CPU.Build.0 = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|x64.ActiveCfg = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|x64.Build.0 = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|x86.ActiveCfg = Release|Any CPU
{49ECE319-789D-4A0C-9CAF-D79CF6BFEB48}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang

protected override void SetKind<TKind>(TKind iconKind)
{
this.SetValue(KindProperty, iconKind);
this.SetCurrentValue(KindProperty, iconKind);
}

protected override void UpdateData()
Expand Down
51 changes: 28 additions & 23 deletions src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@
<iconPacks:PackIconBoxIcons Kind="RegularAtom" />
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type iconPacks:PackIconBoxIcons}"
TargetType="iconPacks:PackIconBoxIcons">
<ControlTemplate x:Key="IconPacks.Avalonia.PackIconBoxIcons.Template" TargetType="iconPacks:PackIconBoxIcons">
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Grid x:Name="PART_InnerGrid"
Margin="{TemplateBinding BorderThickness}">
<Viewbox Margin="{TemplateBinding Padding}">
<Path Data="{Binding Data, RelativeSource={RelativeSource TemplatedParent}}"
Fill="{TemplateBinding Foreground}"
Stretch="Uniform"
UseLayoutRounding="False" />
<Viewbox.RenderTransform>
<ScaleTransform ScaleY="-1" />
</Viewbox.RenderTransform>
</Viewbox>
</Grid>
</Grid>
</ControlTemplate>

<ControlTheme x:Key="IconPacks.Avalonia.PackIconBoxIcons.Theme" TargetType="iconPacks:PackIconBoxIcons">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundColor}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="{DynamicResource IconElementThemeHeight}" />
<Setter Property="Width" Value="{DynamicResource IconElementThemeWidth}" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="FlowDirection" Value="LeftToRight" />
<Setter Property="Padding" Value="0" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="UseLayoutRounding" Value="False" />
<Setter Property="Template">
<ControlTemplate>
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Grid x:Name="PART_InnerGrid"
Margin="{TemplateBinding BorderThickness}">
<Viewbox Margin="{TemplateBinding Padding}">
<Path Fill="{TemplateBinding Foreground}"
Stretch="Uniform"
Data="{Binding Data, RelativeSource={RelativeSource TemplatedParent}}"
UseLayoutRounding="False" />
<Viewbox.RenderTransform>
<ScaleTransform ScaleY="-1" />
</Viewbox.RenderTransform>
</Viewbox>
</Grid>
</Grid>
</ControlTemplate>
</Setter>
<Setter Property="Template" Value="{DynamicResource IconPacks.Avalonia.PackIconBoxIcons.Template}" />
</ControlTheme>

<ControlTheme x:Key="{x:Type iconPacks:PackIconBoxIcons}"
BasedOn="{StaticResource IconPacks.Avalonia.PackIconBoxIcons.Theme}"
TargetType="iconPacks:PackIconBoxIcons" />

</ResourceDictionary>
183 changes: 183 additions & 0 deletions src/IconPacks.Avalonia/Converter/PackIconKindToImageConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
using Avalonia.Media;

namespace IconPacks.Avalonia.Converter
{
public class PackIconKindToImageConverter : PackIconKindToImageConverterBase
{
/// <inheritdoc />
protected override string GetPathData(object iconKind)
{
string data = null;
switch (iconKind)
{
// case PackIconBootstrapIconsKind kind:
// PackIconDataFactory<PackIconBootstrapIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
case PackIconBoxIconsKind kind:
PackIconDataFactory<PackIconBoxIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
return data;
// case PackIconCircumIconsKind kind:
// PackIconDataFactory<PackIconCircumIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconCodiconsKind kind:
// PackIconDataFactory<PackIconCodiconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconCooliconsKind kind:
// PackIconDataFactory<PackIconCooliconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconEntypoKind kind:
// PackIconDataFactory<PackIconEntypoKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconEvaIconsKind kind:
// PackIconDataFactory<PackIconEvaIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconFeatherIconsKind kind:
// PackIconDataFactory<PackIconFeatherIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconFileIconsKind kind:
// PackIconDataFactory<PackIconFileIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconFontaudioKind kind:
// PackIconDataFactory<PackIconFontaudioKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconFontAwesomeKind kind:
// PackIconDataFactory<PackIconFontAwesomeKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconFontistoKind kind:
// PackIconDataFactory<PackIconFontistoKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconForkAwesomeKind kind:
// PackIconDataFactory<PackIconForkAwesomeKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconGameIconsKind kind:
// PackIconDataFactory<PackIconGameIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconIoniconsKind kind:
// PackIconDataFactory<PackIconIoniconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconJamIconsKind kind:
// PackIconDataFactory<PackIconJamIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconLucideKind kind:
// PackIconDataFactory<PackIconLucideKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconMaterialKind kind:
// PackIconDataFactory<PackIconMaterialKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconMaterialLightKind kind:
// PackIconDataFactory<PackIconMaterialLightKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconMaterialDesignKind kind:
// PackIconDataFactory<PackIconMaterialDesignKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconMemoryIconsKind kind:
// PackIconDataFactory<PackIconMemoryIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconMicronsKind kind:
// PackIconDataFactory<PackIconMicronsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconModernKind kind:
// PackIconDataFactory<PackIconModernKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconOcticonsKind kind:
// PackIconDataFactory<PackIconOcticonsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconPhosphorIconsKind kind:
// PackIconDataFactory<PackIconPhosphorIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconPicolIconsKind kind:
// PackIconDataFactory<PackIconPicolIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconPixelartIconsKind kind:
// PackIconDataFactory<PackIconPixelartIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconRadixIconsKind kind:
// PackIconDataFactory<PackIconRadixIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconRemixIconKind kind:
// PackIconDataFactory<PackIconRemixIconKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconRPGAwesomeKind kind:
// PackIconDataFactory<PackIconRPGAwesomeKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconSimpleIconsKind kind:
// PackIconDataFactory<PackIconSimpleIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconTypiconsKind kind:
// PackIconDataFactory<PackIconTypiconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconUniconsKind kind:
// PackIconDataFactory<PackIconUniconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconVaadinIconsKind kind:
// PackIconDataFactory<PackIconVaadinIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconWeatherIconsKind kind:
// PackIconDataFactory<PackIconWeatherIconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
// case PackIconZondiconsKind kind:
// PackIconDataFactory<PackIconZondiconsKind>.DataIndex.Value?.TryGetValue(kind, out data);
// return data;
default:
return null;
}
}

/// <inheritdoc />
protected override ScaleTransform GetScaleTransform(object iconKind)
{
switch (iconKind)
{
// case PackIconBootstrapIconsKind _:
case PackIconBoxIconsKind _:
// case PackIconCodiconsKind _:
// case PackIconCooliconsKind _:
// case PackIconEvaIconsKind _:
// case PackIconFileIconsKind _:
// case PackIconFontaudioKind _:
// case PackIconFontistoKind _:
// case PackIconForkAwesomeKind _:
// case PackIconJamIconsKind _:
// case PackIconLucideKind _:
// case PackIconRPGAwesomeKind _:
// case PackIconTypiconsKind _:
// case PackIconVaadinIconsKind _:
return new ScaleTransform(1, -1);
default:
return new ScaleTransform(1, 1);
}
}

/// <inheritdoc />
protected override DrawingGroup GetDrawingGroup(object iconKind, IBrush foregroundBrush, string path)
{
var geometryDrawing = new GeometryDrawing
{
Geometry = Geometry.Parse(path)
};

// if (iconKind is PackIconFeatherIconsKind)
// {
// var pen = new Pen(foregroundBrush, 2d)
// {
// StartLineCap = PenLineCap.Round,
// EndLineCap = PenLineCap.Round,
// LineJoin = PenLineJoin.Round
// };
// geometryDrawing.Pen = pen;
// }
// else
{
geometryDrawing.Brush = foregroundBrush;
}

var drawingGroup = new DrawingGroup
{
Children = { geometryDrawing },
Transform = this.GetTransformGroup(iconKind)
};

return drawingGroup;
}
}
}
32 changes: 32 additions & 0 deletions src/IconPacks.Avalonia/IconPacks.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);AVALONIA</DefineConstants>
<LangVersion>latest</LangVersion>
<Nullable>disable</Nullable>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);ALL</DefineConstants>
<AssemblyName>IconPacks.Avalonia</AssemblyName>
<Title>IconPacks.Avalonia</Title>
<RootNamespace>IconPacks.Avalonia</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IconPacks.Avalonia.Core\IconPacks.Avalonia.Core.csproj" />
<ProjectReference Include="..\IconPacks.Avalonia.BoxIcons\IconPacks.Avalonia.BoxIcons.csproj" />
</ItemGroup>

<ItemGroup>
<AvaloniaResource Include="**/*.xaml" />
</ItemGroup>

</Project>
Loading

0 comments on commit 8c87422

Please sign in to comment.