ImageButton & ImageSplitButton

This commit is contained in:
Pilzinsel64
2025-11-07 10:48:36 +01:00
parent 0e11a0f9c4
commit 1ab775aa3e
11 changed files with 235 additions and 6 deletions

View File

@@ -15,7 +15,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Pilz.UI.Avalonia\Pilz.UI.AvaloniaUI.csproj" /> <ProjectReference Include="..\Pilz.UI.AvaloniaUI\Pilz.UI.AvaloniaUI.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,25 @@
<Button xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Pilz.UI.AvaloniaUI.Controls.ImageButton">
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="6"
>
<Image
VerticalAlignment="Center"
Width="16"
Height="16"
x:Name="ButtonImage"
/>
<TextBlock
VerticalAlignment="Center"
x:Name="ButtonText"
/>
</StackPanel>
</Button>

View File

@@ -0,0 +1,55 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace Pilz.UI.AvaloniaUI.Controls;
public partial class ImageButton : Button
{
protected override Type StyleKeyOverride => typeof(Button);
public ImageButton()
{
InitializeComponent();
}
public string? Text
{
get => ButtonText.Text;
set => ButtonText.Text = value;
}
public IImage? ImageSource
{
get => ButtonImage.Source;
set => ButtonImage.Source = value;
}
public double ImageWidth
{
get => ButtonImage.Width;
set => ButtonImage.Width = value;
}
public double ImageHeight
{
get => ButtonImage.Height;
set => ButtonImage.Height = value;
}
public double ImageQuadSize
{
get => ButtonImage.Width;
set => ButtonImage.Width = ButtonImage.Height = value;
}
public Size ImageSize
{
get => new(ButtonImage.Width, ButtonImage.Height);
set
{
ButtonImage.Width = value.Width;
ButtonImage.Height = value.Height;
}
}
}

View File

@@ -0,0 +1,25 @@
<SplitButton xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Pilz.UI.AvaloniaUI.Controls.ImageSplitButton">
<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="6"
>
<Image
VerticalAlignment="Center"
Width="16"
Height="16"
x:Name="ButtonImage"
/>
<TextBlock
VerticalAlignment="Center"
x:Name="ButtonText"
/>
</StackPanel>
</SplitButton>

View File

@@ -0,0 +1,55 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace Pilz.UI.AvaloniaUI.Controls;
public partial class ImageSplitButton : SplitButton
{
protected override Type StyleKeyOverride => typeof(SplitButton);
public ImageSplitButton()
{
InitializeComponent();
}
public string? Text
{
get => ButtonText.Text;
set => ButtonText.Text = value;
}
public IImage? ImageSource
{
get => ButtonImage.Source;
set => ButtonImage.Source = value;
}
public double ImageWidth
{
get => ButtonImage.Width;
set => ButtonImage.Width = value;
}
public double ImageHeight
{
get => ButtonImage.Height;
set => ButtonImage.Height = value;
}
public double ImageQuadSize
{
get => ButtonImage.Width;
set => ButtonImage.Width = ButtonImage.Height = value;
}
public Size ImageSize
{
get => new(ButtonImage.Width, ButtonImage.Height);
set
{
ButtonImage.Width = value.Width;
ButtonImage.Height = value.Height;
}
}
}

View File

@@ -0,0 +1,3 @@
using Avalonia.Metadata;
[assembly: XmlnsDefinition("https://git.pilzinsel64.de/pilz-framework/pilz", "Pilz.UI.AvaloniaUI.Controls")]

View File

@@ -7,10 +7,11 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<Version>1.0.0</Version> <Version>1.1.3</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.3.8" />
<PackageReference Include="Avalonia.Svg" Version="11.3.0" /> <PackageReference Include="Avalonia.Svg" Version="11.3.0" />
</ItemGroup> </ItemGroup>
@@ -18,4 +19,10 @@
<ProjectReference Include="..\Pilz.UI\Pilz.UI.csproj" /> <ProjectReference Include="..\Pilz.UI\Pilz.UI.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Update="Controls\ImageSplitButton.axaml.cs">
<DependentUpon>ImageSplitButton.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,5 @@
using Avalonia.Media; using Avalonia.Controls;
using Avalonia.Media;
using Pilz.UI.Symbols; using Pilz.UI.Symbols;
namespace Pilz.UI.AvaloniaUI.Symbols; namespace Pilz.UI.AvaloniaUI.Symbols;
@@ -6,5 +7,9 @@ namespace Pilz.UI.AvaloniaUI.Symbols;
public interface ISymbolFactory<TSymbols> : IBaseSymbolFactory<TSymbols> public interface ISymbolFactory<TSymbols> : IBaseSymbolFactory<TSymbols>
{ {
IImage? GetImageSource(TSymbols image); IImage? GetImageSource(TSymbols image);
Image? GetImage(TSymbols image, double width, double height);
Image? GetImage(TSymbols image, Avalonia.Size size);
Image? GetImage(TSymbols image, System.Drawing.Size size);
Image? GetImage(TSymbols image, SymbolSize size);
ISymbolProxy GetImage(TSymbols image); ISymbolProxy GetImage(TSymbols image);
} }

View File

@@ -1,8 +1,14 @@
using Avalonia.Media; using Avalonia.Controls;
using Avalonia.Media;
using Pilz.UI.Symbols;
namespace Pilz.UI.AvaloniaUI.Symbols; namespace Pilz.UI.AvaloniaUI.Symbols;
public interface ISymbolProxy public interface ISymbolProxy
{ {
IImage? GetImageSource(); IImage? GetImageSource();
Image? GetImage(double width, double height);
Image? GetImage(Avalonia.Size size);
Image? GetImage(System.Drawing.Size size);
Image? GetImage(SymbolSize size);
} }

View File

@@ -1,4 +1,5 @@
using Avalonia.Media; using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Svg; using Avalonia.Svg;
using Pilz.UI.Symbols; using Pilz.UI.Symbols;
@@ -19,6 +20,31 @@ public abstract class SymbolFactory<TSymbols> : BaseSymbolFactory<TSymbols>, ISy
}; };
} }
public Image? GetImage(TSymbols image, double width, double height)
{
return new Image
{
Source = GetImageSource(image),
Width = width,
Height = height,
};
}
public Image? GetImage(TSymbols image, Avalonia.Size size)
{
return GetImage(image, size.Width, size.Height);
}
public Image? GetImage(TSymbols image, System.Drawing.Size size)
{
return GetImage(image, size.Width, size.Height);
}
public Image? GetImage(TSymbols image, SymbolSize size)
{
return GetImage(image, ResolveCommonSize(size));
}
public ISymbolProxy GetImage(TSymbols image) public ISymbolProxy GetImage(TSymbols image)
{ {
return new SymbolProxy<TSymbols>(this, image); return new SymbolProxy<TSymbols>(this, image);

View File

@@ -1,4 +1,6 @@
using Avalonia.Media; using Avalonia.Controls;
using Avalonia.Media;
using Pilz.UI.Symbols;
namespace Pilz.UI.AvaloniaUI.Symbols; namespace Pilz.UI.AvaloniaUI.Symbols;
@@ -8,4 +10,24 @@ public class SymbolProxy<TSymbols>(SymbolFactory<TSymbols> factory, TSymbols ima
{ {
return factory.GetImageSource(image); return factory.GetImageSource(image);
} }
public Image? GetImage(double width, double height)
{
return factory.GetImage(image, width, height);
}
public Image? GetImage(Avalonia.Size size)
{
return factory.GetImage(image, size);
}
public Image? GetImage(System.Drawing.Size size)
{
return factory.GetImage(image, size);
}
public Image? GetImage(SymbolSize size)
{
return factory.GetImage(image, size);
}
} }