Skip to content

Commit

Permalink
Move template and theme to core
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Oct 30, 2024
1 parent eb889ef commit 87a4fca
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 219 deletions.
2 changes: 2 additions & 0 deletions src/IconPacks.Avalonia.BoxIcons/BoxIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>

<StyleInclude Source="avares://IconPacks.Avalonia.Core/PackIcon.xaml"/>
</Styles>
7 changes: 5 additions & 2 deletions src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace IconPacks.Avalonia
[MetaData("Boxicons", "https://boxicons.com/", "https://boxicons.com/usage/#license")]
public class PackIconBoxIcons : PackIconControlBase
{
public PackIconBoxIcons()
{
base.UpdateIconPseudoClasses(true, false, true);
}

public static readonly StyledProperty<PackIconBoxIconsKind> KindProperty
= AvaloniaProperty.Register<PackIconBoxIcons, PackIconBoxIconsKind>(nameof(Kind));

Expand All @@ -33,8 +38,6 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
{
UpdateData();
}

base.UpdateIconPseudoClasses(true, false, true);
}

protected override void SetKind<TKind>(TKind iconKind)
Expand Down
36 changes: 3 additions & 33 deletions src/IconPacks.Avalonia.BoxIcons/PackIconBoxIcons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,9 @@
<iconPacks:PackIconBoxIcons Kind="RegularAtom" />
</Design.PreviewWith>

<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" Value="{DynamicResource IconPacks.Avalonia.PackIconBoxIcons.Template}" />
</ControlTheme>
<ControlTheme x:Key="IconPacks.Avalonia.PackIconBoxIcons.Theme"
BasedOn="{StaticResource IconPacks.Avalonia.PackIconControlBase.Theme}"
TargetType="iconPacks:PackIconBoxIcons" />

<ControlTheme x:Key="{x:Type iconPacks:PackIconBoxIcons}"
BasedOn="{StaticResource IconPacks.Avalonia.PackIconBoxIcons.Theme}"
Expand Down
4 changes: 4 additions & 0 deletions src/IconPacks.Avalonia.Core/IconPacks.Avalonia.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<RootNamespace>IconPacks.Avalonia</RootNamespace>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.4" />
Expand Down
10 changes: 10 additions & 0 deletions src/IconPacks.Avalonia.Core/PackIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Styles.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<MergeResourceInclude Source="avares://IconPacks.Avalonia.Core/PackIconControlBase.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Styles.Resources>
</Styles>
8 changes: 4 additions & 4 deletions src/IconPacks.Avalonia.Core/PackIconControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public abstract class PackIconControlBase : PackIconBase
/// </summary>
/// <returns>":icon-data-flipped-vertically"</returns>
public const string IconDataFlippedVerticallyPseudoClass = ":icon-data-flipped-vertically";

/// <summary>
/// A string representing the pseudo-class when the icon data is drawn filled
/// </summary>
/// <returns>":icon-filled"</returns>
public const string IconFilledPseudoClass = ":icon-filled";

/// <summary>
/// A string representing the pseudo-class when the icon data is drawn outlined
/// </summary>
/// <returns>":icon-outlided"</returns>
/// <returns>":icon-outlined"</returns>
public const string IconOutlinedPseudoClass = ":icon-outlined";

protected PackIconControlBase()
{
AffectsRender<PackIconControlBase>(SpinProperty, SpinDurationProperty, OpacityProperty, SpinEasingFunctionProperty, FlipProperty, RotationAngleProperty);
Expand Down
63 changes: 63 additions & 0 deletions src/IconPacks.Avalonia.Core/PackIconControlBase.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="urn:iconpacks-avalonia"
xmlns:converter="clr-namespace:IconPacks.Avalonia.Converter;assembly=IconPacks.Avalonia.Core"
x:ClassModifier="internal">

<ControlTemplate x:Key="IconPacks.Avalonia.PackIconControlBase.Template" TargetType="iconPacks:PackIconControlBase">
<Grid>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Grid x:Name="PART_InnerGrid"
Margin="{TemplateBinding BorderThickness}">
<Viewbox x:Name="PART_ViewBox"
Margin="{TemplateBinding Padding}">
<Path x:Name="PART_IconPath"
Data="{Binding Data, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Converter={x:Static converter:NullToUnsetValueConverter.Instance}}"
Stretch="Uniform"
UseLayoutRounding="False" />
</Viewbox>
</Grid>
</Grid>
</ControlTemplate>

<ControlTheme x:Key="IconPacks.Avalonia.PackIconControlBase.Theme" TargetType="iconPacks:PackIconControlBase">
<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" Value="{DynamicResource IconPacks.Avalonia.PackIconControlBase.Template}" />

<!-- icon is filled -->
<Style Selector="^:icon-filled /template/ Path#PART_IconPath">
<Setter Property="Fill" Value="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</Style>

<!-- icon is outlined -->
<Style Selector="^:icon-outlined /template/ Path#PART_IconPath">
<Setter Property="Stroke" Value="{Binding Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
<Setter Property="StrokeThickness" Value="2" />
<Setter Property="StrokeLineCap" Value="Round" />
<Setter Property="StrokeJoin" Value="Round" />
<Setter Property="Width" Value="24" />
<Setter Property="Height" Value="24" />
</Style>

<!-- flipped icon data -->
<Style Selector="^:icon-data-flipped-vertically /template/ Viewbox#PART_ViewBox">
<Setter Property="RenderTransform" Value="scale(1, -1)" />
</Style>
</ControlTheme>

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

</ResourceDictionary>
1 change: 1 addition & 0 deletions src/IconPacks.Avalonia/Icons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
</ResourceDictionary>
</Styles.Resources>

<StyleInclude Source="avares://IconPacks.Avalonia.Core/PackIcon.xaml"/>
<StyleInclude Source="avares://IconPacks.Avalonia.BoxIcons/BoxIcons.xaml"/>
</Styles>
Loading

0 comments on commit 87a4fca

Please sign in to comment.