Skip to content

Commit

Permalink
Merge pull request #2 from timunie/IdeasTim
Browse files Browse the repository at this point in the history
Make style more generic
  • Loading branch information
punker76 authored Oct 30, 2024
2 parents 8c87422 + 603d4c0 commit 0a92b41
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/IconPacks.Avalonia/PackIconControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ namespace IconPacks.Avalonia
{
/// <summary>
/// </summary>
[PseudoClasses(":PackIconBoxIcons")]
[PseudoClasses(IconDataFlippedVerticallyPseudoClass)]
public class PackIconControl : PackIconControlBase
{
/// <summary>
/// A string representing the pseudo-class when the icon data is flipped vertically
/// </summary>
/// <returns>":icon-data-flipped-vertically"</returns>
public const string IconDataFlippedVerticallyPseudoClass = ":icon-data-flipped-vertically";

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

Expand Down Expand Up @@ -44,7 +50,16 @@ protected override void SetKind<TKind>(TKind iconKind)

protected override void UpdateData()
{
this.PseudoClasses.Set(":PackIconBoxIcons", Kind is PackIconBoxIconsKind);
switch(Kind)
{
case PackIconBoxIconsKind:
PseudoClasses.Set(IconDataFlippedVerticallyPseudoClass, true);
break;

default:
PseudoClasses.Set(IconDataFlippedVerticallyPseudoClass, false);
break;
}

if (Kind != default(Enum))
{
Expand Down
18 changes: 13 additions & 5 deletions src/IconPacks.Avalonia/PackIconControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
xmlns:iconPacks="urn:iconpacks-avalonia"
xmlns:converter="clr-namespace:IconPacks.Avalonia.Converter;assembly=IconPacks.Avalonia.Core"
x:ClassModifier="internal">


<Design.PreviewWith>
<iconPacks:PackIconBoxIcons Kind="RegularBowlingBall" />
</Design.PreviewWith>


<ControlTemplate x:Key="IconPacks.Avalonia.PackIconControl.Template" TargetType="iconPacks:PackIconControl">
<Grid>
<Border Background="{TemplateBinding Background}"
Expand All @@ -12,7 +17,8 @@
<Grid x:Name="PART_InnerGrid"
Margin="{TemplateBinding BorderThickness}"
RenderTransformOrigin="0.5 0.5">
<Viewbox Margin="{TemplateBinding Padding}">
<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}}"
Fill="{TemplateBinding Foreground}"
Expand Down Expand Up @@ -161,10 +167,12 @@
<Setter Property="UseLayoutRounding" Value="False" />
<Setter Property="Template" Value="{DynamicResource IconPacks.Avalonia.PackIconControl.Template}" />

<!-- <Style Selector="^[Kind=IconPacks.Avalonia.PackIconBoxIconsKind]"> -->
<Style Selector="^:PackIconBoxIcons">
<Setter Property="Template" Value="{DynamicResource IconPacks.Avalonia.PackIconBoxIcons.Template}" />
<!-- 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:PackIconControl}"
Expand Down

0 comments on commit 0a92b41

Please sign in to comment.