mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Shared UI - Added icons control supporting PackIcons and SVGs
This commit is contained in:
parent
3bbb04dd17
commit
e6417585b5
@ -40,6 +40,7 @@
|
|||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||||
<PackageReference Include="Ninject" Version="3.3.4" />
|
<PackageReference Include="Ninject" Version="3.3.4" />
|
||||||
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
|
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
|
||||||
|
<PackageReference Include="SharpVectors.Reloaded" Version="1.6.0" />
|
||||||
<PackageReference Include="SkiaSharp" Version="1.68.3" />
|
<PackageReference Include="SkiaSharp" Version="1.68.3" />
|
||||||
<PackageReference Include="SkiaSharp.Views.WPF" Version="1.68.3" />
|
<PackageReference Include="SkiaSharp.Views.WPF" Version="1.68.3" />
|
||||||
<PackageReference Include="Stylet" Version="1.3.4" />
|
<PackageReference Include="Stylet" Version="1.3.4" />
|
||||||
|
|||||||
30
src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml
Normal file
30
src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<UserControl x:Class="Artemis.UI.Shared.Controls.ArtemisIcon"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:Artemis.UI.Shared.Controls"
|
||||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
|
xmlns:system="clr-namespace:System;assembly=System.Runtime"
|
||||||
|
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
|
<ContentControl Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=Icon}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Focusable="False">
|
||||||
|
<ContentControl.Resources>
|
||||||
|
<DataTemplate DataType="{x:Type system:Uri}">
|
||||||
|
<Rectangle Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=Foreground}">
|
||||||
|
<Rectangle.OpacityMask>
|
||||||
|
<VisualBrush Stretch="Uniform">
|
||||||
|
<VisualBrush.Visual>
|
||||||
|
<svgc:SvgViewbox Source="{Binding}" Name="SvgDisplay"/>
|
||||||
|
</VisualBrush.Visual>
|
||||||
|
</VisualBrush>
|
||||||
|
</Rectangle.OpacityMask>
|
||||||
|
</Rectangle>
|
||||||
|
</DataTemplate>
|
||||||
|
<DataTemplate DataType="{x:Type materialDesign:PackIconKind}">
|
||||||
|
<materialDesign:PackIcon Kind="{Binding}" Width="Auto" Height="Auto"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ContentControl.Resources>
|
||||||
|
</ContentControl>
|
||||||
|
</UserControl>
|
||||||
88
src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml.cs
Normal file
88
src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using MaterialDesignThemes.Wpf;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Shared.Controls
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for ArtemisIcon.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class ArtemisIcon : UserControl
|
||||||
|
{
|
||||||
|
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(object), typeof(ArtemisIcon),
|
||||||
|
new FrameworkPropertyMetadata(IconPropertyChangedCallback));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty PackIconProperty = DependencyProperty.Register(nameof(PackIcon), typeof(PackIconKind?), typeof(ArtemisIcon),
|
||||||
|
new FrameworkPropertyMetadata(IconPropertyChangedCallback));
|
||||||
|
|
||||||
|
public static readonly DependencyProperty SvgSourceProperty = DependencyProperty.Register(nameof(SvgSource), typeof(Uri), typeof(ArtemisIcon),
|
||||||
|
new FrameworkPropertyMetadata(IconPropertyChangedCallback));
|
||||||
|
|
||||||
|
private bool _inCallback;
|
||||||
|
|
||||||
|
public ArtemisIcon()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the currently displayed icon as either a <see cref="PackIconKind" /> or an <see cref="Uri" /> pointing
|
||||||
|
/// to an SVG
|
||||||
|
/// </summary>
|
||||||
|
public object Icon
|
||||||
|
{
|
||||||
|
get => GetValue(IconProperty);
|
||||||
|
set => SetValue(IconProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the <see cref="PackIconKind" />
|
||||||
|
/// </summary>
|
||||||
|
public PackIconKind? PackIcon
|
||||||
|
{
|
||||||
|
get => (PackIconKind?) GetValue(PackIconProperty);
|
||||||
|
set => SetValue(PackIconProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the <see cref="Uri" /> pointing to the SVG
|
||||||
|
/// </summary>
|
||||||
|
public Uri SvgSource
|
||||||
|
{
|
||||||
|
get => (Uri) GetValue(SvgSourceProperty);
|
||||||
|
set => SetValue(SvgSourceProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IconPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
ArtemisIcon artemisIcon = (ArtemisIcon) d;
|
||||||
|
if (artemisIcon._inCallback)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
artemisIcon._inCallback = true;
|
||||||
|
if (artemisIcon.PackIcon != null)
|
||||||
|
{
|
||||||
|
artemisIcon.Icon = artemisIcon.PackIcon;
|
||||||
|
}
|
||||||
|
else if (artemisIcon.SvgSource != null)
|
||||||
|
{
|
||||||
|
artemisIcon.Icon = artemisIcon.SvgSource;
|
||||||
|
}
|
||||||
|
else if (artemisIcon.Icon is string iconString)
|
||||||
|
{
|
||||||
|
if (Uri.TryCreate(iconString, UriKind.Absolute, out Uri uriResult))
|
||||||
|
artemisIcon.Icon = uriResult;
|
||||||
|
else if (Enum.TryParse(typeof(PackIconKind), iconString, true, out object result))
|
||||||
|
artemisIcon.Icon = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
artemisIcon._inCallback = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -88,6 +88,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="Resources\Fonts\RobotoMono-Regular.ttf" />
|
<Resource Include="Resources\Fonts\RobotoMono-Regular.ttf" />
|
||||||
|
<Resource Include="Resources\Images\Logo\bow.svg" />
|
||||||
<Resource Include="Resources\Images\Logo\logo-512.ico" />
|
<Resource Include="Resources\Images\Logo\logo-512.ico" />
|
||||||
<Resource Include="Resources\Images\Logo\logo-512.png" />
|
<Resource Include="Resources\Images\Logo\logo-512.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -304,6 +305,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="Resources\Fonts\RobotoMono-Regular.ttf" />
|
<None Remove="Resources\Fonts\RobotoMono-Regular.ttf" />
|
||||||
|
<None Remove="Resources\Images\Logo\bow.svg" />
|
||||||
<None Remove="Resources\Images\Logo\logo-512.ico" />
|
<None Remove="Resources\Images\Logo\logo-512.ico" />
|
||||||
<None Remove="Resources\Images\Sidebar\sidebar-header.png" />
|
<None Remove="Resources\Images\Sidebar\sidebar-header.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||||
xmlns:home="clr-namespace:Artemis.UI.Screens.Home"
|
xmlns:home="clr-namespace:Artemis.UI.Screens.Home"
|
||||||
|
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="574.026"
|
d:DesignHeight="574.026"
|
||||||
d:DesignWidth="1029.87"
|
d:DesignWidth="1029.87"
|
||||||
@ -35,7 +36,8 @@
|
|||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Image Source="/Resources/Images/Logo/logo-512.png" Stretch="Uniform" Width="100" Height="100" />
|
|
||||||
|
<controls:ArtemisIcon SvgSource="/Resources/Images/Logo/bow.svg" Width="100" Height="100"/>
|
||||||
<StackPanel Grid.Column="1" Margin="24 0 0 0" VerticalAlignment="Center">
|
<StackPanel Grid.Column="1" Margin="24 0 0 0" VerticalAlignment="Center">
|
||||||
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" TextWrapping="Wrap">Welcome to Artemis, RGB on steroids.</TextBlock>
|
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" TextWrapping="Wrap">Welcome to Artemis, RGB on steroids.</TextBlock>
|
||||||
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user